diff options
Diffstat (limited to 'url/third_party/mozilla/url_parse.cc')
-rw-r--r-- | url/third_party/mozilla/url_parse.cc | 54 |
1 files changed, 34 insertions, 20 deletions
diff --git a/url/third_party/mozilla/url_parse.cc b/url/third_party/mozilla/url_parse.cc index fbc8a9b..84a7558 100644 --- a/url/third_party/mozilla/url_parse.cc +++ b/url/third_party/mozilla/url_parse.cc @@ -455,45 +455,53 @@ void DoParseFileSystemURL(const CHAR* spec, int spec_len, Parsed* parsed) { // Initializes a path URL which is merely a scheme followed by a path. Examples // include "about:foo" and "javascript:alert('bar');" template<typename CHAR> -void DoParsePathURL(const CHAR* spec, int spec_len, Parsed* parsed) { +void DoParsePathURL(const CHAR* spec, int spec_len, + bool trim_path_end, + Parsed* parsed) { // Get the non-path and non-scheme parts of the URL out of the way, we never // use them. parsed->username.reset(); parsed->password.reset(); parsed->host.reset(); parsed->port.reset(); + parsed->path.reset(); parsed->query.reset(); parsed->ref.reset(); // Strip leading & trailing spaces and control characters. - int begin = 0; - TrimURL(spec, &begin, &spec_len); + int scheme_begin = 0; + TrimURL(spec, &scheme_begin, &spec_len, trim_path_end); // Handle empty specs or ones that contain only whitespace or control chars. - if (begin == spec_len) { + if (scheme_begin == spec_len) { parsed->scheme.reset(); parsed->path.reset(); return; } + int path_begin; // Extract the scheme, with the path being everything following. We also // handle the case where there is no scheme. - if (ExtractScheme(&spec[begin], spec_len - begin, &parsed->scheme)) { + if (ExtractScheme(&spec[scheme_begin], spec_len - scheme_begin, + &parsed->scheme)) { // Offset the results since we gave ExtractScheme a substring. - parsed->scheme.begin += begin; - - // For compatability with the standard URL parser, we treat no path as - // -1, rather than having a length of 0 (we normally wouldn't care so - // much for these non-standard URLs). - if (parsed->scheme.end() == spec_len - 1) - parsed->path.reset(); - else - parsed->path = MakeRange(parsed->scheme.end() + 1, spec_len); + parsed->scheme.begin += scheme_begin; + path_begin = parsed->scheme.end() + 1; } else { - // No scheme found, just path. + // No scheme case. parsed->scheme.reset(); - parsed->path = MakeRange(begin, spec_len); + path_begin = scheme_begin; } + + if (path_begin == spec_len) + return; + DCHECK_LT(path_begin, spec_len); + + ParsePath(spec, + MakeRange(path_begin, spec_len), + &parsed->path, + &parsed->query, + &parsed->ref); } template<typename CHAR> @@ -875,12 +883,18 @@ void ParseStandardURL(const base::char16* url, int url_len, Parsed* parsed) { DoParseStandardURL(url, url_len, parsed); } -void ParsePathURL(const char* url, int url_len, Parsed* parsed) { - DoParsePathURL(url, url_len, parsed); +void ParsePathURL(const char* url, + int url_len, + bool trim_path_end, + Parsed* parsed) { + DoParsePathURL(url, url_len, trim_path_end, parsed); } -void ParsePathURL(const base::char16* url, int url_len, Parsed* parsed) { - DoParsePathURL(url, url_len, parsed); +void ParsePathURL(const base::char16* url, + int url_len, + bool trim_path_end, + Parsed* parsed) { + DoParsePathURL(url, url_len, trim_path_end, parsed); } void ParseFileSystemURL(const char* url, int url_len, Parsed* parsed) { |