changeset: 6817:2a6bfdb9f869
user: Kevin McCarthy <[email protected]>
date: Sat Oct 15 14:45:55 2016 -0700
link: http://dev.mutt.org/hg/mutt/rev/2a6bfdb9f869
Allow IPv6 literal addresses in URLs. (closes #3681)
RFCs 2732 and 3986 specify a literal IPv6 address be surrounded by
"[]".
This patch removes the "[]" delimiters when parsing the URL, but adds
them back in url_ciss_tostring() if the host name contains a ':'.
Thanks to Evgeni Golov for the original patch.
diffs (50 lines):
diff -r a3e35631b503 -r 2a6bfdb9f869 url.c
--- a/url.c Wed Oct 12 18:10:35 2016 -0700
+++ b/url.c Sat Oct 15 14:45:55 2016 -0700
@@ -143,7 +143,16 @@
ciss->user = src;
if (url_pct_decode (ciss->user) < 0)
return -1;
- t++;
+ src = t + 1;
+ }
+
+ /* IPv6 literal address. It may contain colons, so set t to start
+ * the port scan after it.
+ */
+ if ((*src == '[') && (t = strchr (src, ']')))
+ {
+ src++;
+ *t++ = '\0';
}
else
t = src;
@@ -159,7 +168,7 @@
else
ciss->port = 0;
- ciss->host = t;
+ ciss->host = src;
return url_pct_decode (ciss->host) >= 0 &&
(!ciss->path || url_pct_decode (ciss->path) >= 0) ? 0 : -1;
}
@@ -232,10 +241,17 @@
len -= (l = strlen (dest)); dest += l;
}
+ if (strchr (ciss->host, ':'))
+ snprintf (dest, len, "[%s]", ciss->host);
+ else
+ snprintf (dest, len, "%s", ciss->host);
+
+ len -= (l = strlen (dest)); dest += l;
+
if (ciss->port)
- snprintf (dest, len, "%s:%hu/", ciss->host, ciss->port);
+ snprintf (dest, len, ":%hu/", ciss->port);
else
- snprintf (dest, len, "%s/", ciss->host);
+ snprintf (dest, len, "/");
}
if (ciss->path)