Allow '+', '-' and '.' in remote helper names
According to relevant RFCs, in addition to alphanumerics, the following characters are valid in URL scheme parts: '+', '-' and '.', but currently only alphanumerics are allowed in remote helper names. Allow those three characters in remote helper names (both 'foo://' and 'foo::' syntax). Signed-off-by: Ilari Liusvaara <ilari.liusvaara@elisanet.fi> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Ilari Liusvaara committed
Feb 23, 2010 at 14:33 UTC
53a52ff33d42faf2dcceea5b33f8049bd9416555
1 file changed
+17
-2
transport.c
+17
-2
@@ -872,6 +872,21 @@ static int is_file(const char *url)
872
return S_ISREG(buf.st_mode);
873
}
874
875
+static int isurlschemechar(int first_flag, int ch)
876
+{
877
+ /*
878
+ * The set of valid URL schemes, as per STD66 (RFC3986) is
879
+ * '[A-Za-z][A-Za-z0-9+.-]*'. But use sightly looser check
880
+ * of '[A-Za-z0-9][A-Za-z0-9+.-]*' because earlier version
881
+ * of check used '[A-Za-z0-9]+' so not to break any remote
882
+ * helpers.
883
+ */
884
+ int alphanumeric, special;
885
+ alphanumeric = ch > 0 && isalnum(ch);
886
+ special = ch == '+' || ch == '-' || ch == '.';
887
+ return alphanumeric || (!first_flag && special);
888
+}
889
+
890
static int is_url(const char *url)
891
{
892
const char *url2, *first_slash;
@@ -896,7 +911,7 @@ static int is_url(const char *url)
911
*/
912
url2 = url;
913
while (url2 < first_slash - 1) {
899
- if (!isalnum((unsigned char)*url2))
914
+ if (!isurlschemechar(url2 == url, (unsigned char)*url2))
915
return 0;
916
url2++;
917
}
@@ -929,7 +944,7 @@ struct transport *transport_get(struct remote *remote, const char *url)
944
if (url) {
945
const char *p = url;
946
932
- while (isalnum(*p))
947
+ while (isurlschemechar(p == url, *p))
948
p++;
949
if (!prefixcmp(p, "::"))
950
helper = xstrndup(url, p - url);