2018-03-24 08:45:03 +01:00
|
|
|
#include "test-tool.h"
|
2013-08-05 22:20:36 +02:00
|
|
|
#include "git-compat-util.h"
|
|
|
|
#include "urlmatch.h"
|
|
|
|
|
2018-03-24 08:45:03 +01:00
|
|
|
int cmd__urlmatch_normalization(int argc, const char **argv)
|
2013-08-05 22:20:36 +02:00
|
|
|
{
|
2018-03-24 08:45:03 +01:00
|
|
|
const char usage[] = "test-tool urlmatch-normalization [-p | -l] <url1> | <url1> <url2>";
|
2022-07-01 12:37:35 +02:00
|
|
|
char *url1 = NULL, *url2 = NULL;
|
2013-08-05 22:20:36 +02:00
|
|
|
int opt_p = 0, opt_l = 0;
|
2022-07-01 12:37:35 +02:00
|
|
|
int ret = 0;
|
2013-08-05 22:20:36 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* For one url, succeed if url_normalize succeeds on it, fail otherwise.
|
|
|
|
* For two urls, succeed only if url_normalize succeeds on both and
|
|
|
|
* the results compare equal with strcmp. If -p is given (one url only)
|
|
|
|
* and url_normalize succeeds, print the result followed by "\n". If
|
|
|
|
* -l is given (one url only) and url_normalize succeeds, print the
|
|
|
|
* returned length in decimal followed by "\n".
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (argc > 1 && !strcmp(argv[1], "-p")) {
|
|
|
|
opt_p = 1;
|
|
|
|
argc--;
|
|
|
|
argv++;
|
|
|
|
} else if (argc > 1 && !strcmp(argv[1], "-l")) {
|
|
|
|
opt_l = 1;
|
|
|
|
argc--;
|
|
|
|
argv++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc < 2 || argc > 3)
|
2013-08-09 06:41:44 +02:00
|
|
|
die("%s", usage);
|
2013-08-05 22:20:36 +02:00
|
|
|
|
|
|
|
if (argc == 2) {
|
|
|
|
struct url_info info;
|
|
|
|
url1 = url_normalize(argv[1], &info);
|
|
|
|
if (!url1)
|
|
|
|
return 1;
|
|
|
|
if (opt_p)
|
|
|
|
printf("%s\n", url1);
|
|
|
|
if (opt_l)
|
|
|
|
printf("%u\n", (unsigned)info.url_len);
|
2022-07-01 12:37:35 +02:00
|
|
|
goto cleanup;
|
2013-08-05 22:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (opt_p || opt_l)
|
2013-08-09 06:41:44 +02:00
|
|
|
die("%s", usage);
|
2013-08-05 22:20:36 +02:00
|
|
|
|
|
|
|
url1 = url_normalize(argv[1], NULL);
|
|
|
|
url2 = url_normalize(argv[2], NULL);
|
2022-07-01 12:37:35 +02:00
|
|
|
ret = (url1 && url2 && !strcmp(url1, url2)) ? 0 : 1;
|
|
|
|
cleanup:
|
|
|
|
free(url1);
|
|
|
|
free(url2);
|
|
|
|
return ret;
|
2013-08-05 22:20:36 +02:00
|
|
|
}
|