From 36612e4daf8b5b5eaf16315aa13c66925f878cd6 Mon Sep 17 00:00:00 2001 From: Jakub Narebski Date: Tue, 28 Feb 2012 19:41:47 +0100 Subject: gitweb: Handle invalid regexp in regexp search When using regexp search ('sr' parameter / $search_use_regexp variable is true), check first that regexp is valid. Without this patch we would get an error from Perl during search (if searching is performed by gitweb), or highlighting matches substring (if applicable), if user provided invalid regexp... which means broken HTML, with error page (including HTTP headers) generated after gitweb already produced some output. Add test that illustrates such error: for example for regexp "*\.git" we would get the following error: Quantifier follows nothing in regex; marked by <-- HERE in m/* <-- HERE \.git/ at /var/www/cgi-bin/gitweb.cgi line 3084. Reported-by: Ramsay Jones Signed-off-by: Jakub Narebski Signed-off-by: Junio C Hamano --- t/t9501-gitweb-standalone-http-status.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 't/t9501-gitweb-standalone-http-status.sh') diff --git a/t/t9501-gitweb-standalone-http-status.sh b/t/t9501-gitweb-standalone-http-status.sh index 26102ee9b0..31076edc5b 100755 --- a/t/t9501-gitweb-standalone-http-status.sh +++ b/t/t9501-gitweb-standalone-http-status.sh @@ -134,4 +134,14 @@ our $maxload = undef; EOF +# ---------------------------------------------------------------------- +# invalid arguments + +test_expect_success 'invalid arguments: invalid regexp (in project search)' ' + gitweb_run "a=project_list;s=*\.git;sr=1" && + grep "Status: 400" gitweb.headers && + grep "400 - Invalid.*regexp" gitweb.body +' +test_debug 'cat gitweb.headers' + test_done -- cgit v1.2.1 From b7d565ea4c2bd6d0c79e512eeca77beb15736f80 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Thu, 29 Mar 2012 08:45:48 -0400 Subject: gitweb: refactor If-Modified-Since handling The current gitweb only generates Last-Modified and handles If-Modified-Since headers for the git_feed action. This patch breaks the Last-Modified and If-Modified-Since handling code out from git_feed into a new function exit_if_unmodified_since. This makes the code easy to reuse for other actions. Only gitweb actions which can easily calculate a modification time should use exit_if_unmodified_since, as the goal is to balance local processing time vs. upload bandwidth. Signed-off-by: W Trevor King Acked-by: Jakub Narebski Signed-off-by: Junio C Hamano --- t/t9501-gitweb-standalone-http-status.sh | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 't/t9501-gitweb-standalone-http-status.sh') diff --git a/t/t9501-gitweb-standalone-http-status.sh b/t/t9501-gitweb-standalone-http-status.sh index 31076edc5b..358010315f 100755 --- a/t/t9501-gitweb-standalone-http-status.sh +++ b/t/t9501-gitweb-standalone-http-status.sh @@ -92,7 +92,7 @@ test_debug 'cat gitweb.output' test_expect_success 'snapshots: bad tree-ish id (tagged object)' ' echo object > tag-object && git add tag-object && - git commit -m "Object to be tagged" && + test_tick && git commit -m "Object to be tagged" && git tag tagged-object `git hash-object tag-object` && gitweb_run "p=.git;a=snapshot;h=tagged-object;sf=tgz" && grep "400 - Object is not a tree-ish" gitweb.output @@ -112,6 +112,31 @@ test_expect_success 'snapshots: bad object id' ' ' test_debug 'cat gitweb.output' +# ---------------------------------------------------------------------- +# modification times (Last-Modified and If-Modified-Since) + +test_expect_success 'modification: feed last-modified' ' + gitweb_run "p=.git;a=atom;h=master" && + grep "Status: 200 OK" gitweb.headers && + grep "Last-modified: Thu, 7 Apr 2005 22:14:13 +0000" gitweb.headers +' +test_debug 'cat gitweb.headers' + +test_expect_success 'modification: feed if-modified-since (modified)' ' + export HTTP_IF_MODIFIED_SINCE="Wed, 6 Apr 2005 22:14:13 +0000" && + test_when_finished "unset HTTP_IF_MODIFIED_SINCE" && + gitweb_run "p=.git;a=atom;h=master" && + grep "Status: 200 OK" gitweb.headers +' +test_debug 'cat gitweb.headers' + +test_expect_success 'modification: feed if-modified-since (unmodified)' ' + export HTTP_IF_MODIFIED_SINCE="Thu, 7 Apr 2005 22:14:13 +0000" && + test_when_finished "unset HTTP_IF_MODIFIED_SINCE" && + gitweb_run "p=.git;a=atom;h=master" && + grep "Status: 304 Not Modified" gitweb.headers +' +test_debug 'cat gitweb.headers' # ---------------------------------------------------------------------- # load checking -- cgit v1.2.1 From 8745db63ca65c28221229df3d945cb10045c29dc Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Thu, 29 Mar 2012 08:45:49 -0400 Subject: gitweb: add If-Modified-Since handling to git_snapshot(). Because snapshots can be large, you can save some bandwidth by supporting caching via If-Modified-Since. This patch adds support for the i-m-s request to git_snapshot() if the request is a commit. Requests for snapshots of trees, which lack well defined timestamps, are still handled as they were before. Signed-off-by: W Trevor King Signed-off-by: Junio C Hamano --- t/t9501-gitweb-standalone-http-status.sh | 33 ++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 't/t9501-gitweb-standalone-http-status.sh') diff --git a/t/t9501-gitweb-standalone-http-status.sh b/t/t9501-gitweb-standalone-http-status.sh index 358010315f..fa2f65f6be 100755 --- a/t/t9501-gitweb-standalone-http-status.sh +++ b/t/t9501-gitweb-standalone-http-status.sh @@ -138,6 +138,39 @@ test_expect_success 'modification: feed if-modified-since (unmodified)' ' ' test_debug 'cat gitweb.headers' +test_expect_success 'modification: snapshot last-modified' ' + gitweb_run "p=.git;a=snapshot;h=master;sf=tgz" && + grep "Status: 200 OK" gitweb.headers && + grep "Last-modified: Thu, 7 Apr 2005 22:14:13 +0000" gitweb.headers +' +test_debug 'cat gitweb.headers' + +test_expect_success 'modification: snapshot if-modified-since (modified)' ' + export HTTP_IF_MODIFIED_SINCE="Wed, 6 Apr 2005 22:14:13 +0000" && + test_when_finished "unset HTTP_IF_MODIFIED_SINCE" && + gitweb_run "p=.git;a=snapshot;h=master;sf=tgz" && + grep "Status: 200 OK" gitweb.headers +' +test_debug 'cat gitweb.headers' + +test_expect_success 'modification: snapshot if-modified-since (unmodified)' ' + export HTTP_IF_MODIFIED_SINCE="Thu, 7 Apr 2005 22:14:13 +0000" && + test_when_finished "unset HTTP_IF_MODIFIED_SINCE" && + gitweb_run "p=.git;a=snapshot;h=master;sf=tgz" && + grep "Status: 304 Not Modified" gitweb.headers +' +test_debug 'cat gitweb.headers' + +test_expect_success 'modification: tree snapshot' ' + ID=`git rev-parse --verify HEAD^{tree}` && + export HTTP_IF_MODIFIED_SINCE="Wed, 6 Apr 2005 22:14:13 +0000" && + test_when_finished "unset HTTP_IF_MODIFIED_SINCE" && + gitweb_run "p=.git;a=snapshot;h=$ID;sf=tgz" && + grep "Status: 200 OK" gitweb.headers && + ! grep -i "last-modified" gitweb.headers +' +test_debug 'cat gitweb.headers' + # ---------------------------------------------------------------------- # load checking -- cgit v1.2.1 From 2a8a4490c20e3f39dc15721b49715867511163ba Mon Sep 17 00:00:00 2001 From: Ramsay Jones Date: Tue, 12 Jun 2012 19:09:38 +0100 Subject: gitweb: Skip 'modification times' tests when no date parser available The If-Modified-Since support in Gitweb is conditional on the availability of a date parser from either the HTTP::Date or Time::ParseDate modules. If a suitable parser is not available, then the corresponding 'modification times' tests should be skipped. Introduce the DATE_PARSER test prerequisite and use it to skip all of the dependent tests. Signed-off-by: Ramsay Jones Signed-off-by: Junio C Hamano --- t/t9501-gitweb-standalone-http-status.sh | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 't/t9501-gitweb-standalone-http-status.sh') diff --git a/t/t9501-gitweb-standalone-http-status.sh b/t/t9501-gitweb-standalone-http-status.sh index fa2f65f6be..ef86948d21 100755 --- a/t/t9501-gitweb-standalone-http-status.sh +++ b/t/t9501-gitweb-standalone-http-status.sh @@ -12,6 +12,13 @@ code and message.' . ./gitweb-lib.sh +# +# Gitweb only provides the functionality tested by the 'modification times' +# tests if it can access a date parser from one of these modules: +# +perl -MHTTP::Date -e 0 >/dev/null 2>&1 && test_set_prereq DATE_PARSER +perl -MTime::ParseDate -e 0 >/dev/null 2>&1 && test_set_prereq DATE_PARSER + # ---------------------------------------------------------------------- # snapshot settings @@ -115,14 +122,14 @@ test_debug 'cat gitweb.output' # ---------------------------------------------------------------------- # modification times (Last-Modified and If-Modified-Since) -test_expect_success 'modification: feed last-modified' ' +test_expect_success DATE_PARSER 'modification: feed last-modified' ' gitweb_run "p=.git;a=atom;h=master" && grep "Status: 200 OK" gitweb.headers && grep "Last-modified: Thu, 7 Apr 2005 22:14:13 +0000" gitweb.headers ' test_debug 'cat gitweb.headers' -test_expect_success 'modification: feed if-modified-since (modified)' ' +test_expect_success DATE_PARSER 'modification: feed if-modified-since (modified)' ' export HTTP_IF_MODIFIED_SINCE="Wed, 6 Apr 2005 22:14:13 +0000" && test_when_finished "unset HTTP_IF_MODIFIED_SINCE" && gitweb_run "p=.git;a=atom;h=master" && @@ -130,7 +137,7 @@ test_expect_success 'modification: feed if-modified-since (modified)' ' ' test_debug 'cat gitweb.headers' -test_expect_success 'modification: feed if-modified-since (unmodified)' ' +test_expect_success DATE_PARSER 'modification: feed if-modified-since (unmodified)' ' export HTTP_IF_MODIFIED_SINCE="Thu, 7 Apr 2005 22:14:13 +0000" && test_when_finished "unset HTTP_IF_MODIFIED_SINCE" && gitweb_run "p=.git;a=atom;h=master" && @@ -138,14 +145,14 @@ test_expect_success 'modification: feed if-modified-since (unmodified)' ' ' test_debug 'cat gitweb.headers' -test_expect_success 'modification: snapshot last-modified' ' +test_expect_success DATE_PARSER 'modification: snapshot last-modified' ' gitweb_run "p=.git;a=snapshot;h=master;sf=tgz" && grep "Status: 200 OK" gitweb.headers && grep "Last-modified: Thu, 7 Apr 2005 22:14:13 +0000" gitweb.headers ' test_debug 'cat gitweb.headers' -test_expect_success 'modification: snapshot if-modified-since (modified)' ' +test_expect_success DATE_PARSER 'modification: snapshot if-modified-since (modified)' ' export HTTP_IF_MODIFIED_SINCE="Wed, 6 Apr 2005 22:14:13 +0000" && test_when_finished "unset HTTP_IF_MODIFIED_SINCE" && gitweb_run "p=.git;a=snapshot;h=master;sf=tgz" && @@ -153,7 +160,7 @@ test_expect_success 'modification: snapshot if-modified-since (modified)' ' ' test_debug 'cat gitweb.headers' -test_expect_success 'modification: snapshot if-modified-since (unmodified)' ' +test_expect_success DATE_PARSER 'modification: snapshot if-modified-since (unmodified)' ' export HTTP_IF_MODIFIED_SINCE="Thu, 7 Apr 2005 22:14:13 +0000" && test_when_finished "unset HTTP_IF_MODIFIED_SINCE" && gitweb_run "p=.git;a=snapshot;h=master;sf=tgz" && @@ -161,7 +168,7 @@ test_expect_success 'modification: snapshot if-modified-since (unmodified)' ' ' test_debug 'cat gitweb.headers' -test_expect_success 'modification: tree snapshot' ' +test_expect_success DATE_PARSER 'modification: tree snapshot' ' ID=`git rev-parse --verify HEAD^{tree}` && export HTTP_IF_MODIFIED_SINCE="Wed, 6 Apr 2005 22:14:13 +0000" && test_when_finished "unset HTTP_IF_MODIFIED_SINCE" && -- cgit v1.2.1 From d87ec816cd2459a27c1d22ae3947d67c8b121bd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20B=C3=B6gershausen?= Date: Fri, 26 Apr 2013 11:18:07 +0200 Subject: t9501: do not use export X=Y MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The shell syntax "export X=Y" is not understood by all shells. Signed-off-by: Torsten Bögershausen Signed-off-by: Junio C Hamano --- t/t9501-gitweb-standalone-http-status.sh | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 't/t9501-gitweb-standalone-http-status.sh') diff --git a/t/t9501-gitweb-standalone-http-status.sh b/t/t9501-gitweb-standalone-http-status.sh index ef86948d21..d3a5bac754 100755 --- a/t/t9501-gitweb-standalone-http-status.sh +++ b/t/t9501-gitweb-standalone-http-status.sh @@ -130,7 +130,8 @@ test_expect_success DATE_PARSER 'modification: feed last-modified' ' test_debug 'cat gitweb.headers' test_expect_success DATE_PARSER 'modification: feed if-modified-since (modified)' ' - export HTTP_IF_MODIFIED_SINCE="Wed, 6 Apr 2005 22:14:13 +0000" && + HTTP_IF_MODIFIED_SINCE="Wed, 6 Apr 2005 22:14:13 +0000" && + export HTTP_IF_MODIFIED_SINCE && test_when_finished "unset HTTP_IF_MODIFIED_SINCE" && gitweb_run "p=.git;a=atom;h=master" && grep "Status: 200 OK" gitweb.headers @@ -138,7 +139,8 @@ test_expect_success DATE_PARSER 'modification: feed if-modified-since (modified) test_debug 'cat gitweb.headers' test_expect_success DATE_PARSER 'modification: feed if-modified-since (unmodified)' ' - export HTTP_IF_MODIFIED_SINCE="Thu, 7 Apr 2005 22:14:13 +0000" && + HTTP_IF_MODIFIED_SINCE="Thu, 7 Apr 2005 22:14:13 +0000" && + export HTTP_IF_MODIFIED_SINCE && test_when_finished "unset HTTP_IF_MODIFIED_SINCE" && gitweb_run "p=.git;a=atom;h=master" && grep "Status: 304 Not Modified" gitweb.headers @@ -153,7 +155,8 @@ test_expect_success DATE_PARSER 'modification: snapshot last-modified' ' test_debug 'cat gitweb.headers' test_expect_success DATE_PARSER 'modification: snapshot if-modified-since (modified)' ' - export HTTP_IF_MODIFIED_SINCE="Wed, 6 Apr 2005 22:14:13 +0000" && + HTTP_IF_MODIFIED_SINCE="Wed, 6 Apr 2005 22:14:13 +0000" && + export HTTP_IF_MODIFIED_SINCE && test_when_finished "unset HTTP_IF_MODIFIED_SINCE" && gitweb_run "p=.git;a=snapshot;h=master;sf=tgz" && grep "Status: 200 OK" gitweb.headers @@ -161,7 +164,8 @@ test_expect_success DATE_PARSER 'modification: snapshot if-modified-since (modif test_debug 'cat gitweb.headers' test_expect_success DATE_PARSER 'modification: snapshot if-modified-since (unmodified)' ' - export HTTP_IF_MODIFIED_SINCE="Thu, 7 Apr 2005 22:14:13 +0000" && + HTTP_IF_MODIFIED_SINCE="Thu, 7 Apr 2005 22:14:13 +0000" && + export HTTP_IF_MODIFIED_SINCE && test_when_finished "unset HTTP_IF_MODIFIED_SINCE" && gitweb_run "p=.git;a=snapshot;h=master;sf=tgz" && grep "Status: 304 Not Modified" gitweb.headers @@ -170,7 +174,8 @@ test_debug 'cat gitweb.headers' test_expect_success DATE_PARSER 'modification: tree snapshot' ' ID=`git rev-parse --verify HEAD^{tree}` && - export HTTP_IF_MODIFIED_SINCE="Wed, 6 Apr 2005 22:14:13 +0000" && + HTTP_IF_MODIFIED_SINCE="Wed, 6 Apr 2005 22:14:13 +0000" && + export HTTP_IF_MODIFIED_SINCE && test_when_finished "unset HTTP_IF_MODIFIED_SINCE" && gitweb_run "p=.git;a=snapshot;h=$ID;sf=tgz" && grep "Status: 200 OK" gitweb.headers && -- cgit v1.2.1