Diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
Say when nothing matches a mistyped url
| -rw-r--r-- | source/ui-repolist.c | 24 | |
| -rwxr-xr-x | tests/t0101-index.sh | 11 |
2 files changed, 34 insertions, 1 deletion
diff --git a/source/ui-repolist.c b/source/ui-repolist.c index 87abf0b..3eb9375 100644 --- a/source/ui-repolist.c +++ b/source/ui-repolist.c @@ -170,6 +170,23 @@ static int any_repos_visible(void) } /* + * Whether any listed repository lies under the url the request carried, + * whatever the search terms. + */ +static int any_repos_under_url(void) +{ + int i; + + for (i = 0; i < cgit_repolist.count; i++) { + struct cgit_repo *repo = &cgit_repolist.repos[i]; + + if (!repo->hide && !repo->ignore && matches_url(repo)) + return 1; + } + return 0; +} + +/* * currenturl is passed in because it is the same for every heading and every * row, and working it out here would mean an allocation and a free per cell. */ @@ -398,7 +415,12 @@ void cgit_print_repolist(void) cgit_read_repo_desc(&cgit_repolist.repos[i]); if (!any_repos_visible()) { - cgit_print_error_page(404, "Not Found", "No repositories found"); + // A url naming no repository or page lands here, as a prefix + // that no repository's url starts with. + if (ctx.qry.url && *ctx.qry.url && !any_repos_under_url()) + cgit_print_error_page(404, "Not Found", "Nothing matches this url"); + else + cgit_print_error_page(404, "Not Found", "No repositories found"); return; } diff --git a/tests/t0101-index.sh b/tests/t0101-index.sh index 0953b8d..fcf873b 100755 --- a/tests/t0101-index.sh +++ b/tests/t0101-index.sh @@ -53,6 +53,17 @@ test_expect_success 'a cut description keeps whole characters' ' grep ">日本語\.\.\.</a>" tmp ' +# A url naming no repository falls through to the index as a prefix that +# matches none, which is not the same as a search finding nothing. +test_expect_success 'a url matching no repository says so' ' + cgit_url "nonexistent/tree/" >tmp && + grep "^Status: 404" tmp && + grep "<div class=.error.>Nothing matches this url</div>" tmp && + cgit_query "q=nonexistent" >tmp && + grep "^Status: 404" tmp && + grep "<div class=.error.>No repositories found</div>" tmp +' + # The index sorts by a column only when asked, which nothing else exercises. test_expect_success 'the index sorts by a column on request' ' cgit_query "s=name" >tmp && |
