Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1399)

Unified Diff: src/url_parse.cc

Issue 115748: url_parse: Segment partially-typed IPv6 literals.... (Closed) Base URL: http://google-url.googlecode.com/svn/trunk/
Patch Set: '' Created 11 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/url_parse_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/url_parse.cc
===================================================================
--- src/url_parse.cc (revision 104)
+++ src/url_parse.cc (working copy)
@@ -147,31 +147,33 @@
return;
}
- // Search backwards for a ':' but stop on ']' (IPv6 address literal
- // delimiter).
- int i = serverinfo.begin + serverinfo.len - 1;
- int colon = -1, bracket = -1;
- while (i >= serverinfo.begin && colon < 0) {
+ // If the host starts with a left-bracket, assume the entire host is an
+ // IPv6 literal. Otherwise, assume none of the host is an IPv6 literal.
+ // This assumption will be overridden if we find a right-bracket.
+ //
+ // Our IPv6 address canonicalization code requires both brackets to exist,
+ // but the ability to locate an incomplete address can still be useful.
+ int ipv6_terminator = spec[serverinfo.begin] == '[' ? serverinfo.end() : -1;
+ int colon = -1;
+
+ // Find the last right-bracket, and the last colon.
+ for (int i = serverinfo.begin; i < serverinfo.end(); i++) {
switch (spec[i]) {
case ']':
- bracket = i;
+ ipv6_terminator = i;
break;
case ':':
- if (bracket < 0)
- colon = i; // Will cause loop to terminate.
+ colon = i;
break;
}
- i--;
}
- if (colon >= 0) {
+ if (colon > ipv6_terminator) {
// Found a port number: <hostname>:<port>
- int host_len = colon - serverinfo.begin;
- if (host_len)
- *hostname = MakeRange(serverinfo.begin, colon);
- else
+ *hostname = MakeRange(serverinfo.begin, colon);
+ if (hostname->len == 0)
hostname->reset();
- *port_num = MakeRange(colon + 1, serverinfo.begin + serverinfo.len);
+ *port_num = MakeRange(colon + 1, serverinfo.end());
} else {
// No port: <hostname>
*hostname = serverinfo;
@@ -386,7 +388,7 @@
parsed->host.reset();
parsed->port.reset();
parsed->ref.reset();
- parsed->query.reset(); // May use this; reset for convenience.
+ parsed->query.reset(); // May use this; reset for convenience.
// Strip leading & trailing spaces and control characters.
int begin = 0;
@@ -444,7 +446,7 @@
template<typename CHAR>
int DoParsePort(const CHAR* spec, const Component& component) {
// Easy success case when there is no port.
- const int max_digits = 5;
+ const int kMaxDigits = 5;
if (!component.is_nonempty())
return PORT_UNSPECIFIED;
@@ -461,11 +463,11 @@
// Verify we don't have too many digits (we'll be copying to our buffer so
// we need to double-check).
- if (digits_comp.len > max_digits)
+ if (digits_comp.len > kMaxDigits)
return PORT_INVALID;
// Copy valid digits to the buffer.
- char digits[max_digits + 1]; // +1 for null terminator
+ char digits[kMaxDigits + 1]; // +1 for null terminator
for (int i = 0; i < digits_comp.len; i++) {
CHAR ch = spec[digits_comp.begin + i];
if (!IsPortDigit(ch)) {
« no previous file with comments | « no previous file | src/url_parse_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698