Bug with URL-decoding
$ cd /tmp $ mkdir x+y $ cd x+y $ git init $ cd .. $ git clone file:///tmp/x%2By zz # <==== ERROR $ git clone file:///tmp/x+y zz # <====== OK
Funny characters do come up in names, especially in test suites
Quoted 9 lines · Dave Abrahams
$ cd /tmp $ mkdir x+y $ cd x+y $ git init $ cd .. $ git clone file:///tmp/x%2By zz # <==== ERROR $ git clone file:///tmp/x+y zz # <====== OKFunny characters do come up in names, especially in test suites
Yeah, at this point file:// is more or less just an alias for a straight path (and ssh:// an alias for "host:path" syntax). We correctly percent-decode http:// URLs because we just hand them to curl, which does the right thing. We should be decoding these ones when we pick apart the URL components.
Patch series to follow:
[1/2]: make url-related functions reusable
[2/2]: decode file:// and ssh:// URLs
With these patches, you can do:
git clone file:///tmp/x%2By
or
git clone /tmp/x+y
The former will clone into "x%2By". Which I'm not even sure is wrong, so I left it as-is.
-Peff
PATCH 1/2 make url-related functions reusable
The is_url function and url percent-decoding functions were static, but are generally useful. Let's make them available to other parts of the code.
---
There was some minor tweaking of the url_decode functions to be more generally useful.
Makefile | 1 + http-backend.c | 59 +-------------------------- transport.c | 51 +----------------------- url.c | 118 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ url.h | 10 +++++ 5 files changed, 134 insertions(+), 105 deletions(-) create mode 100644 url.c create mode 100644 url.h
Makefile +1 -0
@@ -627,6 +627,7 @@ LIB_OBJS += tree-diff.o LIB_OBJS += tree.o LIB_OBJS += tree-walk.o LIB_OBJS += unpack-trees.o +LIB_OBJS += url.o LIB_OBJS += usage.o LIB_OBJS += userdiff.o LIB_OBJS += utf8.o
http-backend.c +3 -56
77 lines not on this page · raw message
transport.c +2 -49
69 lines not on this page · raw message
url.c new file +118 -0
118 lines not on this page · raw message
url.h new file +10 -0
@@ -0,0 +1,10 @@ +#ifndef URL_H +#define URL_H + +extern int is_url (const char *url); +extern int is_urlschemechar (int first_flag,int ch); +extern char *url_decode (const char *url); +extern char *url_decode_parameter_name (const char **query); +extern char *url_decode_parameter_value (const char **query); + +#endif /* URL_H */
Signature · 1 line
1.7.1.356.gc7d3.dirty
PATCH 2/2 decode file:// and ssh:// URLs
In reply to Jeff KingWe generally treat these as equivalent to "/path/to/repo" and "host:path_to_repo" respectively. However, they are URLs and as such may be percent-encoded. The current code simply uses them as-is without any decoding.
With this patch, we will now percent-decode any file:// or ssh:// url (or ssh+git, git+ssh, etc) at the transport layer. We continue to treat plain paths and "host:path" syntax literally.
---
I think this also impacts git:// URLs. Which I is probably a good thing, but I haven't looked extensively for unexpected fallouts.
connect.c | 8 +++++++- t/t5601-clone.sh | 12 ++++++++++++ 2 files changed, 19 insertions(+), 1 deletions(-)
connect.c +7 -1
@@ -5,6 +5,7 @@#include "refs.h" #include "run-command.h" #include "remote.h" +#include "url.h" static char *server_capabilities;
@@ -450,7 +451,7 @@ static struct child_process no_fork;struct child_process *git_connect (int fd[2 ],const char *url_orig,const char *prog,int flags) { -char *url =xstrdup (url_orig); +char *url;char *host, *path;char *end;int c;
@@ -466,6 +467,11 @@ struct child_process *git_connect(int fd[2], const char *url_orig,*/ signal (SIGCHLD ,SIG_DFL ); +if (is_url (url_orig)) + url =url_decode (url_orig); +else + url =xstrdup (url_orig); + host =strstr (url,"://" );if (host) { *host ='\0' ;
t/t5601-clone.sh +12 -0
@@ -176,4 +176,16 @@ test_expect_success 'clone respects global branch.autosetuprebase' ' ) ' +test_expect_success 'respect url-encoding of file://' ' + git init x+y && + test_must_fail git clone "file://$PWD/x+y" xy-url && + git clone "file://$PWD/x%2By" xy-url +' + +test_expect_success 'do not respect url-encoding of non-url path' ' + git init x+y && + test_must_fail git clone x%2By xy-regular && + git clone x+y xy-regular +' + test_done
Signature · 1 line
1.7.1.356.gc7d3.dirty
Re: [PATCH 2/2] decode file:// and ssh:// URLs
Quoted 10 lines · Jeff King
We generally treat these as equivalent to "/path/to/repo" and "host:path_to_repo" respectively. However, they are URLs and as such may be percent-encoded. The current code simply uses them as-is without any decoding.
With this patch, we will now percent-decode any file:// or ssh:// url (or ssh+git, git+ssh, etc) at the transport layer. We continue to treat plain paths and "host:path" syntax literally.
Quoted 4 lines
Signed-off-by Jeff King <[email protected]>---
I think this also impactsgit://URLs. Which I is probably a good thing, but I haven't looked extensively for unexpected fallouts.
One possible fallout: IPv6 scope syntax uses literal '%' in host part. The relevant RFC indicates it should be escaped, but in the past connect would fail if it was... But then, who uses that syntax...
-Ilari
Re: [PATCH 2/2] decode file:// and ssh:// URLs
Quoted 8 lines · Ilari Liusvaara
Quoted 4 lines
With this patch, we will now percent-decode any file:// or ssh:// url (or ssh+git, git+ssh, etc) at the transport layer. We continue to treat plain paths and "host:path" syntax literally.
One possible fallout: IPv6 scope syntax uses literal '%' in host part. The relevant RFC indicates it should be escaped, but in the past connect would fail if it was... But then, who uses that syntax...
Bleh. I am not happy about breaking a syntax people might be using, but the current behavior is broken, which will cause problems for some other people. Short of doing some context-sensitive "is this probably a literal % in the host" heuristic (which I really think is a bad idea), I think we will have to break one or the other.
-Peff