diff options
-rw-r--r-- | cgit.c | 5 | ||||
-rw-r--r-- | html.c | 15 | ||||
-rw-r--r-- | parsing.c | 5 | ||||
-rw-r--r-- | shared.c | 19 | ||||
-rwxr-xr-x | tests/setup.sh | 25 | ||||
-rwxr-xr-x | tests/t0101-index.sh | 1 | ||||
-rwxr-xr-x | tests/t0103-log.sh | 10 | ||||
-rw-r--r-- | ui-diff.c | 8 | ||||
-rw-r--r-- | ui-repolist.c | 2 |
9 files changed, 61 insertions, 29 deletions
diff --git a/cgit.c b/cgit.c index 349d6e0..eb964ac 100644 --- a/cgit.c +++ b/cgit.c | |||
@@ -767,8 +767,11 @@ int main(int argc, const char **argv) | |||
767 | * that virtual-root equals SCRIPT_NAME, minus any possibly | 767 | * that virtual-root equals SCRIPT_NAME, minus any possibly |
768 | * trailing slashes. | 768 | * trailing slashes. |
769 | */ | 769 | */ |
770 | if (!ctx.cfg.virtual_root) | 770 | if (!ctx.cfg.virtual_root && ctx.cfg.script_name) { |
771 | ctx.cfg.virtual_root = trim_end(ctx.cfg.script_name, '/'); | 771 | ctx.cfg.virtual_root = trim_end(ctx.cfg.script_name, '/'); |
772 | if (!ctx.cfg.virtual_root) | ||
773 | ctx.cfg.virtual_root = ""; | ||
774 | } | ||
772 | 775 | ||
773 | /* If no url parameter is specified on the querystring, lets | 776 | /* If no url parameter is specified on the querystring, lets |
774 | * use PATH_INFO as url. This allows cgit to work with virtual | 777 | * use PATH_INFO as url. This allows cgit to work with virtual |
diff --git a/html.c b/html.c index a60bc13..a0f6db4 100644 --- a/html.c +++ b/html.c | |||
@@ -18,7 +18,7 @@ static const char* url_escape_table[256] = { | |||
18 | "%00", "%01", "%02", "%03", "%04", "%05", "%06", "%07", "%08", "%09", | 18 | "%00", "%01", "%02", "%03", "%04", "%05", "%06", "%07", "%08", "%09", |
19 | "%0a", "%0b", "%0c", "%0d", "%0e", "%0f", "%10", "%11", "%12", "%13", | 19 | "%0a", "%0b", "%0c", "%0d", "%0e", "%0f", "%10", "%11", "%12", "%13", |
20 | "%14", "%15", "%16", "%17", "%18", "%19", "%1a", "%1b", "%1c", "%1d", | 20 | "%14", "%15", "%16", "%17", "%18", "%19", "%1a", "%1b", "%1c", "%1d", |
21 | "%1e", "%1f", "+", 0, "%22", "%23", 0, "%25", "%26", "%27", 0, 0, 0, | 21 | "%1e", "%1f", "%20", 0, "%22", "%23", 0, "%25", "%26", "%27", 0, 0, 0, |
22 | "%2b", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "%3c", "%3d", | 22 | "%2b", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "%3c", "%3d", |
23 | "%3e", "%3f", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | 23 | "%3e", "%3f", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
24 | 0, 0, 0, 0, 0, 0, 0, 0, 0, "%5c", 0, "%5e", 0, "%60", 0, 0, 0, 0, 0, | 24 | 0, 0, 0, 0, 0, 0, 0, 0, 0, "%5c", 0, "%5e", 0, "%60", 0, 0, 0, 0, 0, |
@@ -162,9 +162,9 @@ void html_url_path(const char *txt) | |||
162 | while(t && *t){ | 162 | while(t && *t){ |
163 | int c = *t; | 163 | int c = *t; |
164 | const char *e = url_escape_table[c]; | 164 | const char *e = url_escape_table[c]; |
165 | if (e && c!='+' && c!='&' && c!='+') { | 165 | if (e && c!='+' && c!='&') { |
166 | html_raw(txt, t - txt); | 166 | html_raw(txt, t - txt); |
167 | html_raw(e, 3); | 167 | html(e); |
168 | txt = t+1; | 168 | txt = t+1; |
169 | } | 169 | } |
170 | t++; | 170 | t++; |
@@ -179,9 +179,11 @@ void html_url_arg(const char *txt) | |||
179 | while(t && *t){ | 179 | while(t && *t){ |
180 | int c = *t; | 180 | int c = *t; |
181 | const char *e = url_escape_table[c]; | 181 | const char *e = url_escape_table[c]; |
182 | if (c == ' ') | ||
183 | e = "+"; | ||
182 | if (e) { | 184 | if (e) { |
183 | html_raw(txt, t - txt); | 185 | html_raw(txt, t - txt); |
184 | html_raw(e, strlen(e)); | 186 | html(e); |
185 | txt = t+1; | 187 | txt = t+1; |
186 | } | 188 | } |
187 | t++; | 189 | t++; |
@@ -288,12 +290,12 @@ char *convert_query_hexchar(char *txt) | |||
288 | 290 | ||
289 | int http_parse_querystring(const char *txt_, void (*fn)(const char *name, const char *value)) | 291 | int http_parse_querystring(const char *txt_, void (*fn)(const char *name, const char *value)) |
290 | { | 292 | { |
291 | char *t, *txt, *value = NULL, c; | 293 | char *o, *t, *txt, *value = NULL, c; |
292 | 294 | ||
293 | if (!txt_) | 295 | if (!txt_) |
294 | return 0; | 296 | return 0; |
295 | 297 | ||
296 | t = txt = strdup(txt_); | 298 | o = t = txt = strdup(txt_); |
297 | if (t == NULL) { | 299 | if (t == NULL) { |
298 | printf("Out of memory\n"); | 300 | printf("Out of memory\n"); |
299 | exit(1); | 301 | exit(1); |
@@ -316,5 +318,6 @@ int http_parse_querystring(const char *txt_, void (*fn)(const char *name, const | |||
316 | } | 318 | } |
317 | if (t!=txt) | 319 | if (t!=txt) |
318 | (*fn)(txt, value); | 320 | (*fn)(txt, value); |
321 | free(o); | ||
319 | return 0; | 322 | return 0; |
320 | } | 323 | } |
diff --git a/parsing.c b/parsing.c index c9e4350..151c0fe 100644 --- a/parsing.c +++ b/parsing.c | |||
@@ -103,7 +103,10 @@ const char *reencode(char **txt, const char *src_enc, const char *dst_enc) | |||
103 | { | 103 | { |
104 | char *tmp; | 104 | char *tmp; |
105 | 105 | ||
106 | if (!txt || !*txt || !src_enc || !dst_enc) | 106 | if (!txt) |
107 | return NULL; | ||
108 | |||
109 | if (!*txt || !src_enc || !dst_enc) | ||
107 | return *txt; | 110 | return *txt; |
108 | 111 | ||
109 | /* no encoding needed if src_enc equals dst_enc */ | 112 | /* no encoding needed if src_enc equals dst_enc */ |
diff --git a/shared.c b/shared.c index 7ec2e19..3778a5b 100644 --- a/shared.c +++ b/shared.c | |||
@@ -100,23 +100,15 @@ void *cgit_free_commitinfo(struct commitinfo *info) | |||
100 | char *trim_end(const char *str, char c) | 100 | char *trim_end(const char *str, char c) |
101 | { | 101 | { |
102 | int len; | 102 | int len; |
103 | char *s, *t; | ||
104 | 103 | ||
105 | if (str == NULL) | 104 | if (str == NULL) |
106 | return NULL; | 105 | return NULL; |
107 | t = (char *)str; | 106 | len = strlen(str); |
108 | len = strlen(t); | 107 | while(len > 0 && str[len - 1] == c) |
109 | while(len > 0 && t[len - 1] == c) | ||
110 | len--; | 108 | len--; |
111 | |||
112 | if (len == 0) | 109 | if (len == 0) |
113 | return NULL; | 110 | return NULL; |
114 | 111 | return xstrndup(str, len); | |
115 | c = t[len]; | ||
116 | t[len] = '\0'; | ||
117 | s = xstrdup(t); | ||
118 | t[len] = c; | ||
119 | return s; | ||
120 | } | 112 | } |
121 | 113 | ||
122 | char *strlpart(char *txt, int maxlen) | 114 | char *strlpart(char *txt, int maxlen) |
@@ -311,7 +303,6 @@ void cgit_diff_tree(const unsigned char *old_sha1, | |||
311 | filepair_fn fn, const char *prefix, int ignorews) | 303 | filepair_fn fn, const char *prefix, int ignorews) |
312 | { | 304 | { |
313 | struct diff_options opt; | 305 | struct diff_options opt; |
314 | int ret; | ||
315 | int prefixlen; | 306 | int prefixlen; |
316 | 307 | ||
317 | diff_setup(&opt); | 308 | diff_setup(&opt); |
@@ -332,9 +323,9 @@ void cgit_diff_tree(const unsigned char *old_sha1, | |||
332 | diff_setup_done(&opt); | 323 | diff_setup_done(&opt); |
333 | 324 | ||
334 | if (old_sha1 && !is_null_sha1(old_sha1)) | 325 | if (old_sha1 && !is_null_sha1(old_sha1)) |
335 | ret = diff_tree_sha1(old_sha1, new_sha1, "", &opt); | 326 | diff_tree_sha1(old_sha1, new_sha1, "", &opt); |
336 | else | 327 | else |
337 | ret = diff_root_tree_sha1(new_sha1, "", &opt); | 328 | diff_root_tree_sha1(new_sha1, "", &opt); |
338 | diffcore_std(&opt); | 329 | diffcore_std(&opt); |
339 | diff_flush(&opt); | 330 | diff_flush(&opt); |
340 | } | 331 | } |
diff --git a/tests/setup.sh b/tests/setup.sh index 30f90d5..b2f1169 100755 --- a/tests/setup.sh +++ b/tests/setup.sh | |||
@@ -20,10 +20,10 @@ mkrepo() { | |||
20 | name=$1 | 20 | name=$1 |
21 | count=$2 | 21 | count=$2 |
22 | dir=$PWD | 22 | dir=$PWD |
23 | test -d $name && return | 23 | test -d "$name" && return |
24 | printf "Creating testrepo %s\n" $name | 24 | printf "Creating testrepo %s\n" $name |
25 | mkdir -p $name | 25 | mkdir -p "$name" |
26 | cd $name | 26 | cd "$name" |
27 | git init | 27 | git init |
28 | n=1 | 28 | n=1 |
29 | while test $n -le $count | 29 | while test $n -le $count |
@@ -50,6 +50,7 @@ setup_repos() | |||
50 | mkrepo trash/repos/foo 5 >/dev/null | 50 | mkrepo trash/repos/foo 5 >/dev/null |
51 | mkrepo trash/repos/bar 50 >/dev/null | 51 | mkrepo trash/repos/bar 50 >/dev/null |
52 | mkrepo trash/repos/foo+bar 10 testplus >/dev/null | 52 | mkrepo trash/repos/foo+bar 10 testplus >/dev/null |
53 | mkrepo "trash/repos/with space" 2 >/dev/null | ||
53 | cat >trash/cgitrc <<EOF | 54 | cat >trash/cgitrc <<EOF |
54 | virtual-root=/ | 55 | virtual-root=/ |
55 | cache-root=$PWD/trash/cache | 56 | cache-root=$PWD/trash/cache |
@@ -75,6 +76,10 @@ repo.desc=the bar repo | |||
75 | repo.url=foo+bar | 76 | repo.url=foo+bar |
76 | repo.path=$PWD/trash/repos/foo+bar/.git | 77 | repo.path=$PWD/trash/repos/foo+bar/.git |
77 | repo.desc=the foo+bar repo | 78 | repo.desc=the foo+bar repo |
79 | |||
80 | repo.url=with space | ||
81 | repo.path=$PWD/trash/repos/with space/.git | ||
82 | repo.desc=spaced repo | ||
78 | EOF | 83 | EOF |
79 | } | 84 | } |
80 | 85 | ||
@@ -101,6 +106,12 @@ tests_done() | |||
101 | 106 | ||
102 | run_test() | 107 | run_test() |
103 | { | 108 | { |
109 | bug=0 | ||
110 | if test "$1" = "BUG" | ||
111 | then | ||
112 | bug=1 | ||
113 | shift | ||
114 | fi | ||
104 | desc=$1 | 115 | desc=$1 |
105 | script=$2 | 116 | script=$2 |
106 | test_count=$(expr $test_count + 1) | 117 | test_count=$(expr $test_count + 1) |
@@ -109,9 +120,15 @@ run_test() | |||
109 | eval "$2" >>test-output.log 2>>test-output.log | 120 | eval "$2" >>test-output.log 2>>test-output.log |
110 | res=$? | 121 | res=$? |
111 | printf "test %d: exitcode=%d\n" $test_count $res >>test-output.log | 122 | printf "test %d: exitcode=%d\n" $test_count $res >>test-output.log |
112 | if test $res = 0 | 123 | if test $res = 0 -a $bug = 0 |
113 | then | 124 | then |
114 | printf " %2d) %-60s [ok]\n" $test_count "$desc" | 125 | printf " %2d) %-60s [ok]\n" $test_count "$desc" |
126 | elif test $res = 0 -a $bug = 1 | ||
127 | then | ||
128 | printf " %2d) %-60s [BUG FIXED]\n" $test_count "$desc" | ||
129 | elif test $bug = 1 | ||
130 | then | ||
131 | printf " %2d) %-60s [KNOWN BUG]\n" $test_count "$desc" | ||
115 | else | 132 | else |
116 | test_failed=$(expr $test_failed + 1) | 133 | test_failed=$(expr $test_failed + 1) |
117 | printf " %2d) %-60s [failed]\n" $test_count "$desc" | 134 | printf " %2d) %-60s [failed]\n" $test_count "$desc" |
diff --git a/tests/t0101-index.sh b/tests/t0101-index.sh index 07e39f9..573a351 100755 --- a/tests/t0101-index.sh +++ b/tests/t0101-index.sh | |||
@@ -11,6 +11,7 @@ run_test 'find bar repo' 'grep -e "bar" trash/tmp' | |||
11 | run_test 'find bar description' 'grep -e "the bar repo" trash/tmp' | 11 | run_test 'find bar description' 'grep -e "the bar repo" trash/tmp' |
12 | run_test 'find foo+bar repo' 'grep -e ">foo+bar<" trash/tmp' | 12 | run_test 'find foo+bar repo' 'grep -e ">foo+bar<" trash/tmp' |
13 | run_test 'verify foo+bar link' 'grep -e "/foo+bar/" trash/tmp' | 13 | run_test 'verify foo+bar link' 'grep -e "/foo+bar/" trash/tmp' |
14 | run_test 'verify "with%20space" link' 'grep -e "/with%20space/" trash/tmp' | ||
14 | run_test 'no tree-link' '! grep -e "foo/tree" trash/tmp' | 15 | run_test 'no tree-link' '! grep -e "foo/tree" trash/tmp' |
15 | run_test 'no log-link' '! grep -e "foo/log" trash/tmp' | 16 | run_test 'no log-link' '! grep -e "foo/log" trash/tmp' |
16 | 17 | ||
diff --git a/tests/t0103-log.sh b/tests/t0103-log.sh index b08cd29..def5c18 100755 --- a/tests/t0103-log.sh +++ b/tests/t0103-log.sh | |||
@@ -12,4 +12,14 @@ run_test 'generate bar/log' 'cgit_url "bar/log" >trash/tmp' | |||
12 | run_test 'find commit 1' 'grep -e "commit 1" trash/tmp' | 12 | run_test 'find commit 1' 'grep -e "commit 1" trash/tmp' |
13 | run_test 'find commit 50' 'grep -e "commit 50" trash/tmp' | 13 | run_test 'find commit 50' 'grep -e "commit 50" trash/tmp' |
14 | 14 | ||
15 | run_test 'generate "with%20space/log?qt=grep&q=commit+1"' ' | ||
16 | cgit_url "with+space/log&qt=grep&q=commit+1" >trash/tmp | ||
17 | ' | ||
18 | run_test 'find commit 1' 'grep -e "commit 1" trash/tmp' | ||
19 | run_test 'find link with %20 in path' 'grep -e "/with%20space/log/?qt=grep" trash/tmp' | ||
20 | run_test 'find link with + in arg' 'grep -e "/log/?qt=grep&q=commit+1" trash/tmp' | ||
21 | run_test BUG 'no links with space in path' '! grep -e "href=./with space/" trash/tmp' | ||
22 | run_test 'no links with space in arg' '! grep -e "q=commit 1" trash/tmp' | ||
23 | run_test 'commit 2 is not visible' '! grep -e "commit 2" trash/tmp' | ||
24 | |||
15 | tests_done | 25 | tests_done |
diff --git a/ui-diff.c b/ui-diff.c index a7bc667..d21541b 100644 --- a/ui-diff.c +++ b/ui-diff.c | |||
@@ -345,8 +345,10 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefi | |||
345 | return; | 345 | return; |
346 | } | 346 | } |
347 | commit = lookup_commit_reference(new_rev_sha1); | 347 | commit = lookup_commit_reference(new_rev_sha1); |
348 | if (!commit || parse_commit(commit)) | 348 | if (!commit || parse_commit(commit)) { |
349 | cgit_print_error(fmt("Bad commit: %s", sha1_to_hex(new_rev_sha1))); | 349 | cgit_print_error(fmt("Bad commit: %s", sha1_to_hex(new_rev_sha1))); |
350 | return; | ||
351 | } | ||
350 | 352 | ||
351 | if (old_rev) | 353 | if (old_rev) |
352 | get_sha1(old_rev, old_rev_sha1); | 354 | get_sha1(old_rev, old_rev_sha1); |
@@ -362,8 +364,10 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefi | |||
362 | return; | 364 | return; |
363 | } | 365 | } |
364 | commit2 = lookup_commit_reference(old_rev_sha1); | 366 | commit2 = lookup_commit_reference(old_rev_sha1); |
365 | if (!commit2 || parse_commit(commit2)) | 367 | if (!commit2 || parse_commit(commit2)) { |
366 | cgit_print_error(fmt("Bad commit: %s", sha1_to_hex(old_rev_sha1))); | 368 | cgit_print_error(fmt("Bad commit: %s", sha1_to_hex(old_rev_sha1))); |
369 | return; | ||
370 | } | ||
367 | } | 371 | } |
368 | 372 | ||
369 | if ((ctx.qry.ssdiff && !ctx.cfg.ssdiff) || (!ctx.qry.ssdiff && ctx.cfg.ssdiff)) | 373 | if ((ctx.qry.ssdiff && !ctx.cfg.ssdiff) || (!ctx.qry.ssdiff && ctx.cfg.ssdiff)) |
diff --git a/ui-repolist.c b/ui-repolist.c index 2c98668..e138f59 100644 --- a/ui-repolist.c +++ b/ui-repolist.c | |||
@@ -20,7 +20,7 @@ time_t read_agefile(char *path) | |||
20 | if (readfile(path, &buf, &size)) | 20 | if (readfile(path, &buf, &size)) |
21 | return -1; | 21 | return -1; |
22 | 22 | ||
23 | if (parse_date(buf, buf2, sizeof(buf2))) | 23 | if (parse_date(buf, buf2, sizeof(buf2)) > 0) |
24 | result = strtoul(buf2, NULL, 10); | 24 | result = strtoul(buf2, NULL, 10); |
25 | else | 25 | else |
26 | result = 0; | 26 | result = 0; |