* Troubles using special characters in links with lighttpd
@ 2015-05-15 12:08 demelier.david
2015-05-15 12:24 ` john
0 siblings, 1 reply; 6+ messages in thread
From: demelier.david @ 2015-05-15 12:08 UTC (permalink / raw)
Hello,
I'm trying to setup cgit with lighttpd, this is my actual
configuration :
$HTTP["host"] == "git.malikania.fr" {
alias.url = (
"/static/" => "/usr/local/www/cgit/",
"/cgit.cgi" => "/usr/local/www/cgit/cgit.cgi",
)
url.rewrite-once =
(
"^/static/.*$" => "$0",
"^/([^?/]+/[^?]*)?(?:\?(.*))?$" => "/cgit.cgi?url=$1&
$2",
)
server.document-root = "/usr/local/www/cgit"
cgi.assign = ( ".cgi" => "/usr/local/www/cgit/cgit.cgi" )
}
I have found several documents about that, this is mainly written from
[1].
Almost everythin works, except directories that contains special
characters that should be escaped. For example, I have a directory named
"C++", and this one will not work from the rewrite rule:
http://git.malikania.fr/code/tree/
If you click on C++, you get an empty directory, however, the resolved
link with appropriate characters works fine:
http://git.malikania.fr/code/tree/C%2b%2b
I have no idea how to fix that, is it a lighttpd problem or a cgit
configuration missing?
Regards,
David.
[1]:
https://github.com/willysr/SlackHacks/blob/master/SlackBuilds/cgit/config/cgit-lighttpd.conf
^ permalink raw reply [flat|nested] 6+ messages in thread
* Troubles using special characters in links with lighttpd
2015-05-15 12:08 Troubles using special characters in links with lighttpd demelier.david
@ 2015-05-15 12:24 ` john
2015-05-15 12:39 ` john
0 siblings, 1 reply; 6+ messages in thread
From: john @ 2015-05-15 12:24 UTC (permalink / raw)
On Fri, May 15, 2015 at 02:08:23PM +0200, David Demelier wrote:
> I'm trying to setup cgit with lighttpd, this is my actual
> configuration :
>
> $HTTP["host"] == "git.malikania.fr" {
> alias.url = (
> "/static/" => "/usr/local/www/cgit/",
> "/cgit.cgi" => "/usr/local/www/cgit/cgit.cgi",
> )
> url.rewrite-once =
> (
> "^/static/.*$" => "$0",
> "^/([^?/]+/[^?]*)?(?:\?(.*))?$" => "/cgit.cgi?url=$1&
> $2",
> )
> server.document-root = "/usr/local/www/cgit"
> cgi.assign = ( ".cgi" => "/usr/local/www/cgit/cgit.cgi" )
> }
>
>
> I have found several documents about that, this is mainly written from
> [1].
>
> Almost everythin works, except directories that contains special
> characters that should be escaped. For example, I have a directory named
> "C++", and this one will not work from the rewrite rule:
>
> http://git.malikania.fr/code/tree/
>
> If you click on C++, you get an empty directory, however, the resolved
> link with appropriate characters works fine:
>
> http://git.malikania.fr/code/tree/C%2b%2b
>
> I have no idea how to fix that, is it a lighttpd problem or a cgit
> configuration missing?
I think CGit should be encoding the '+' in the path here, but according
to [1] that isn't required in the path element of a URL, so something
else must be wrong.
The patch below should cause CGit to escape the '+', but I haven't had
time to analyze the full implications, so I'm not sure if it will break
anything else (a cursory look suggests it will be OK but I want to spend
a bit more time examining all the callers before sending a proper
patch).
[1] http://blog.lunatech.com/2009/02/03/what-every-web-developer-must-know-about-url-encoding
-- >8 --
diff --git a/html.c b/html.c
index 155cde5..c61db1c 100644
--- a/html.c
+++ b/html.c
@@ -222,7 +222,7 @@ void html_url_path(const char *txt)
while (t && *t) {
unsigned char c = *t;
const char *e = url_escape_table[c];
- if (e && c != '+' && c != '&') {
+ if (e && c != '&') {
html_raw(txt, t - txt);
html(e);
txt = t + 1;
^ permalink raw reply [flat|nested] 6+ messages in thread
* Troubles using special characters in links with lighttpd
2015-05-15 12:24 ` john
@ 2015-05-15 12:39 ` john
2015-05-15 13:12 ` demelier.david
0 siblings, 1 reply; 6+ messages in thread
From: john @ 2015-05-15 12:39 UTC (permalink / raw)
On Fri, May 15, 2015 at 01:24:29PM +0100, John Keeping wrote:
> On Fri, May 15, 2015 at 02:08:23PM +0200, David Demelier wrote:
> > I'm trying to setup cgit with lighttpd, this is my actual
> > configuration :
> >
> > $HTTP["host"] == "git.malikania.fr" {
> > alias.url = (
> > "/static/" => "/usr/local/www/cgit/",
> > "/cgit.cgi" => "/usr/local/www/cgit/cgit.cgi",
> > )
> > url.rewrite-once =
> > (
> > "^/static/.*$" => "$0",
> > "^/([^?/]+/[^?]*)?(?:\?(.*))?$" => "/cgit.cgi?url=$1&
> > $2",
> > )
> > server.document-root = "/usr/local/www/cgit"
> > cgi.assign = ( ".cgi" => "/usr/local/www/cgit/cgit.cgi" )
> > }
> >
> >
> > I have found several documents about that, this is mainly written from
> > [1].
> >
> > Almost everythin works, except directories that contains special
> > characters that should be escaped. For example, I have a directory named
> > "C++", and this one will not work from the rewrite rule:
> >
> > http://git.malikania.fr/code/tree/
> >
> > If you click on C++, you get an empty directory, however, the resolved
> > link with appropriate characters works fine:
> >
> > http://git.malikania.fr/code/tree/C%2b%2b
> >
> > I have no idea how to fix that, is it a lighttpd problem or a cgit
> > configuration missing?
>
> I think CGit should be encoding the '+' in the path here, but according
> to [1] that isn't required in the path element of a URL, so something
> else must be wrong.
I looked a bit closer and noticed that you have "C" and "C++"
directories; the page for "C++" looks like it shows the path "root/C" at
the top, but the content is different from the proper "C" page. "View
Source" shows what's happening:
<a href="/code/tree/C%20%20">C </a>
So I think what's happening is that you rewrite the URL from:
/code/tree/C++
to:
/cgit.cgi?url=code/tree/C++
but now the path is in the query part not the path part and the escaping
rules are different, so "+" translates to " ".
I'm not sure if lighttpd will allow you to call a CGI script with a
path. In Apache you can do this:
RewriteRule ^/var/www/cgit(.*) /cgi-bin/cgit.cgi$1 [L,PT]
The patch below is still a good idea, but both CGit and lighttpd are
behaving correctly, the problem is using a rewrite rule that moves
something from the path part of a URL to the query part without taking
account of the different rules for escaping.
> The patch below should cause CGit to escape the '+', but I haven't had
> time to analyze the full implications, so I'm not sure if it will break
> anything else (a cursory look suggests it will be OK but I want to spend
> a bit more time examining all the callers before sending a proper
> patch).
>
> [1] http://blog.lunatech.com/2009/02/03/what-every-web-developer-must-know-about-url-encoding
>
> -- >8 --
> diff --git a/html.c b/html.c
> index 155cde5..c61db1c 100644
> --- a/html.c
> +++ b/html.c
> @@ -222,7 +222,7 @@ void html_url_path(const char *txt)
> while (t && *t) {
> unsigned char c = *t;
> const char *e = url_escape_table[c];
> - if (e && c != '+' && c != '&') {
> + if (e && c != '&') {
> html_raw(txt, t - txt);
> html(e);
> txt = t + 1;
> _______________________________________________
> CGit mailing list
> CGit at lists.zx2c4.com
> http://lists.zx2c4.com/mailman/listinfo/cgit
^ permalink raw reply [flat|nested] 6+ messages in thread
* Troubles using special characters in links with lighttpd
2015-05-15 12:39 ` john
@ 2015-05-15 13:12 ` demelier.david
2015-05-15 13:32 `
2015-05-15 13:34 ` john
0 siblings, 2 replies; 6+ messages in thread
From: demelier.david @ 2015-05-15 13:12 UTC (permalink / raw)
On Fri, 2015-05-15 at 13:39 +0100, John Keeping wrote:
> On Fri, May 15, 2015 at 01:24:29PM +0100, John Keeping wrote:
>
> <a href="/code/tree/C%20%20">C </a>
>
> So I think what's happening is that you rewrite the URL from:
>
> /code/tree/C++
>
> to:
>
> /cgit.cgi?url=code/tree/C++
>
> but now the path is in the query part not the path part and the escaping
> rules are different, so "+" translates to " ".
>
Thanks for your quick answer!
Okay, I understand the problem. I can't remember where do I saw the
usage of url parameter instead.
I've switched to this instead :
$HTTP["host"] == "git.malikania.fr" {
server.errorlog =
"/var/log/lighttpd/cgit-error.log"
accesslog.filename = "/var/log/lighttpd/cgit-access.log"
server.document-root = "/usr/local/www/cgit"
cgi.assign = ( ".cgi" => "/usr/local/www/cgit/cgit.cgi" )
index-file.names = ( "cgit.cgi" )
$HTTP["url"] =~ "^/(.*)\.git" {
url.rewrite-once = (
"^(.*)?$" => "/cgit.cgi/$1"
)
}
}
I conditionnaly rewrite links only when searching for a directory
starting with .git (so that the cgit.css is not broken).
Works correctly now :-)
Only have to name my repositories with trailing .git though, if you have
an idea how I can improve that.
Thanks!
^ permalink raw reply [flat|nested] 6+ messages in thread
* Troubles using special characters in links with lighttpd
2015-05-15 13:12 ` demelier.david
@ 2015-05-15 13:32 `
2015-05-15 13:34 ` john
1 sibling, 0 replies; 6+ messages in thread
From: @ 2015-05-15 13:32 UTC (permalink / raw)
Am 15.05.2015 um 15:12 schrieb David Demelier:
> Only have to name my repositories with trailing .git though, if you have
> an idea how I can improve that.
No, the path of the repo, its url and its name are three different
things, which can be set independently. Take a look at REPOSITORY
SETTINGS in 'man cgitrc'. Using 'enable-git-config', this works
exceptionally well when combined with gitolite....
This can also be used for having directories with the same name as projects:
https://git.necoro.eu/portato.git/
https://git.necoro.eu/portato/web.git/
- Ren?
^ permalink raw reply [flat|nested] 6+ messages in thread
* Troubles using special characters in links with lighttpd
2015-05-15 13:12 ` demelier.david
2015-05-15 13:32 `
@ 2015-05-15 13:34 ` john
1 sibling, 0 replies; 6+ messages in thread
From: john @ 2015-05-15 13:34 UTC (permalink / raw)
On Fri, May 15, 2015 at 03:12:53PM +0200, David Demelier wrote:
> On Fri, 2015-05-15 at 13:39 +0100, John Keeping wrote:
> > On Fri, May 15, 2015 at 01:24:29PM +0100, John Keeping wrote:
> >
> > <a href="/code/tree/C%20%20">C </a>
> >
> > So I think what's happening is that you rewrite the URL from:
> >
> > /code/tree/C++
> >
> > to:
> >
> > /cgit.cgi?url=code/tree/C++
> >
> > but now the path is in the query part not the path part and the escaping
> > rules are different, so "+" translates to " ".
> >
>
> Thanks for your quick answer!
>
> Okay, I understand the problem. I can't remember where do I saw the
> usage of url parameter instead.
>
> I've switched to this instead :
> $HTTP["host"] == "git.malikania.fr" {
> server.errorlog =
> "/var/log/lighttpd/cgit-error.log"
> accesslog.filename = "/var/log/lighttpd/cgit-access.log"
>
> server.document-root = "/usr/local/www/cgit"
> cgi.assign = ( ".cgi" => "/usr/local/www/cgit/cgit.cgi" )
> index-file.names = ( "cgit.cgi" )
>
> $HTTP["url"] =~ "^/(.*)\.git" {
> url.rewrite-once = (
> "^(.*)?$" => "/cgit.cgi/$1"
> )
> }
> }
>
> I conditionnaly rewrite links only when searching for a directory
> starting with .git (so that the cgit.css is not broken).
>
> Works correctly now :-)
>
> Only have to name my repositories with trailing .git though, if you have
> an idea how I can improve that.
With Apache I have:
RewriteCond %{REQUEST_FILENAME} !-f
so that any request that doesn't match a file gets rewritten and passed
to CGit. I suspect you can do something similar in lighttpd providing
you don't need to serve anything that is neither a file nor a CGit
request.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2015-05-15 13:34 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-15 12:08 Troubles using special characters in links with lighttpd demelier.david
2015-05-15 12:24 ` john
2015-05-15 12:39 ` john
2015-05-15 13:12 ` demelier.david
2015-05-15 13:32 `
2015-05-15 13:34 ` john
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).