From 087885049e38c38a437153055ff521567132b183 Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Mon, 10 Oct 2016 10:56:10 -0700 Subject: submodule: ignore trailing slash on superproject URL Before 63e95beb0 (2016-04-15, submodule: port resolve_relative_url from shell to C), it did not matter if the superprojects URL had a trailing slash or not. It was just chopped off as one of the first steps (The "remoteurl=${remoteurl%/}" near the beginning of resolve_relative_url(), which was removed in said commit). When porting this to the C version, an off-by-one error was introduced and we did not check the actual last character to be a slash, but the NULL delimiter. Reintroduce the behavior from before 63e95beb0, to ignore the trailing slash. Reported-by: Helped-by: Dennis Kaarsemaker Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano --- builtin/submodule--helper.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'builtin') diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 7f0941ddc3..612e87084c 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -95,6 +95,8 @@ static int chop_last_dir(char **remoteurl, int is_relative) * NEEDSWORK: This works incorrectly on the domain and protocol part. * remote_url url outcome expectation * http://a.com/b ../c http://a.com/c as is + * http://a.com/b/ ../c http://a.com/c same as previous line, but + * ignore trailing slash in url * http://a.com/b ../../c http://c error out * http://a.com/b ../../../c http:/c error out * http://a.com/b ../../../../c http:c error out @@ -113,8 +115,8 @@ static char *relative_url(const char *remote_url, struct strbuf sb = STRBUF_INIT; size_t len = strlen(remoteurl); - if (is_dir_sep(remoteurl[len])) - remoteurl[len] = '\0'; + if (is_dir_sep(remoteurl[len-1])) + remoteurl[len-1] = '\0'; if (!url_is_local_not_ssh(remoteurl) || is_absolute_path(remoteurl)) is_relative = 0; -- cgit v1.2.3 From 3389e78ec8cd117f981ce3963a901b66db6c8206 Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Mon, 10 Oct 2016 10:56:11 -0700 Subject: submodule: ignore trailing slash in relative url This is similar to the previous patch, though no user reported a bug and I could not find a regressive behavior. However it is a good thing to be strict on the output and for that we always omit a trailing slash. Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano --- builtin/submodule--helper.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'builtin') diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 612e87084c..569bc8cf3d 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -149,6 +149,8 @@ static char *relative_url(const char *remote_url, } strbuf_reset(&sb); strbuf_addf(&sb, "%s%s%s", remoteurl, colonsep ? ":" : "/", url); + if (ends_with(url, "/")) + strbuf_setlen(&sb, sb.len - 1); free(remoteurl); if (starts_with_dot_slash(sb.buf)) -- cgit v1.2.3