From b430fd4e3f1cc2f2ba1d58b77eee8d527f3b3cf7 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sat, 7 Nov 2026 19:34:05 -1000 Subject: 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. --- source/ui-shared.c | 5 ++++- 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 "my lib" tmp && + grep "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 && -- cgit 2.12.1