List for cgit developers and users
 help / color / mirror / Atom feed
From: john at keeping.me.uk (John Keeping)
Subject: [PATCH] parsing: don't clear existing state with empty input
Date: Sat, 14 Oct 2017 13:02:53 +0100	[thread overview]
Message-ID: <03593065512ae1eac1d8a96446cb38fe16ac6055.1507982215.git.john@keeping.me.uk> (raw)

Since commit c699866 (parsing: clear query path before starting,
2017-02-19), we clear the "page" variable simply by calling
cgit_parse_url() even if the URL is empty.  This breaks a URL like:

	.../cgit?p=about

which is generated when using the "root-readme" configuration option.

This happens because "page" is set to "about" when parsing the query
string before we handle the path (which is empty, but non-null).

It turns out that this is not the only case which is broken, but
specifying repository and page via query options has been broken since
before the commit mentioned above, for example:

	.../cgit?r=git&p=log

Fix both of these by allowing the previous state to persist if PATH_INFO
is empty, falling back to the query parameters if no path has been
requested.

Reported-by: Tom Ryder <tom at sanctum.geek.nz>
Signed-off-by: John Keeping <john at keeping.me.uk>
---
This is still a bit of a mess, but I'm not really sure what we should be
doing when both PATH_INFO and query parameters are provided.  At least
this change fixes the particular case Tom reported and I think it also
makes sure that any links we generate will be handled correctly.

 parsing.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/parsing.c b/parsing.c
index b8d7f10..fd1ea99 100644
--- a/parsing.c
+++ b/parsing.c
@@ -20,11 +20,10 @@ void cgit_parse_url(const char *url)
 	char *c, *cmd, *p;
 	struct cgit_repo *repo;
 
-	ctx.repo = NULL;
-	ctx.qry.page = NULL;
 	if (!url || url[0] == '\0')
 		return;
 
+	ctx.qry.page = NULL;
 	ctx.repo = cgit_get_repoinfo(url);
 	if (ctx.repo) {
 		ctx.qry.repo = ctx.repo->url;
-- 
2.14.1.555.g1b9dbff880.dirty



             reply	other threads:[~2017-10-14 12:02 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-14 12:02 john [this message]
2017-10-14 12:30 ` Jason

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=03593065512ae1eac1d8a96446cb38fe16ac6055.1507982215.git.john@keeping.me.uk \
    --to=cgit@lists.zx2c4.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).