summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--html.c16
-rw-r--r--html.h1
-rwxr-xr-xtests/setup.sh13
-rwxr-xr-xtests/t0101-index.sh2
-rwxr-xr-xtests/t0104-tree.sh12
-rw-r--r--ui-shared.c20
6 files changed, 53 insertions, 11 deletions
diff --git a/html.c b/html.c
index 36e9a2f..167127f 100644
--- a/html.c
+++ b/html.c
@@ -129,4 +129,20 @@ void html_attr(char *txt)
}
+void html_url_arg(char *txt)
+{
+ char *t = txt;
+ while(t && *t){
+ int c = *t;
+ if (c=='"' || c=='#' || c=='%' || c=='&' || c=='\'' || c=='+' || c=='?') {
+ write(htmlfd, txt, t - txt);
+ write(htmlfd, fmt("%%%2x", c), 3);
+ txt = t+1;
+ }
+ t++;
+ }
+ if (t!=txt)
+ html(txt);
+}
+
void html_hidden(char *name, char *value)
{
diff --git a/html.h b/html.h
index 3c32935..038cf60 100644
--- a/html.h
+++ b/html.h
@@ -11,4 +11,5 @@ extern void html_txt(char *txt);
extern void html_ntxt(int len, char *txt);
extern void html_attr(char *txt);
+extern void html_url_arg(char *txt);
extern void html_hidden(char *name, char *value);
extern void html_option(char *value, char *text, char *selected_value);
diff --git a/tests/setup.sh b/tests/setup.sh
index e37306e..1457dd5 100755
--- a/tests/setup.sh
+++ b/tests/setup.sh
@@ -32,4 +32,11 @@ mkrepo() {
git commit -m "commit $n"
done
+ if test "$3" = "testplus"
+ then
+ echo "hello" >a+b
+ git add a+b
+ git commit -m "add a+b"
+ git branch "1+2"
+ fi
cd $dir
}
@@ -41,4 +48,5 @@ setup_repos()
mkrepo trash/repos/foo 5 >/dev/null
mkrepo trash/repos/bar 50 >/dev/null
+ mkrepo trash/repos/foo+bar 10 testplus >/dev/null
cat >trash/cgitrc <<EOF
virtual-root=/
@@ -62,4 +70,8 @@ repo.url=bar
repo.path=$PWD/trash/repos/bar/.git
repo.desc=the bar repo
+
+repo.url=foo+bar
+repo.path=$PWD/trash/repos/foo+bar/.git
+repo.desc=the foo+bar repo
EOF
}
@@ -114,3 +126,2 @@ cgit_url()
CGIT_CONFIG="$PWD/trash/cgitrc" QUERY_STRING="url=$1" "$PWD/../cgit"
}
-
diff --git a/tests/t0101-index.sh b/tests/t0101-index.sh
index 445af6a..07e39f9 100755
--- a/tests/t0101-index.sh
+++ b/tests/t0101-index.sh
@@ -10,4 +10,6 @@ run_test 'find foo description' 'grep -e "\[no description\]" trash/tmp'
run_test 'find bar repo' 'grep -e "bar" trash/tmp'
run_test 'find bar description' 'grep -e "the bar repo" trash/tmp'
+run_test 'find foo+bar repo' 'grep -e ">foo+bar<" trash/tmp'
+run_test 'verify foo+bar link' 'grep -e "/foo+bar/" trash/tmp'
run_test 'no tree-link' '! grep -e "foo/tree" trash/tmp'
run_test 'no log-link' '! grep -e "foo/log" trash/tmp'
diff --git a/tests/t0104-tree.sh b/tests/t0104-tree.sh
index 2516c72..0d62cc8 100755
--- a/tests/t0104-tree.sh
+++ b/tests/t0104-tree.sh
@@ -19,3 +19,15 @@ run_test 'no line 2' '
'
+run_test 'generate foo+bar/tree' 'cgit_url "foo%2bbar/tree" >trash/tmp'
+
+run_test 'verify a+b link' '
+ grep -e "/foo+bar/tree/a+b" trash/tmp
+'
+
+run_test 'generate foo+bar/tree?h=1+2' 'cgit_url "foo%2bbar/tree&h=1%2b2" >trash/tmp'
+
+run_test 'verify a+b?h=1+2 link' '
+ grep -e "/foo+bar/tree/a+b?h=1%2b2" trash/tmp
+'
+
tests_done
diff --git a/ui-shared.c b/ui-shared.c
index c23bc75..a2f636c 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -222,12 +222,12 @@ static char *repolink(char *title, char *class, char *page, char *head,
html(ctx.cfg.script_name);
html("?url=");
- html_attr(ctx.repo->url);
+ html_url_arg(ctx.repo->url);
if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/')
html("/");
if (page) {
- html(page);
+ html_url_arg(page);
html("/");
if (path)
- html_attr(path);
+ html_url_arg(path);
}
delim = "&amp;";
@@ -236,5 +236,5 @@ static char *repolink(char *title, char *class, char *page, char *head,
html(delim);
html("h=");
- html_attr(head);
+ html_url_arg(head);
delim = "&amp;";
}
@@ -251,5 +251,5 @@ static void reporevlink(char *page, char *name, char *title, char *class,
html(delim);
html("id=");
- html_attr(rev);
+ html_url_arg(rev);
}
html("'>");
@@ -279,5 +279,5 @@ void cgit_log_link(char *name, char *title, char *class, char *head,
html(delim);
html("id=");
- html_attr(rev);
+ html_url_arg(rev);
delim = "&";
}
@@ -285,9 +285,9 @@ void cgit_log_link(char *name, char *title, char *class, char *head,
html(delim);
html("qt=");
- html_attr(grep);
+ html_url_arg(grep);
delim = "&";
html(delim);
html("q=");
- html_attr(pattern);
+ html_url_arg(pattern);
}
if (ofs > 0) {
@@ -334,5 +334,5 @@ void cgit_diff_link(char *name, char *title, char *class, char *head,
html(delim);
html("id=");
- html_attr(new_rev);
+ html_url_arg(new_rev);
delim = "&amp;";
}
@@ -340,5 +340,5 @@ void cgit_diff_link(char *name, char *title, char *class, char *head,
html(delim);
html("id2=");
- html_attr(old_rev);
+ html_url_arg(old_rev);
}
html("'>");