Diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
Percent-encode a submodule path in its link
A module-link template takes the path as the tree names it, so a path
holding a space or a byte past ASCII gave an href that broke there. The
url is now encoded the way a clone url is.
| -rw-r--r-- | source/ui-shared.c | 5 | |
| -rwxr-xr-x | tests/t0202-submodule-links.sh | 18 |
2 files changed, 22 insertions, 1 deletion
diff --git a/source/ui-shared.c b/source/ui-shared.c index d2eec25..c64cd9a 100644 --- a/source/ui-shared.c +++ b/source/ui-shared.c @@ -1210,7 +1210,10 @@ static void emit_module_link(const char *tmpl, const char **args, int nargs) strbuf_addch(&sb, '%'); } } - html_attr(sb.buf); + // The path comes from the tree as it is, and a space or a byte past + // ASCII in it would break the href, so the url is encoded as a clone + // url is. + html_attr_url(sb.buf); strbuf_release(&sb); } diff --git a/tests/t0202-submodule-links.sh b/tests/t0202-submodule-links.sh index ffe10de..7e43c67 100755 --- a/tests/t0202-submodule-links.sh +++ b/tests/t0202-submodule-links.sh @@ -177,6 +177,24 @@ test_expect_success 'the module-link templates win over .gitmodules' ' ! grep "subtarget/tree" tmp ' +# A template takes the path as the tree names it, so a space or a byte past +# ASCII in a path has to be percent-encoded before an href can carry it. +test_expect_success 'a module-link template percent-encodes the path' ' + sub=$(git -C repos/subtarget rev-parse HEAD) && + git init -q repos/oddsub && + ( + cd repos/oddsub && + git update-index --add --cacheinfo "160000,$sub,my lib" && + git update-index --add --cacheinfo "160000,$sub,$(printf "caf\303\251")" && + git commit -q -m "odd submodule paths" + ) && + cgitrc_repo oddrc oddsub "module-link=/mods/%s/%s" && + cgit_ok oddrc "url=oddsub/tree/" >tmp && + grep "<a class=.ls-mod. href=./mods/my%20lib/$sub.>my lib</a>" tmp && + grep "<a class=.ls-mod. href=./mods/caf%C3%A9/$sub.>caf" tmp && + ! grep "href=./mods/my lib/" tmp +' + test_expect_success 'the links stay off without the flag' ' cgitrc_repo suboffrc subparent && cgit_ok suboffrc "url=subparent/tree/" >tmp && |
