Skip to content

Commit e4c497a

Browse files
peffgitster
authored andcommitted
urlmatch: add underscore to URL_HOST_CHARS
When parsing a URL to normalize it, we allow hostnames to contain only dot (".") or dash ("-"), plus brackets and colons for IPv6 literals. This matches the old URL standard in RFC 1738, which says: host = hostname | hostnumber hostname = *[ domainlabel "." ] toplabel domainlabel = alphadigit | alphadigit *[ alphadigit | "-" ] alphadigit But this was later updated by RFC 3986, which is more liberal: host = IP-literal / IPv4address / reg-name reg-name = *( unreserved / pct-encoded / sub-delims ) unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" While names with underscore in them are not common and possibly violate some DNS rules, they do work in practice, and we will happily contact them over http://, git://, or ssh://. It seems odd to ignore them for purposes of URL matching, especially when the URL RFC seems to allow them. There shouldn't be any downside here. It's not a syntactically significant character in a URL, so we won't be confused about parsing; we'd have simply rejected such a URL previously (the test here checks the url code directly, but the obvious user-visible effect would be failing to match credential.http://foo_bar.example.com.helper, or similar config in http.<url>.*). Arguably we'd want to allow tilde ("~") here, too. There's likewise probably no downside, but I didn't add it simply because it seems like an even less likely character to appear in a hostname. Reported-by: Alex Waite <[email protected]> Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent af6d1d6 commit e4c497a

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

t/t0110-urlmatch-normalization.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ test_expect_success 'url authority' '
4747
test-tool urlmatch-normalization "scheme://@host" &&
4848
test-tool urlmatch-normalization "scheme://%00@host" &&
4949
! test-tool urlmatch-normalization "scheme://%%@host" &&
50-
! test-tool urlmatch-normalization "scheme://host_" &&
50+
test-tool urlmatch-normalization "scheme://host_" &&
5151
test-tool urlmatch-normalization "scheme://user:pass@host/" &&
5252
test-tool urlmatch-normalization "scheme://@host/" &&
5353
test-tool urlmatch-normalization "scheme://host/" &&

urlmatch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#define URL_DIGIT "0123456789"
66
#define URL_ALPHADIGIT URL_ALPHA URL_DIGIT
77
#define URL_SCHEME_CHARS URL_ALPHADIGIT "+.-"
8-
#define URL_HOST_CHARS URL_ALPHADIGIT ".-[:]" /* IPv6 literals need [:] */
8+
#define URL_HOST_CHARS URL_ALPHADIGIT ".-_[:]" /* IPv6 literals need [:] */
99
#define URL_UNSAFE_CHARS " <>\"%{}|\\^`" /* plus 0x00-0x1F,0x7F-0xFF */
1010
#define URL_GEN_RESERVED ":/?#[]@"
1111
#define URL_SUB_RESERVED "!$&'()*+,;="

0 commit comments

Comments
 (0)