From 0318f92ba7c54fc5ef6397c6d58250fea95c7196 Mon Sep 17 00:00:00 2001 From: "vitalybuka@chromium.org" Date: Tue, 22 Apr 2014 00:09:23 +0000 Subject: [PATCH] Renamed namespaces in src/url. url_util -> url url_parse -> url url_canon -> url BUG=364747 R=brettw@chromium.org, thestig@chromium.org, willchan@chromium.org Review URL: https://codereview.chromium.org/242463002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@265120 0039d316-1c4b-4281-b951-d872f2087c98 --- .../ui/webui/signin/user_manager_ui_browsertest.cc | 7 +- chrome/common/net/url_fixer_upper.h | 2 +- chrome/common/net/url_fixer_upper_unittest.cc | 4 +- net/base/net_util.h | 13 +- url/gurl.cc | 99 +- url/gurl.h | 30 +- url/gurl_unittest.cc | 42 +- url/third_party/mozilla/url_parse.cc | 16 +- url/third_party/mozilla/url_parse.h | 14 +- url/url_canon.h | 248 +++-- url/url_canon_etc.cc | 85 +- url/url_canon_filesystemurl.cc | 46 +- url/url_canon_fileurl.cc | 55 +- url/url_canon_host.cc | 34 +- url/url_canon_icu.cc | 4 +- url/url_canon_icu.h | 4 +- url/url_canon_internal.cc | 29 +- url/url_canon_internal.h | 14 +- url/url_canon_internal_file.h | 14 +- url/url_canon_ip.cc | 79 +- url/url_canon_ip.h | 34 +- url/url_canon_mailtourl.cc | 46 +- url/url_canon_path.cc | 28 +- url/url_canon_pathurl.cc | 34 +- url/url_canon_query.cc | 28 +- url/url_canon_relative.cc | 129 ++- url/url_canon_stdstring.cc | 4 +- url/url_canon_stdstring.h | 31 +- url/url_canon_stdurl.cc | 32 +- url/url_canon_unittest.cc | 1066 ++++++++++---------- url/url_export.h | 7 + url/url_file.h | 4 +- url/url_parse_file.cc | 4 +- url/url_parse_internal.h | 4 +- url/url_parse_unittest.cc | 66 +- url/url_test_utils.h | 19 +- url/url_util.cc | 257 +++-- url/url_util.h | 89 +- url/url_util_internal.h | 8 +- url/url_util_unittest.cc | 149 ++- 40 files changed, 1408 insertions(+), 1470 deletions(-) diff --git a/chrome/browser/ui/webui/signin/user_manager_ui_browsertest.cc b/chrome/browser/ui/webui/signin/user_manager_ui_browsertest.cc index 96c2366a9e03..dbdb6bbfa632 100644 --- a/chrome/browser/ui/webui/signin/user_manager_ui_browsertest.cc +++ b/chrome/browser/ui/webui/signin/user_manager_ui_browsertest.cc @@ -15,10 +15,6 @@ #include "grit/generated_resources.h" #include "ui/base/l10n/l10n_util.h" -namespace { -const GURL& url = GURL(chrome::kChromeUIUserManagerURL); -} // namespace - class UserManagerUIBrowserTest : public InProcessBrowserTest, public testing::WithParamInterface { public: @@ -37,7 +33,8 @@ class UserManagerUIBrowserTest : public InProcessBrowserTest, }; IN_PROC_BROWSER_TEST_F(UserManagerUIBrowserTest, PageLoads) { - ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(), url, 1); + ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( + browser(), GURL(chrome::kChromeUIUserManagerURL), 1); content::WebContents* web_contents = browser()->tab_strip_model()->GetActiveWebContents(); diff --git a/chrome/common/net/url_fixer_upper.h b/chrome/common/net/url_fixer_upper.h index 3462880bd408..4a632980c3d0 100644 --- a/chrome/common/net/url_fixer_upper.h +++ b/chrome/common/net/url_fixer_upper.h @@ -14,7 +14,7 @@ namespace base { class FilePath; } -namespace url_parse { +namespace url { struct Component; struct Parsed; } diff --git a/chrome/common/net/url_fixer_upper_unittest.cc b/chrome/common/net/url_fixer_upper_unittest.cc index a6e80c672dd4..654b9fafb0aa 100644 --- a/chrome/common/net/url_fixer_upper_unittest.cc +++ b/chrome/common/net/url_fixer_upper_unittest.cc @@ -21,13 +21,13 @@ namespace { }; }; -namespace url_parse { +namespace url { std::ostream& operator<<(std::ostream& os, const Component& part) { return os << "(begin=" << part.begin << ", len=" << part.len << ")"; } -} // namespace url_parse +} // namespace url struct SegmentCase { const std::string input; diff --git a/net/base/net_util.h b/net/base/net_util.h index a63aa9dc19ec..ad0c67aed539 100644 --- a/net/base/net_util.h +++ b/net/base/net_util.h @@ -31,11 +31,8 @@ namespace base { class Time; } -namespace url_canon { +namespace url { struct CanonHostInfo; -} - -namespace url_parse { struct Parsed; } @@ -195,7 +192,7 @@ NET_EXPORT base::string16 IDNToUnicode(const std::string& host, // Canonicalizes |host| and returns it. Also fills |host_info| with // IP address information. |host_info| must not be NULL. NET_EXPORT std::string CanonicalizeHost(const std::string& host, - url_canon::CanonHostInfo* host_info); + url::CanonHostInfo* host_info); // Returns true if |host| is not an IP address and is compliant with a set of // rules based on RFC 1738 and tweaked to be compatible with the real world. @@ -300,7 +297,7 @@ NET_EXPORT base::string16 FormatUrl(const GURL& url, const std::string& languages, FormatUrlTypes format_types, UnescapeRule::Type unescape_rules, - url_parse::Parsed* new_parsed, + url::Parsed* new_parsed, size_t* prefix_end, size_t* offset_for_adjustment); NET_EXPORT base::string16 FormatUrlWithOffsets( @@ -308,7 +305,7 @@ NET_EXPORT base::string16 FormatUrlWithOffsets( const std::string& languages, FormatUrlTypes format_types, UnescapeRule::Type unescape_rules, - url_parse::Parsed* new_parsed, + url::Parsed* new_parsed, size_t* prefix_end, std::vector* offsets_for_adjustment); // This function is like those above except it takes |adjustments| rather @@ -320,7 +317,7 @@ NET_EXPORT base::string16 FormatUrlWithAdjustments( const std::string& languages, FormatUrlTypes format_types, UnescapeRule::Type unescape_rules, - url_parse::Parsed* new_parsed, + url::Parsed* new_parsed, size_t* prefix_end, base::OffsetAdjuster::Adjustments* adjustments); diff --git a/url/gurl.cc b/url/gurl.cc index 77b8def28c46..c79cdba1aa21 100644 --- a/url/gurl.cc +++ b/url/gurl.cc @@ -86,16 +86,17 @@ GURL::GURL(const std::string& url_string, RetainWhiteSpaceSelector) { InitCanonical(url_string, false); } -GURL::GURL(const char* canonical_spec, size_t canonical_spec_len, - const url_parse::Parsed& parsed, bool is_valid) +GURL::GURL(const char* canonical_spec, + size_t canonical_spec_len, + const url::Parsed& parsed, + bool is_valid) : spec_(canonical_spec, canonical_spec_len), is_valid_(is_valid), parsed_(parsed) { InitializeFromCanonicalSpec(); } -GURL::GURL(std::string canonical_spec, - const url_parse::Parsed& parsed, bool is_valid) +GURL::GURL(std::string canonical_spec, const url::Parsed& parsed, bool is_valid) : is_valid_(is_valid), parsed_(parsed) { spec_.swap(canonical_spec); @@ -107,8 +108,8 @@ void GURL::InitCanonical(const STR& input_spec, bool trim_path_end) { // Reserve enough room in the output for the input, plus some extra so that // we have room if we have to escape a few things without reallocating. spec_.reserve(input_spec.size() + 32); - url_canon::StdStringCanonOutput output(&spec_); - is_valid_ = url_util::Canonicalize( + url::StdStringCanonOutput output(&spec_); + is_valid_ = url::Canonicalize( input_spec.data(), static_cast(input_spec.length()), trim_path_end, NULL, &output, &parsed_); @@ -131,12 +132,12 @@ void GURL::InitializeFromCanonicalSpec() { // what we would have produced. Skip checking for invalid URLs have no meaning // and we can't always canonicalize then reproducabely. if (is_valid_) { - url_parse::Component scheme; + url::Component scheme; // We can't do this check on the inner_url of a filesystem URL, as // canonical_spec actually points to the start of the outer URL, so we'd // end up with infinite recursion in this constructor. - if (!url_util::FindAndCompareScheme(spec_.data(), spec_.length(), - "filesystem", &scheme) || + if (!url::FindAndCompareScheme(spec_.data(), spec_.length(), + "filesystem", &scheme) || scheme.begin == parsed_.scheme.begin) { // We need to retain trailing whitespace on path URLs, as the |parsed_| // spec we originally received may legitimately contain trailing white- @@ -186,7 +187,7 @@ GURL GURL::Resolve(const base::string16& relative) const { // Note: code duplicated below (it's inconvenient to use a template here). GURL GURL::ResolveWithCharsetConverter( const std::string& relative, - url_canon::CharsetConverter* charset_converter) const { + url::CharsetConverter* charset_converter) const { // Not allowed for invalid URLs. if (!is_valid_) return GURL(); @@ -196,12 +197,12 @@ GURL GURL::ResolveWithCharsetConverter( // Reserve enough room in the output for the input, plus some extra so that // we have room if we have to escape a few things without reallocating. result.spec_.reserve(spec_.size() + 32); - url_canon::StdStringCanonOutput output(&result.spec_); + url::StdStringCanonOutput output(&result.spec_); - if (!url_util::ResolveRelative( - spec_.data(), static_cast(spec_.length()), parsed_, - relative.data(), static_cast(relative.length()), - charset_converter, &output, &result.parsed_)) { + if (!url::ResolveRelative(spec_.data(), static_cast(spec_.length()), + parsed_, relative.data(), + static_cast(relative.length()), + charset_converter, &output, &result.parsed_)) { // Error resolving, return an empty URL. return GURL(); } @@ -219,7 +220,7 @@ GURL GURL::ResolveWithCharsetConverter( // Note: code duplicated above (it's inconvenient to use a template here). GURL GURL::ResolveWithCharsetConverter( const base::string16& relative, - url_canon::CharsetConverter* charset_converter) const { + url::CharsetConverter* charset_converter) const { // Not allowed for invalid URLs. if (!is_valid_) return GURL(); @@ -229,12 +230,12 @@ GURL GURL::ResolveWithCharsetConverter( // Reserve enough room in the output for the input, plus some extra so that // we have room if we have to escape a few things without reallocating. result.spec_.reserve(spec_.size() + 32); - url_canon::StdStringCanonOutput output(&result.spec_); + url::StdStringCanonOutput output(&result.spec_); - if (!url_util::ResolveRelative( - spec_.data(), static_cast(spec_.length()), parsed_, - relative.data(), static_cast(relative.length()), - charset_converter, &output, &result.parsed_)) { + if (!url::ResolveRelative(spec_.data(), static_cast(spec_.length()), + parsed_, relative.data(), + static_cast(relative.length()), + charset_converter, &output, &result.parsed_)) { // Error resolving, return an empty URL. return GURL(); } @@ -251,7 +252,7 @@ GURL GURL::ResolveWithCharsetConverter( // Note: code duplicated below (it's inconvenient to use a template here). GURL GURL::ReplaceComponents( - const url_canon::Replacements& replacements) const { + const url::Replacements& replacements) const { GURL result; // Not allowed for invalid URLs. @@ -261,9 +262,9 @@ GURL GURL::ReplaceComponents( // Reserve enough room in the output for the input, plus some extra so that // we have room if we have to escape a few things without reallocating. result.spec_.reserve(spec_.size() + 32); - url_canon::StdStringCanonOutput output(&result.spec_); + url::StdStringCanonOutput output(&result.spec_); - result.is_valid_ = url_util::ReplaceComponents( + result.is_valid_ = url::ReplaceComponents( spec_.data(), static_cast(spec_.length()), parsed_, replacements, NULL, &output, &result.parsed_); @@ -277,7 +278,7 @@ GURL GURL::ReplaceComponents( // Note: code duplicated above (it's inconvenient to use a template here). GURL GURL::ReplaceComponents( - const url_canon::Replacements& replacements) const { + const url::Replacements& replacements) const { GURL result; // Not allowed for invalid URLs. @@ -287,9 +288,9 @@ GURL GURL::ReplaceComponents( // Reserve enough room in the output for the input, plus some extra so that // we have room if we have to escape a few things without reallocating. result.spec_.reserve(spec_.size() + 32); - url_canon::StdStringCanonOutput output(&result.spec_); + url::StdStringCanonOutput output(&result.spec_); - result.is_valid_ = url_util::ReplaceComponents( + result.is_valid_ = url::ReplaceComponents( spec_.data(), static_cast(spec_.length()), parsed_, replacements, NULL, &output, &result.parsed_); @@ -310,7 +311,7 @@ GURL GURL::GetOrigin() const { if (SchemeIsFileSystem()) return inner_url_->GetOrigin(); - url_canon::Replacements replacements; + url::Replacements replacements; replacements.ClearUsername(); replacements.ClearPassword(); replacements.ClearPath(); @@ -325,7 +326,7 @@ GURL GURL::GetAsReferrer() const { (!has_ref() && !has_username() && !has_password())) return GURL(*this); - url_canon::Replacements replacements; + url::Replacements replacements; replacements.ClearRef(); replacements.ClearUsername(); replacements.ClearPassword(); @@ -357,15 +358,15 @@ GURL GURL::GetWithEmptyPath() const { } bool GURL::IsStandard() const { - return url_util::IsStandard(spec_.data(), parsed_.scheme); + return url::IsStandard(spec_.data(), parsed_.scheme); } bool GURL::SchemeIs(const char* lower_ascii_scheme) const { if (parsed_.scheme.len <= 0) return lower_ascii_scheme == NULL; - return url_util::LowerCaseEqualsASCII(spec_.data() + parsed_.scheme.begin, - spec_.data() + parsed_.scheme.end(), - lower_ascii_scheme); + return url::LowerCaseEqualsASCII(spec_.data() + parsed_.scheme.begin, + spec_.data() + parsed_.scheme.end(), + lower_ascii_scheme); } bool GURL::SchemeIsHTTPOrHTTPS() const { @@ -378,21 +379,21 @@ bool GURL::SchemeIsWSOrWSS() const { int GURL::IntPort() const { if (parsed_.port.is_nonempty()) - return url_parse::ParsePort(spec_.data(), parsed_.port); - return url_parse::PORT_UNSPECIFIED; + return url::ParsePort(spec_.data(), parsed_.port); + return url::PORT_UNSPECIFIED; } int GURL::EffectiveIntPort() const { int int_port = IntPort(); - if (int_port == url_parse::PORT_UNSPECIFIED && IsStandard()) - return url_canon::DefaultPortForScheme(spec_.data() + parsed_.scheme.begin, - parsed_.scheme.len); + if (int_port == url::PORT_UNSPECIFIED && IsStandard()) + return url::DefaultPortForScheme(spec_.data() + parsed_.scheme.begin, + parsed_.scheme.len); return int_port; } std::string GURL::ExtractFileName() const { - url_parse::Component file_component; - url_parse::ExtractFileName(spec_.data(), parsed_.path, &file_component); + url::Component file_component; + url::ExtractFileName(spec_.data(), parsed_.path, &file_component); return ComponentString(file_component); } @@ -416,7 +417,7 @@ std::string GURL::PathForRequest() const { std::string GURL::HostNoBrackets() const { // If host looks like an IPv6 literal, strip the square brackets. - url_parse::Component h(parsed_.host); + url::Component h(parsed_.host); if (h.len >= 2 && spec_[h.begin] == '[' && spec_[h.end() - 1] == ']') { h.begin++; h.len -= 2; @@ -432,10 +433,10 @@ bool GURL::HostIsIPAddress() const { if (!is_valid_ || spec_.empty()) return false; - url_canon::RawCanonOutputT ignored_output; - url_canon::CanonHostInfo host_info; - url_canon::CanonicalizeIPAddress(spec_.c_str(), parsed_.host, - &ignored_output, &host_info); + url::RawCanonOutputT ignored_output; + url::CanonHostInfo host_info; + url::CanonicalizeIPAddress(spec_.c_str(), parsed_.host, &ignored_output, + &host_info); return host_info.IsIPAddress(); } @@ -502,10 +503,10 @@ bool GURL::DomainIs(const char* lower_ascii_domain, const char* start_pos = spec_.data() + parsed_.host.begin + host_len - domain_len; - if (!url_util::LowerCaseEqualsASCII(start_pos, - last_pos + 1, - lower_ascii_domain, - lower_ascii_domain + domain_len)) + if (!url::LowerCaseEqualsASCII(start_pos, + last_pos + 1, + lower_ascii_domain, + lower_ascii_domain + domain_len)) return false; // Check whether host has right domain start with dot, make sure we got diff --git a/url/gurl.h b/url/gurl.h index 28897d16703e..b8632b45e910 100644 --- a/url/gurl.h +++ b/url/gurl.h @@ -17,8 +17,8 @@ class URL_EXPORT GURL { public: - typedef url_canon::StdStringReplacements Replacements; - typedef url_canon::StdStringReplacements ReplacementsW; + typedef url::StdStringReplacements Replacements; + typedef url::StdStringReplacements ReplacementsW; // Creates an empty, invalid URL. GURL(); @@ -40,16 +40,17 @@ class URL_EXPORT GURL { // Constructor for URLs that have already been parsed and canonicalized. This // is used for conversions from KURL, for example. The caller must supply all // information associated with the URL, which must be correct and consistent. - GURL(const char* canonical_spec, size_t canonical_spec_len, - const url_parse::Parsed& parsed, bool is_valid); + GURL(const char* canonical_spec, + size_t canonical_spec_len, + const url::Parsed& parsed, + bool is_valid); // Notice that we take the canonical_spec by value so that we can convert // from WebURL without copying the string. When we call this constructor // we pass in a temporary std::string, which lets the compiler skip the // copy and just move the std::string into the function argument. In the // implementation, we use swap to move the data into the GURL itself, // which means we end up with zero copies. - GURL(std::string canonical_spec, - const url_parse::Parsed& parsed, bool is_valid); + GURL(std::string canonical_spec, const url::Parsed& parsed, bool is_valid); ~GURL(); @@ -105,7 +106,7 @@ class URL_EXPORT GURL { // or may not be valid. If you are using this to index into the spec, BE // SURE YOU ARE USING possibly_invalid_spec() to get the spec, and that you // don't do anything "important" with invalid specs. - const url_parse::Parsed& parsed_for_possibly_invalid_spec() const { + const url::Parsed& parsed_for_possibly_invalid_spec() const { return parsed_; } @@ -152,10 +153,10 @@ class URL_EXPORT GURL { // name). GURL ResolveWithCharsetConverter( const std::string& relative, - url_canon::CharsetConverter* charset_converter) const; + url::CharsetConverter* charset_converter) const; GURL ResolveWithCharsetConverter( const base::string16& relative, - url_canon::CharsetConverter* charset_converter) const; + url::CharsetConverter* charset_converter) const; // Creates a new GURL by replacing the current URL's components with the // supplied versions. See the Replacements class in url_canon.h for more. @@ -166,12 +167,11 @@ class URL_EXPORT GURL { // It is an error to replace components of an invalid URL. The result will // be the empty URL. // - // Note that we use the more general url_canon::Replacements type to give + // Note that we use the more general url::Replacements type to give // callers extra flexibility rather than our override. + GURL ReplaceComponents(const url::Replacements& replacements) const; GURL ReplaceComponents( - const url_canon::Replacements& replacements) const; - GURL ReplaceComponents( - const url_canon::Replacements& replacements) const; + const url::Replacements& replacements) const; // A helper function that is equivalent to replacing the path with a slash // and clearing out everything after that. We sometimes need to know just the @@ -377,7 +377,7 @@ class URL_EXPORT GURL { void InitializeFromCanonicalSpec(); // Returns the substring of the input identified by the given component. - std::string ComponentString(const url_parse::Component& comp) const { + std::string ComponentString(const url::Component& comp) const { if (comp.len <= 0) return std::string(); return std::string(spec_, comp.begin, comp.len); @@ -392,7 +392,7 @@ class URL_EXPORT GURL { bool is_valid_; // Identified components of the canonical spec. - url_parse::Parsed parsed_; + url::Parsed parsed_; // Used for nested schemes [currently only filesystem:]. scoped_ptr inner_url_; diff --git a/url/gurl_unittest.cc b/url/gurl_unittest.cc index a5608876c98d..89375a8bfb4f 100644 --- a/url/gurl_unittest.cc +++ b/url/gurl_unittest.cc @@ -14,18 +14,20 @@ #define ARRAYSIZE ARRAYSIZE_UNSAFE #endif -using url_test_utils::WStringToUTF16; -using url_test_utils::ConvertUTF8ToUTF16; +namespace url { + +using test_utils::WStringToUTF16; +using test_utils::ConvertUTF8ToUTF16; namespace { template -void SetupReplacement(void (url_canon::Replacements::*func)(const CHAR*, - const url_parse::Component&), - url_canon::Replacements* replacements, - const CHAR* str) { +void SetupReplacement( + void (Replacements::*func)(const CHAR*, const Component&), + Replacements* replacements, + const CHAR* str) { if (str) { - url_parse::Component comp; + Component comp; if (str[0]) comp.len = static_cast(strlen(str)); (replacements->*func)(str, comp); @@ -105,7 +107,7 @@ TEST(GURLTest, Empty) { EXPECT_EQ("", url.password()); EXPECT_EQ("", url.host()); EXPECT_EQ("", url.port()); - EXPECT_EQ(url_parse::PORT_UNSPECIFIED, url.IntPort()); + EXPECT_EQ(PORT_UNSPECIFIED, url.IntPort()); EXPECT_EQ("", url.path()); EXPECT_EQ("", url.query()); EXPECT_EQ("", url.ref()); @@ -138,7 +140,7 @@ TEST(GURLTest, Copy) { EXPECT_EQ("", invalid2.password()); EXPECT_EQ("", invalid2.host()); EXPECT_EQ("", invalid2.port()); - EXPECT_EQ(url_parse::PORT_UNSPECIFIED, invalid2.IntPort()); + EXPECT_EQ(PORT_UNSPECIFIED, invalid2.IntPort()); EXPECT_EQ("", invalid2.path()); EXPECT_EQ("", invalid2.query()); EXPECT_EQ("", invalid2.ref()); @@ -173,7 +175,7 @@ TEST(GURLTest, Assign) { EXPECT_EQ("", invalid2.password()); EXPECT_EQ("", invalid2.host()); EXPECT_EQ("", invalid2.port()); - EXPECT_EQ(url_parse::PORT_UNSPECIFIED, invalid2.IntPort()); + EXPECT_EQ(PORT_UNSPECIFIED, invalid2.IntPort()); EXPECT_EQ("", invalid2.path()); EXPECT_EQ("", invalid2.query()); EXPECT_EQ("", invalid2.ref()); @@ -198,7 +200,7 @@ TEST(GURLTest, CopyFileSystem) { EXPECT_EQ("", url2.password()); EXPECT_EQ("", url2.host()); EXPECT_EQ("", url2.port()); - EXPECT_EQ(url_parse::PORT_UNSPECIFIED, url2.IntPort()); + EXPECT_EQ(PORT_UNSPECIFIED, url2.IntPort()); EXPECT_EQ("/foo;bar", url2.path()); EXPECT_EQ("q=a", url2.query()); EXPECT_EQ("ref", url2.ref()); @@ -268,7 +270,7 @@ TEST(GURLTest, ComponentGettersWorkEvenForInvalidURL) { EXPECT_EQ("", url.password()); EXPECT_EQ("google.com", url.host()); EXPECT_EQ("foo", url.port()); - EXPECT_EQ(url_parse::PORT_INVALID, url.IntPort()); + EXPECT_EQ(PORT_INVALID, url.IntPort()); EXPECT_EQ("/", url.path()); EXPECT_EQ("", url.query()); EXPECT_EQ("", url.ref()); @@ -421,7 +423,7 @@ TEST(GURLTest, Replacements) { TEST(GURLTest, ClearFragmentOnDataUrl) { // http://crbug.com/291747 - a data URL may legitimately have trailing // whitespace in the spec after the ref is cleared. Test this does not trigger - // the url_parse::Parsed importing validation DCHECK in GURL. + // the Parsed importing validation DCHECK in GURL. GURL url(" data: one ? two # three "); // By default the trailing whitespace will have been stripped. @@ -492,16 +494,16 @@ TEST(GURLTest, EffectiveIntPort) { {"gopher://www.google.com:80/", 80}, // file - no port - {"file://www.google.com/", url_parse::PORT_UNSPECIFIED}, - {"file://www.google.com:443/", url_parse::PORT_UNSPECIFIED}, + {"file://www.google.com/", PORT_UNSPECIFIED}, + {"file://www.google.com:443/", PORT_UNSPECIFIED}, // data - no port - {"data:www.google.com:90", url_parse::PORT_UNSPECIFIED}, - {"data:www.google.com", url_parse::PORT_UNSPECIFIED}, + {"data:www.google.com:90", PORT_UNSPECIFIED}, + {"data:www.google.com", PORT_UNSPECIFIED}, // filesystem - no port - {"filesystem:http://www.google.com:90/t/foo", url_parse::PORT_UNSPECIFIED}, - {"filesystem:file:///t/foo", url_parse::PORT_UNSPECIFIED}, + {"filesystem:http://www.google.com:90/t/foo", PORT_UNSPECIFIED}, + {"filesystem:file:///t/foo", PORT_UNSPECIFIED}, }; for (size_t i = 0; i < ARRAYSIZE(port_tests); i++) { @@ -632,3 +634,5 @@ TEST(GURLTest, SchemeIsWSOrWSS) { EXPECT_TRUE(GURL("wss://bar/").SchemeIsWSOrWSS()); EXPECT_FALSE(GURL("http://bar/").SchemeIsWSOrWSS()); } + +} // namespace url diff --git a/url/third_party/mozilla/url_parse.cc b/url/third_party/mozilla/url_parse.cc index 84a75589babd..62567969a650 100644 --- a/url/third_party/mozilla/url_parse.cc +++ b/url/third_party/mozilla/url_parse.cc @@ -43,7 +43,7 @@ #include "url/url_util.h" #include "url/url_util_internal.h" -namespace url_parse { +namespace url { namespace { @@ -376,7 +376,7 @@ void DoParseFileSystemURL(const CHAR* spec, int spec_len, Parsed* parsed) { return; } - url_parse::Component inner_scheme; + Component inner_scheme; const CHAR* inner_spec = &spec[inner_start]; int inner_spec_len = spec_len - inner_start; @@ -394,15 +394,13 @@ void DoParseFileSystemURL(const CHAR* spec, int spec_len, Parsed* parsed) { Parsed inner_parsed; - if (url_util::CompareSchemeComponent( - spec, inner_scheme, url_util::kFileScheme)) { + if (CompareSchemeComponent(spec, inner_scheme, kFileScheme)) { // File URLs are special. ParseFileURL(inner_spec, inner_spec_len, &inner_parsed); - } else if (url_util::CompareSchemeComponent(spec, inner_scheme, - url_util::kFileSystemScheme)) { + } else if (CompareSchemeComponent(spec, inner_scheme, kFileSystemScheme)) { // Filesystem URLs don't nest. return; - } else if (url_util::IsStandard(spec, inner_scheme)) { + } else if (IsStandard(spec, inner_scheme)) { // All "normal" URLs. DoParseStandardURL(inner_spec, inner_spec_len, &inner_parsed); } else { @@ -686,7 +684,7 @@ bool DoExtractQueryKeyValue(const CHAR* spec, cur++; // Save the new query - *query = url_parse::MakeRange(cur, end); + *query = MakeRange(cur, end); return true; } @@ -943,4 +941,4 @@ void ParseAfterScheme(const base::char16* spec, DoParseAfterScheme(spec, spec_len, after_scheme, parsed); } -} // namespace url_parse +} // namespace url diff --git a/url/third_party/mozilla/url_parse.h b/url/third_party/mozilla/url_parse.h index 9d943e571e31..cc3f2dd475df 100644 --- a/url/third_party/mozilla/url_parse.h +++ b/url/third_party/mozilla/url_parse.h @@ -11,7 +11,7 @@ #include "base/strings/string16.h" #include "url/url_export.h" -namespace url_parse { +namespace url { // Deprecated, but WebKit/WebCore/platform/KURLGooglePrivate.h and // KURLGoogle.cpp still rely on this type. @@ -69,17 +69,17 @@ inline Component MakeRange(int begin, int end) { // // Typical usage would be: // -// url_parse::Parsed parsed; -// url_parse::Component scheme; -// if (!url_parse::ExtractScheme(url, url_len, &scheme)) +// Parsed parsed; +// Component scheme; +// if (!ExtractScheme(url, url_len, &scheme)) // return I_CAN_NOT_FIND_THE_SCHEME_DUDE; // // if (IsStandardScheme(url, scheme)) // Not provided by this component // url_parseParseStandardURL(url, url_len, &parsed); // else if (IsFileURL(url, scheme)) // Not provided by this component -// url_parse::ParseFileURL(url, url_len, &parsed); +// ParseFileURL(url, url_len, &parsed); // else -// url_parse::ParsePathURL(url, url_len, &parsed); +// ParsePathURL(url, url_len, &parsed); // struct URL_EXPORT Parsed { // Identifies different components. @@ -367,6 +367,6 @@ URL_EXPORT bool ExtractQueryKeyValue(const base::char16* url, Component* key, Component* value); -} // namespace url_parse +} // namespace url #endif // URL_THIRD_PARTY_MOZILLA_URL_PARSE_H_ diff --git a/url/url_canon.h b/url/url_canon.h index e118f3a33e1c..624eeaf4710a 100644 --- a/url/url_canon.h +++ b/url/url_canon.h @@ -12,7 +12,7 @@ #include "url/url_export.h" #include "url/url_parse.h" -namespace url_canon { +namespace url { // Canonicalizer output ------------------------------------------------------- @@ -274,13 +274,13 @@ URL_EXPORT bool IDNToASCII(const base::char16* src, // // The 8-bit version requires UTF-8 encoding. URL_EXPORT bool CanonicalizeScheme(const char* spec, - const url_parse::Component& scheme, + const Component& scheme, CanonOutput* output, - url_parse::Component* out_scheme); + Component* out_scheme); URL_EXPORT bool CanonicalizeScheme(const base::char16* spec, - const url_parse::Component& scheme, + const Component& scheme, CanonOutput* output, - url_parse::Component* out_scheme); + Component* out_scheme); // User info: username/password. If present, this will add the delimiters so // the output will be ":@" or "@". Empty @@ -293,20 +293,19 @@ URL_EXPORT bool CanonicalizeScheme(const base::char16* spec, // // The 8-bit version requires UTF-8 encoding. URL_EXPORT bool CanonicalizeUserInfo(const char* username_source, - const url_parse::Component& username, + const Component& username, const char* password_source, - const url_parse::Component& password, + const Component& password, CanonOutput* output, - url_parse::Component* out_username, - url_parse::Component* out_password); + Component* out_username, + Component* out_password); URL_EXPORT bool CanonicalizeUserInfo(const base::char16* username_source, - const url_parse::Component& username, + const Component& username, const base::char16* password_source, - const url_parse::Component& password, + const Component& password, CanonOutput* output, - url_parse::Component* out_username, - url_parse::Component* out_password); - + Component* out_username, + Component* out_password); // This structure holds detailed state exported from the IP/Host canonicalizers. // Additional fields may be added as callers require them. @@ -339,7 +338,7 @@ struct CanonHostInfo { // Location of host within the canonicalized output. // CanonicalizeIPAddress() only sets this field if |family| is IPV4 or IPV6. // CanonicalizeHostVerbose() always sets it. - url_parse::Component out_host; + Component out_host; // |address| contains the parsed IP Address (if any) in its first // AddressLength() bytes, in network order. If IsIPAddress() is false @@ -359,28 +358,27 @@ struct CanonHostInfo { // The 8-bit version requires UTF-8 encoding. Use this version when you only // need to know whether canonicalization succeeded. URL_EXPORT bool CanonicalizeHost(const char* spec, - const url_parse::Component& host, + const Component& host, CanonOutput* output, - url_parse::Component* out_host); + Component* out_host); URL_EXPORT bool CanonicalizeHost(const base::char16* spec, - const url_parse::Component& host, + const Component& host, CanonOutput* output, - url_parse::Component* out_host); + Component* out_host); // Extended version of CanonicalizeHost, which returns additional information. // Use this when you need to know whether the hostname was an IP address. // A successful return is indicated by host_info->family != BROKEN. See the // definition of CanonHostInfo above for details. URL_EXPORT void CanonicalizeHostVerbose(const char* spec, - const url_parse::Component& host, + const Component& host, CanonOutput* output, CanonHostInfo* host_info); URL_EXPORT void CanonicalizeHostVerbose(const base::char16* spec, - const url_parse::Component& host, + const Component& host, CanonOutput* output, CanonHostInfo* host_info); - // IP addresses. // // Tries to interpret the given host name as an IPv4 or IPv6 address. If it is @@ -392,29 +390,29 @@ URL_EXPORT void CanonicalizeHostVerbose(const base::char16* spec, // the input is unescaped and name-prepped, etc. It should not normally be // necessary or wise to call this directly. URL_EXPORT void CanonicalizeIPAddress(const char* spec, - const url_parse::Component& host, + const Component& host, CanonOutput* output, CanonHostInfo* host_info); URL_EXPORT void CanonicalizeIPAddress(const base::char16* spec, - const url_parse::Component& host, + const Component& host, CanonOutput* output, CanonHostInfo* host_info); // Port: this function will add the colon for the port if a port is present. -// The caller can pass url_parse::PORT_UNSPECIFIED as the +// The caller can pass PORT_UNSPECIFIED as the // default_port_for_scheme argument if there is no default port. // // The 8-bit version requires UTF-8 encoding. URL_EXPORT bool CanonicalizePort(const char* spec, - const url_parse::Component& port, + const Component& port, int default_port_for_scheme, CanonOutput* output, - url_parse::Component* out_port); + Component* out_port); URL_EXPORT bool CanonicalizePort(const base::char16* spec, - const url_parse::Component& port, + const Component& port, int default_port_for_scheme, CanonOutput* output, - url_parse::Component* out_port); + Component* out_port); // Returns the default port for the given canonical scheme, or PORT_UNSPECIFIED // if the scheme is unknown. @@ -430,13 +428,13 @@ URL_EXPORT int DefaultPortForScheme(const char* scheme, int scheme_len); // the path that the server expects (we'll escape high-bit characters), so // if something is invalid, it's their problem. URL_EXPORT bool CanonicalizePath(const char* spec, - const url_parse::Component& path, + const Component& path, CanonOutput* output, - url_parse::Component* out_path); + Component* out_path); URL_EXPORT bool CanonicalizePath(const base::char16* spec, - const url_parse::Component& path, + const Component& path, CanonOutput* output, - url_parse::Component* out_path); + Component* out_path); // Canonicalizes the input as a file path. This is like CanonicalizePath except // that it also handles Windows drive specs. For example, the path can begin @@ -445,13 +443,13 @@ URL_EXPORT bool CanonicalizePath(const base::char16* spec, // // The 8-bit version requires UTF-8 encoding. URL_EXPORT bool FileCanonicalizePath(const char* spec, - const url_parse::Component& path, + const Component& path, CanonOutput* output, - url_parse::Component* out_path); + Component* out_path); URL_EXPORT bool FileCanonicalizePath(const base::char16* spec, - const url_parse::Component& path, + const Component& path, CanonOutput* output, - url_parse::Component* out_path); + Component* out_path); // Query: Prepends the ? if needed. // @@ -466,15 +464,15 @@ URL_EXPORT bool FileCanonicalizePath(const base::char16* spec, // // The converter can be NULL. In this case, the output encoding will be UTF-8. URL_EXPORT void CanonicalizeQuery(const char* spec, - const url_parse::Component& query, + const Component& query, CharsetConverter* converter, CanonOutput* output, - url_parse::Component* out_query); + Component* out_query); URL_EXPORT void CanonicalizeQuery(const base::char16* spec, - const url_parse::Component& query, + const Component& query, CharsetConverter* converter, CanonOutput* output, - url_parse::Component* out_query); + Component* out_query); // Ref: Prepends the # if needed. The output will be UTF-8 (this is the only // canonicalizer that does not produce ASCII output). The output is @@ -483,13 +481,13 @@ URL_EXPORT void CanonicalizeQuery(const base::char16* spec, // This function will not fail. If the input is invalid UTF-8/UTF-16, we'll use // the "Unicode replacement character" for the confusing bits and copy the rest. URL_EXPORT void CanonicalizeRef(const char* spec, - const url_parse::Component& path, + const Component& path, CanonOutput* output, - url_parse::Component* out_path); + Component* out_path); URL_EXPORT void CanonicalizeRef(const base::char16* spec, - const url_parse::Component& path, + const Component& path, CanonOutput* output, - url_parse::Component* out_path); + Component* out_path); // Full canonicalizer --------------------------------------------------------- // @@ -504,57 +502,57 @@ URL_EXPORT void CanonicalizeRef(const base::char16* spec, // Use for standard URLs with authorities and paths. URL_EXPORT bool CanonicalizeStandardURL(const char* spec, int spec_len, - const url_parse::Parsed& parsed, + const Parsed& parsed, CharsetConverter* query_converter, CanonOutput* output, - url_parse::Parsed* new_parsed); + Parsed* new_parsed); URL_EXPORT bool CanonicalizeStandardURL(const base::char16* spec, int spec_len, - const url_parse::Parsed& parsed, + const Parsed& parsed, CharsetConverter* query_converter, CanonOutput* output, - url_parse::Parsed* new_parsed); + Parsed* new_parsed); // Use for file URLs. URL_EXPORT bool CanonicalizeFileURL(const char* spec, int spec_len, - const url_parse::Parsed& parsed, + const Parsed& parsed, CharsetConverter* query_converter, CanonOutput* output, - url_parse::Parsed* new_parsed); + Parsed* new_parsed); URL_EXPORT bool CanonicalizeFileURL(const base::char16* spec, int spec_len, - const url_parse::Parsed& parsed, + const Parsed& parsed, CharsetConverter* query_converter, CanonOutput* output, - url_parse::Parsed* new_parsed); + Parsed* new_parsed); // Use for filesystem URLs. URL_EXPORT bool CanonicalizeFileSystemURL(const char* spec, int spec_len, - const url_parse::Parsed& parsed, + const Parsed& parsed, CharsetConverter* query_converter, CanonOutput* output, - url_parse::Parsed* new_parsed); + Parsed* new_parsed); URL_EXPORT bool CanonicalizeFileSystemURL(const base::char16* spec, int spec_len, - const url_parse::Parsed& parsed, + const Parsed& parsed, CharsetConverter* query_converter, CanonOutput* output, - url_parse::Parsed* new_parsed); + Parsed* new_parsed); // Use for path URLs such as javascript. This does not modify the path in any // way, for example, by escaping it. URL_EXPORT bool CanonicalizePathURL(const char* spec, int spec_len, - const url_parse::Parsed& parsed, + const Parsed& parsed, CanonOutput* output, - url_parse::Parsed* new_parsed); + Parsed* new_parsed); URL_EXPORT bool CanonicalizePathURL(const base::char16* spec, int spec_len, - const url_parse::Parsed& parsed, + const Parsed& parsed, CanonOutput* output, - url_parse::Parsed* new_parsed); + Parsed* new_parsed); // Use for mailto URLs. This "canonicalizes" the url into a path and query // component. It does not attempt to merge "to" fields. It uses UTF-8 for @@ -563,14 +561,14 @@ URL_EXPORT bool CanonicalizePathURL(const base::char16* spec, // etc. which would influence a query encoding normally are irrelevant. URL_EXPORT bool CanonicalizeMailtoURL(const char* spec, int spec_len, - const url_parse::Parsed& parsed, + const Parsed& parsed, CanonOutput* output, - url_parse::Parsed* new_parsed); + Parsed* new_parsed); URL_EXPORT bool CanonicalizeMailtoURL(const base::char16* spec, int spec_len, - const url_parse::Parsed& parsed, + const Parsed& parsed, CanonOutput* output, - url_parse::Parsed* new_parsed); + Parsed* new_parsed); // Part replacer -------------------------------------------------------------- @@ -580,7 +578,7 @@ URL_EXPORT bool CanonicalizeMailtoURL(const base::char16* spec, // treated on the same code path as regular canonicalization (the same string // for each component). // -// A url_parse::Parsed structure usually goes along with this. Those +// A Parsed structure usually goes along with this. Those // components identify offsets within these strings, so that they can all be // in the same string, or spread arbitrarily across different ones. // @@ -643,7 +641,7 @@ class Replacements { } // Scheme - void SetScheme(const CHAR* s, const url_parse::Component& comp) { + void SetScheme(const CHAR* s, const Component& comp) { sources_.scheme = s; components_.scheme = comp; } @@ -651,86 +649,86 @@ class Replacements { bool IsSchemeOverridden() const { return sources_.scheme != NULL; } // Username - void SetUsername(const CHAR* s, const url_parse::Component& comp) { + void SetUsername(const CHAR* s, const Component& comp) { sources_.username = s; components_.username = comp; } void ClearUsername() { sources_.username = Placeholder(); - components_.username = url_parse::Component(); + components_.username = Component(); } bool IsUsernameOverridden() const { return sources_.username != NULL; } // Password - void SetPassword(const CHAR* s, const url_parse::Component& comp) { + void SetPassword(const CHAR* s, const Component& comp) { sources_.password = s; components_.password = comp; } void ClearPassword() { sources_.password = Placeholder(); - components_.password = url_parse::Component(); + components_.password = Component(); } bool IsPasswordOverridden() const { return sources_.password != NULL; } // Host - void SetHost(const CHAR* s, const url_parse::Component& comp) { + void SetHost(const CHAR* s, const Component& comp) { sources_.host = s; components_.host = comp; } void ClearHost() { sources_.host = Placeholder(); - components_.host = url_parse::Component(); + components_.host = Component(); } bool IsHostOverridden() const { return sources_.host != NULL; } // Port - void SetPort(const CHAR* s, const url_parse::Component& comp) { + void SetPort(const CHAR* s, const Component& comp) { sources_.port = s; components_.port = comp; } void ClearPort() { sources_.port = Placeholder(); - components_.port = url_parse::Component(); + components_.port = Component(); } bool IsPortOverridden() const { return sources_.port != NULL; } // Path - void SetPath(const CHAR* s, const url_parse::Component& comp) { + void SetPath(const CHAR* s, const Component& comp) { sources_.path = s; components_.path = comp; } void ClearPath() { sources_.path = Placeholder(); - components_.path = url_parse::Component(); + components_.path = Component(); } bool IsPathOverridden() const { return sources_.path != NULL; } // Query - void SetQuery(const CHAR* s, const url_parse::Component& comp) { + void SetQuery(const CHAR* s, const Component& comp) { sources_.query = s; components_.query = comp; } void ClearQuery() { sources_.query = Placeholder(); - components_.query = url_parse::Component(); + components_.query = Component(); } bool IsQueryOverridden() const { return sources_.query != NULL; } // Ref - void SetRef(const CHAR* s, const url_parse::Component& comp) { + void SetRef(const CHAR* s, const Component& comp) { sources_.ref = s; components_.ref = comp; } void ClearRef() { sources_.ref = Placeholder(); - components_.ref = url_parse::Component(); + components_.ref = Component(); } bool IsRefOverridden() const { return sources_.ref != NULL; } // Getters for the itnernal data. See the variables below for how the // information is encoded. const URLComponentSource& sources() const { return sources_; } - const url_parse::Parsed& components() const { return components_; } + const Parsed& components() const { return components_; } private: // Returns a pointer to a static empty string that is used as a placeholder @@ -751,80 +749,80 @@ class Replacements { // We use a pointer to the empty string for the source when the component // should be deleted. URLComponentSource sources_; - url_parse::Parsed components_; + Parsed components_; }; // The base must be an 8-bit canonical URL. URL_EXPORT bool ReplaceStandardURL(const char* base, - const url_parse::Parsed& base_parsed, + const Parsed& base_parsed, const Replacements& replacements, CharsetConverter* query_converter, CanonOutput* output, - url_parse::Parsed* new_parsed); + Parsed* new_parsed); URL_EXPORT bool ReplaceStandardURL( const char* base, - const url_parse::Parsed& base_parsed, + const Parsed& base_parsed, const Replacements& replacements, CharsetConverter* query_converter, CanonOutput* output, - url_parse::Parsed* new_parsed); + Parsed* new_parsed); // Filesystem URLs can only have the path, query, or ref replaced. // All other components will be ignored. URL_EXPORT bool ReplaceFileSystemURL(const char* base, - const url_parse::Parsed& base_parsed, + const Parsed& base_parsed, const Replacements& replacements, CharsetConverter* query_converter, CanonOutput* output, - url_parse::Parsed* new_parsed); + Parsed* new_parsed); URL_EXPORT bool ReplaceFileSystemURL( const char* base, - const url_parse::Parsed& base_parsed, + const Parsed& base_parsed, const Replacements& replacements, CharsetConverter* query_converter, CanonOutput* output, - url_parse::Parsed* new_parsed); + Parsed* new_parsed); // Replacing some parts of a file URL is not permitted. Everything except // the host, path, query, and ref will be ignored. URL_EXPORT bool ReplaceFileURL(const char* base, - const url_parse::Parsed& base_parsed, + const Parsed& base_parsed, const Replacements& replacements, CharsetConverter* query_converter, CanonOutput* output, - url_parse::Parsed* new_parsed); + Parsed* new_parsed); URL_EXPORT bool ReplaceFileURL(const char* base, - const url_parse::Parsed& base_parsed, + const Parsed& base_parsed, const Replacements& replacements, CharsetConverter* query_converter, CanonOutput* output, - url_parse::Parsed* new_parsed); + Parsed* new_parsed); // Path URLs can only have the scheme and path replaced. All other components // will be ignored. URL_EXPORT bool ReplacePathURL(const char* base, - const url_parse::Parsed& base_parsed, + const Parsed& base_parsed, const Replacements& replacements, CanonOutput* output, - url_parse::Parsed* new_parsed); + Parsed* new_parsed); URL_EXPORT bool ReplacePathURL(const char* base, - const url_parse::Parsed& base_parsed, + const Parsed& base_parsed, const Replacements& replacements, CanonOutput* output, - url_parse::Parsed* new_parsed); + Parsed* new_parsed); // Mailto URLs can only have the scheme, path, and query replaced. // All other components will be ignored. URL_EXPORT bool ReplaceMailtoURL(const char* base, - const url_parse::Parsed& base_parsed, + const Parsed& base_parsed, const Replacements& replacements, CanonOutput* output, - url_parse::Parsed* new_parsed); + Parsed* new_parsed); URL_EXPORT bool ReplaceMailtoURL(const char* base, - const url_parse::Parsed& base_parsed, + const Parsed& base_parsed, const Replacements& replacements, CanonOutput* output, - url_parse::Parsed* new_parsed); + Parsed* new_parsed); // Relative URL --------------------------------------------------------------- @@ -840,19 +838,19 @@ URL_EXPORT bool ReplaceMailtoURL(const char* base, // // The base URL should always be canonical, therefore is ASCII. URL_EXPORT bool IsRelativeURL(const char* base, - const url_parse::Parsed& base_parsed, + const Parsed& base_parsed, const char* fragment, int fragment_len, bool is_base_hierarchical, bool* is_relative, - url_parse::Component* relative_component); + Component* relative_component); URL_EXPORT bool IsRelativeURL(const char* base, - const url_parse::Parsed& base_parsed, + const Parsed& base_parsed, const base::char16* fragment, int fragment_len, bool is_base_hierarchical, bool* is_relative, - url_parse::Component* relative_component); + Component* relative_component); // Given a canonical parsed source URL, a URL fragment known to be relative, // and the identified relevant portion of the relative URL (computed by @@ -872,25 +870,23 @@ URL_EXPORT bool IsRelativeURL(const char* base, // Returns true on success. On failure, the output will be "something // reasonable" that will be consistent and valid, just probably not what // was intended by the web page author or caller. -URL_EXPORT bool ResolveRelativeURL( - const char* base_url, - const url_parse::Parsed& base_parsed, - bool base_is_file, - const char* relative_url, - const url_parse::Component& relative_component, - CharsetConverter* query_converter, - CanonOutput* output, - url_parse::Parsed* out_parsed); -URL_EXPORT bool ResolveRelativeURL( - const char* base_url, - const url_parse::Parsed& base_parsed, - bool base_is_file, - const base::char16* relative_url, - const url_parse::Component& relative_component, - CharsetConverter* query_converter, - CanonOutput* output, - url_parse::Parsed* out_parsed); +URL_EXPORT bool ResolveRelativeURL(const char* base_url, + const Parsed& base_parsed, + bool base_is_file, + const char* relative_url, + const Component& relative_component, + CharsetConverter* query_converter, + CanonOutput* output, + Parsed* out_parsed); +URL_EXPORT bool ResolveRelativeURL(const char* base_url, + const Parsed& base_parsed, + bool base_is_file, + const base::char16* relative_url, + const Component& relative_component, + CharsetConverter* query_converter, + CanonOutput* output, + Parsed* out_parsed); -} // namespace url_canon +} // namespace url #endif // URL_URL_CANON_H_ diff --git a/url/url_canon_etc.cc b/url/url_canon_etc.cc index a1512f6f63e6..7409efde590a 100644 --- a/url/url_canon_etc.cc +++ b/url/url_canon_etc.cc @@ -9,7 +9,7 @@ #include "url/url_canon.h" #include "url/url_canon_internal.h" -namespace url_canon { +namespace url { namespace { @@ -82,12 +82,12 @@ inline bool IsSchemeFirstChar(unsigned char c) { template bool DoScheme(const CHAR* spec, - const url_parse::Component& scheme, + const Component& scheme, CanonOutput* output, - url_parse::Component* out_scheme) { + Component* out_scheme) { if (scheme.len <= 0) { // Scheme is unspecified or empty, convert to empty by appending a colon. - *out_scheme = url_parse::Component(output->length(), 0); + *out_scheme = Component(output->length(), 0); output->push_back(':'); return true; } @@ -98,7 +98,7 @@ bool DoScheme(const CHAR* spec, // Danger: it's important that this code does not strip any characters: it // only emits the canonical version (be it valid or escaped) of each of // the input characters. Stripping would put it out of sync with - // url_util::FindAndCompareScheme, which could cause some security checks on + // FindAndCompareScheme, which could cause some security checks on // schemes to be incorrect. bool success = true; int end = scheme.end(); @@ -146,16 +146,16 @@ bool DoScheme(const CHAR* spec, // replacing components. template bool DoUserInfo(const CHAR* username_spec, - const url_parse::Component& username, + const Component& username, const CHAR* password_spec, - const url_parse::Component& password, + const Component& password, CanonOutput* output, - url_parse::Component* out_username, - url_parse::Component* out_password) { + Component* out_username, + Component* out_password) { if (username.len <= 0 && password.len <= 0) { // Common case: no user info. We strip empty username/passwords. - *out_username = url_parse::Component(); - *out_password = url_parse::Component(); + *out_username = Component(); + *out_password = Component(); return true; } @@ -177,7 +177,7 @@ bool DoUserInfo(const CHAR* username_spec, CHAR_USERINFO, output); out_password->len = output->length() - out_password->begin; } else { - *out_password = url_parse::Component(); + *out_password = Component(); } output->push_back('@'); @@ -192,18 +192,17 @@ inline void WritePortInt(char* output, int output_len, int port) { // This function will prepend the colon if there will be a port. template bool DoPort(const CHAR* spec, - const url_parse::Component& port, + const Component& port, int default_port_for_scheme, CanonOutput* output, - url_parse::Component* out_port) { - int port_num = url_parse::ParsePort(spec, port); - if (port_num == url_parse::PORT_UNSPECIFIED || - port_num == default_port_for_scheme) { - *out_port = url_parse::Component(); + Component* out_port) { + int port_num = ParsePort(spec, port); + if (port_num == PORT_UNSPECIFIED || port_num == default_port_for_scheme) { + *out_port = Component(); return true; // Leave port empty. } - if (port_num == url_parse::PORT_INVALID) { + if (port_num == PORT_INVALID) { // Invalid port: We'll copy the text from the input so the user can see // what the error was, and mark the URL as invalid by returning false. output->push_back(':'); @@ -231,12 +230,12 @@ bool DoPort(const CHAR* spec, template void DoCanonicalizeRef(const CHAR* spec, - const url_parse::Component& ref, + const Component& ref, CanonOutput* output, - url_parse::Component* out_ref) { + Component* out_ref) { if (ref.len < 0) { // Common case of no ref. - *out_ref = url_parse::Component(); + *out_ref = Component(); return; } @@ -295,74 +294,74 @@ char CanonicalSchemeChar(base::char16 ch) { } bool CanonicalizeScheme(const char* spec, - const url_parse::Component& scheme, + const Component& scheme, CanonOutput* output, - url_parse::Component* out_scheme) { + Component* out_scheme) { return DoScheme(spec, scheme, output, out_scheme); } bool CanonicalizeScheme(const base::char16* spec, - const url_parse::Component& scheme, + const Component& scheme, CanonOutput* output, - url_parse::Component* out_scheme) { + Component* out_scheme) { return DoScheme(spec, scheme, output, out_scheme); } bool CanonicalizeUserInfo(const char* username_source, - const url_parse::Component& username, + const Component& username, const char* password_source, - const url_parse::Component& password, + const Component& password, CanonOutput* output, - url_parse::Component* out_username, - url_parse::Component* out_password) { + Component* out_username, + Component* out_password) { return DoUserInfo( username_source, username, password_source, password, output, out_username, out_password); } bool CanonicalizeUserInfo(const base::char16* username_source, - const url_parse::Component& username, + const Component& username, const base::char16* password_source, - const url_parse::Component& password, + const Component& password, CanonOutput* output, - url_parse::Component* out_username, - url_parse::Component* out_password) { + Component* out_username, + Component* out_password) { return DoUserInfo( username_source, username, password_source, password, output, out_username, out_password); } bool CanonicalizePort(const char* spec, - const url_parse::Component& port, + const Component& port, int default_port_for_scheme, CanonOutput* output, - url_parse::Component* out_port) { + Component* out_port) { return DoPort(spec, port, default_port_for_scheme, output, out_port); } bool CanonicalizePort(const base::char16* spec, - const url_parse::Component& port, + const Component& port, int default_port_for_scheme, CanonOutput* output, - url_parse::Component* out_port) { + Component* out_port) { return DoPort(spec, port, default_port_for_scheme, output, out_port); } void CanonicalizeRef(const char* spec, - const url_parse::Component& ref, + const Component& ref, CanonOutput* output, - url_parse::Component* out_ref) { + Component* out_ref) { DoCanonicalizeRef(spec, ref, output, out_ref); } void CanonicalizeRef(const base::char16* spec, - const url_parse::Component& ref, + const Component& ref, CanonOutput* output, - url_parse::Component* out_ref) { + Component* out_ref) { DoCanonicalizeRef(spec, ref, output, out_ref); } -} // namespace url_canon +} // namespace url diff --git a/url/url_canon_filesystemurl.cc b/url/url_canon_filesystemurl.cc index 225e1095111f..f330e22dfae7 100644 --- a/url/url_canon_filesystemurl.cc +++ b/url/url_canon_filesystemurl.cc @@ -11,7 +11,7 @@ #include "url/url_util.h" #include "url/url_util_internal.h" -namespace url_canon { +namespace url { namespace { @@ -20,18 +20,18 @@ namespace { template bool DoCanonicalizeFileSystemURL(const CHAR* spec, const URLComponentSource& source, - const url_parse::Parsed& parsed, + const Parsed& parsed, CharsetConverter* charset_converter, CanonOutput* output, - url_parse::Parsed* new_parsed) { + Parsed* new_parsed) { // filesystem only uses {scheme, path, query, ref} -- clear the rest. new_parsed->username.reset(); new_parsed->password.reset(); new_parsed->host.reset(); new_parsed->port.reset(); - const url_parse::Parsed* inner_parsed = parsed.inner_parsed(); - url_parse::Parsed new_inner_parsed; + const Parsed* inner_parsed = parsed.inner_parsed(); + Parsed new_inner_parsed; // Scheme (known, so we don't bother running it through the more // complicated scheme canonicalizer). @@ -43,20 +43,16 @@ bool DoCanonicalizeFileSystemURL(const CHAR* spec, return false; bool success = true; - if (url_util::CompareSchemeComponent(spec, inner_parsed->scheme, - url_util::kFileScheme)) { + if (CompareSchemeComponent(spec, inner_parsed->scheme, kFileScheme)) { new_inner_parsed.scheme.begin = output->length(); output->Append("file://", 7); new_inner_parsed.scheme.len = 4; success &= CanonicalizePath(spec, inner_parsed->path, output, &new_inner_parsed.path); - } else if (url_util::IsStandard(spec, inner_parsed->scheme)) { - success = - url_canon::CanonicalizeStandardURL(spec, - parsed.inner_parsed()->Length(), - *parsed.inner_parsed(), - charset_converter, output, - &new_inner_parsed); + } else if (IsStandard(spec, inner_parsed->scheme)) { + success = CanonicalizeStandardURL(spec, parsed.inner_parsed()->Length(), + *parsed.inner_parsed(), charset_converter, + output, &new_inner_parsed); } else { // TODO(ericu): The URL is wrong, but should we try to output more of what // we were given? Echoing back filesystem:mailto etc. doesn't seem all that @@ -83,10 +79,10 @@ bool DoCanonicalizeFileSystemURL(const CHAR* spec, bool CanonicalizeFileSystemURL(const char* spec, int spec_len, - const url_parse::Parsed& parsed, + const Parsed& parsed, CharsetConverter* charset_converter, CanonOutput* output, - url_parse::Parsed* new_parsed) { + Parsed* new_parsed) { return DoCanonicalizeFileSystemURL( spec, URLComponentSource(spec), parsed, charset_converter, output, new_parsed); @@ -94,40 +90,40 @@ bool CanonicalizeFileSystemURL(const char* spec, bool CanonicalizeFileSystemURL(const base::char16* spec, int spec_len, - const url_parse::Parsed& parsed, + const Parsed& parsed, CharsetConverter* charset_converter, CanonOutput* output, - url_parse::Parsed* new_parsed) { + Parsed* new_parsed) { return DoCanonicalizeFileSystemURL( spec, URLComponentSource(spec), parsed, charset_converter, output, new_parsed); } bool ReplaceFileSystemURL(const char* base, - const url_parse::Parsed& base_parsed, + const Parsed& base_parsed, const Replacements& replacements, CharsetConverter* charset_converter, CanonOutput* output, - url_parse::Parsed* new_parsed) { + Parsed* new_parsed) { URLComponentSource source(base); - url_parse::Parsed parsed(base_parsed); + Parsed parsed(base_parsed); SetupOverrideComponents(base, replacements, &source, &parsed); return DoCanonicalizeFileSystemURL( base, source, parsed, charset_converter, output, new_parsed); } bool ReplaceFileSystemURL(const char* base, - const url_parse::Parsed& base_parsed, + const Parsed& base_parsed, const Replacements& replacements, CharsetConverter* charset_converter, CanonOutput* output, - url_parse::Parsed* new_parsed) { + Parsed* new_parsed) { RawCanonOutput<1024> utf8; URLComponentSource source(base); - url_parse::Parsed parsed(base_parsed); + Parsed parsed(base_parsed); SetupUTF16OverrideComponents(base, replacements, &utf8, &source, &parsed); return DoCanonicalizeFileSystemURL( base, source, parsed, charset_converter, output, new_parsed); } -} // namespace url_canon +} // namespace url diff --git a/url/url_canon_fileurl.cc b/url/url_canon_fileurl.cc index 123583a4ed12..1322be74e407 100644 --- a/url/url_canon_fileurl.cc +++ b/url/url_canon_fileurl.cc @@ -9,7 +9,7 @@ #include "url/url_file.h" #include "url/url_parse_internal.h" -namespace url_canon { +namespace url { namespace { @@ -25,10 +25,10 @@ int FileDoDriveSpec(const CHAR* spec, int begin, int end, CanonOutput* output) { // The path could be one of several things: /foo/bar, c:/foo/bar, /c:/foo, // (with backslashes instead of slashes as well). - int num_slashes = url_parse::CountConsecutiveSlashes(spec, begin, end); + int num_slashes = CountConsecutiveSlashes(spec, begin, end); int after_slashes = begin + num_slashes; - if (!url_parse::DoesBeginWindowsDriveSpec(spec, after_slashes, end)) + if (!DoesBeginWindowsDriveSpec(spec, after_slashes, end)) return begin; // Haven't consumed any characters // A drive spec is the start of a path, so we need to add a slash for the @@ -53,9 +53,9 @@ int FileDoDriveSpec(const CHAR* spec, int begin, int end, template bool DoFileCanonicalizePath(const CHAR* spec, - const url_parse::Component& path, + const Component& path, CanonOutput* output, - url_parse::Component* out_path) { + Component* out_path) { // Copies and normalizes the "c:" at the beginning, if present. out_path->begin = output->length(); int after_drive; @@ -72,9 +72,8 @@ bool DoFileCanonicalizePath(const CHAR* spec, // Use the regular path canonicalizer to canonicalize the rest of the // path. Give it a fake output component to write into. DoCanonicalizeFile // will compute the full path component. - url_parse::Component sub_path = - url_parse::MakeRange(after_drive, path.end()); - url_parse::Component fake_output_path; + Component sub_path = MakeRange(after_drive, path.end()); + Component fake_output_path; success = CanonicalizePath(spec, sub_path, output, &fake_output_path); } else { // No input path, canonicalize to a slash. @@ -87,14 +86,14 @@ bool DoFileCanonicalizePath(const CHAR* spec, template bool DoCanonicalizeFileURL(const URLComponentSource& source, - const url_parse::Parsed& parsed, + const Parsed& parsed, CharsetConverter* query_converter, CanonOutput* output, - url_parse::Parsed* new_parsed) { + Parsed* new_parsed) { // Things we don't set in file: URLs. - new_parsed->username = url_parse::Component(); - new_parsed->password = url_parse::Component(); - new_parsed->port = url_parse::Component(); + new_parsed->username = Component(); + new_parsed->password = Component(); + new_parsed->port = Component(); // Scheme (known, so we don't bother running it through the more // complicated scheme canonicalizer). @@ -124,10 +123,10 @@ bool DoCanonicalizeFileURL(const URLComponentSource& source, bool CanonicalizeFileURL(const char* spec, int spec_len, - const url_parse::Parsed& parsed, + const Parsed& parsed, CharsetConverter* query_converter, CanonOutput* output, - url_parse::Parsed* new_parsed) { + Parsed* new_parsed) { return DoCanonicalizeFileURL( URLComponentSource(spec), parsed, query_converter, output, new_parsed); @@ -135,56 +134,56 @@ bool CanonicalizeFileURL(const char* spec, bool CanonicalizeFileURL(const base::char16* spec, int spec_len, - const url_parse::Parsed& parsed, + const Parsed& parsed, CharsetConverter* query_converter, CanonOutput* output, - url_parse::Parsed* new_parsed) { + Parsed* new_parsed) { return DoCanonicalizeFileURL( URLComponentSource(spec), parsed, query_converter, output, new_parsed); } bool FileCanonicalizePath(const char* spec, - const url_parse::Component& path, + const Component& path, CanonOutput* output, - url_parse::Component* out_path) { + Component* out_path) { return DoFileCanonicalizePath(spec, path, output, out_path); } bool FileCanonicalizePath(const base::char16* spec, - const url_parse::Component& path, + const Component& path, CanonOutput* output, - url_parse::Component* out_path) { + Component* out_path) { return DoFileCanonicalizePath(spec, path, output, out_path); } bool ReplaceFileURL(const char* base, - const url_parse::Parsed& base_parsed, + const Parsed& base_parsed, const Replacements& replacements, CharsetConverter* query_converter, CanonOutput* output, - url_parse::Parsed* new_parsed) { + Parsed* new_parsed) { URLComponentSource source(base); - url_parse::Parsed parsed(base_parsed); + Parsed parsed(base_parsed); SetupOverrideComponents(base, replacements, &source, &parsed); return DoCanonicalizeFileURL( source, parsed, query_converter, output, new_parsed); } bool ReplaceFileURL(const char* base, - const url_parse::Parsed& base_parsed, + const Parsed& base_parsed, const Replacements& replacements, CharsetConverter* query_converter, CanonOutput* output, - url_parse::Parsed* new_parsed) { + Parsed* new_parsed) { RawCanonOutput<1024> utf8; URLComponentSource source(base); - url_parse::Parsed parsed(base_parsed); + Parsed parsed(base_parsed); SetupUTF16OverrideComponents(base, replacements, &utf8, &source, &parsed); return DoCanonicalizeFileURL( source, parsed, query_converter, output, new_parsed); } -} // namespace url_canon +} // namespace url diff --git a/url/url_canon_host.cc b/url/url_canon_host.cc index 9530652ede4b..513248a3804f 100644 --- a/url/url_canon_host.cc +++ b/url/url_canon_host.cc @@ -6,7 +6,7 @@ #include "url/url_canon.h" #include "url/url_canon_internal.h" -namespace url_canon { +namespace url { namespace { @@ -75,8 +75,10 @@ typedef RawCanonOutputT StackBufferW; // |has_non_ascii| will be true if there are any non-7-bit characters, and // |has_escaped| will be true if there is a percent sign. template -void ScanHostname(const CHAR* spec, const url_parse::Component& host, - bool* has_non_ascii, bool* has_escaped) { +void ScanHostname(const CHAR* spec, + const Component& host, + bool* has_non_ascii, + bool* has_escaped) { int end = host.end(); *has_non_ascii = false; *has_escaped = false; @@ -287,13 +289,13 @@ bool DoComplexHost(const base::char16* host, int host_len, template void DoHost(const CHAR* spec, - const url_parse::Component& host, + const Component& host, CanonOutput* output, CanonHostInfo* host_info) { if (host.len <= 0) { // Empty hosts don't need anything. host_info->family = CanonHostInfo::NEUTRAL; - host_info->out_host = url_parse::Component(); + host_info->out_host = Component(); return; } @@ -322,7 +324,7 @@ void DoHost(const CHAR* spec, // should not cause an allocation. RawCanonOutput<64> canon_ip; CanonicalizeIPAddress(output->data(), - url_parse::MakeRange(output_begin, output->length()), + MakeRange(output_begin, output->length()), &canon_ip, host_info); // If we got an IPv4/IPv6 address, copy the canonical form back to the @@ -334,15 +336,15 @@ void DoHost(const CHAR* spec, } } - host_info->out_host = url_parse::MakeRange(output_begin, output->length()); + host_info->out_host = MakeRange(output_begin, output->length()); } } // namespace bool CanonicalizeHost(const char* spec, - const url_parse::Component& host, + const Component& host, CanonOutput* output, - url_parse::Component* out_host) { + Component* out_host) { CanonHostInfo host_info; DoHost(spec, host, output, &host_info); *out_host = host_info.out_host; @@ -350,9 +352,9 @@ bool CanonicalizeHost(const char* spec, } bool CanonicalizeHost(const base::char16* spec, - const url_parse::Component& host, + const Component& host, CanonOutput* output, - url_parse::Component* out_host) { + Component* out_host) { CanonHostInfo host_info; DoHost(spec, host, output, &host_info); *out_host = host_info.out_host; @@ -360,17 +362,17 @@ bool CanonicalizeHost(const base::char16* spec, } void CanonicalizeHostVerbose(const char* spec, - const url_parse::Component& host, + const Component& host, CanonOutput* output, - CanonHostInfo *host_info) { + CanonHostInfo* host_info) { DoHost(spec, host, output, host_info); } void CanonicalizeHostVerbose(const base::char16* spec, - const url_parse::Component& host, + const Component& host, CanonOutput* output, - CanonHostInfo *host_info) { + CanonHostInfo* host_info) { DoHost(spec, host, output, host_info); } -} // namespace url_canon +} // namespace url diff --git a/url/url_canon_icu.cc b/url/url_canon_icu.cc index cabbbf2ae8e0..d53d7cc9b48d 100644 --- a/url/url_canon_icu.cc +++ b/url/url_canon_icu.cc @@ -15,7 +15,7 @@ #include "url/url_canon_icu.h" #include "url/url_canon_internal.h" // for _itoa_s -namespace url_canon { +namespace url { namespace { @@ -227,4 +227,4 @@ bool ReadUTFChar(const base::char16* str, int* begin, int length, return false; } -} // namespace url_canon +} // namespace url diff --git a/url/url_canon_icu.h b/url/url_canon_icu.h index 115976858769..c9632897a190 100644 --- a/url/url_canon_icu.h +++ b/url/url_canon_icu.h @@ -13,7 +13,7 @@ typedef struct UConverter UConverter; -namespace url_canon { +namespace url { // An implementation of CharsetConverter that implementations can use to // interface the canonicalizer with ICU's conversion routines. @@ -35,6 +35,6 @@ class URL_EXPORT ICUCharsetConverter : public CharsetConverter { UConverter* converter_; }; -} // namespace url_canon +} // namespace url #endif // URL_URL_CANON_ICU_H_ diff --git a/url/url_canon_internal.cc b/url/url_canon_internal.cc index 15f93f77c715..bbd14840a5f1 100644 --- a/url/url_canon_internal.cc +++ b/url/url_canon_internal.cc @@ -10,7 +10,7 @@ #include "url/url_canon_internal.h" -namespace url_canon { +namespace url { namespace { @@ -58,12 +58,12 @@ void DoAppendInvalidNarrowString(const CHAR* spec, int begin, int end, } } -// Overrides one component, see the url_canon::Replacements structure for +// Overrides one component, see the Replacements structure for // what the various combionations of source pointer and component mean. void DoOverrideComponent(const char* override_source, - const url_parse::Component& override_component, + const Component& override_component, const char** dest, - url_parse::Component* dest_component) { + Component* dest_component) { if (override_source) { *dest = override_source; *dest_component = override_component; @@ -82,16 +82,15 @@ void DoOverrideComponent(const char* override_source, // may get resized while we're overriding a subsequent component. Instead, the // caller should use the beginning of the |utf8_buffer| as the string pointer // for all components once all overrides have been prepared. -bool PrepareUTF16OverrideComponent( - const base::char16* override_source, - const url_parse::Component& override_component, - CanonOutput* utf8_buffer, - url_parse::Component* dest_component) { +bool PrepareUTF16OverrideComponent(const base::char16* override_source, + const Component& override_component, + CanonOutput* utf8_buffer, + Component* dest_component) { bool success = true; if (override_source) { if (!override_component.is_valid()) { // Non-"valid" component (means delete), so we need to preserve that. - *dest_component = url_parse::Component(); + *dest_component = Component(); } else { // Convert to UTF-8. dest_component->begin = utf8_buffer->length(); @@ -282,10 +281,10 @@ bool ConvertUTF8ToUTF16(const char* input, int input_len, void SetupOverrideComponents(const char* base, const Replacements& repl, URLComponentSource* source, - url_parse::Parsed* parsed) { + Parsed* parsed) { // Get the source and parsed structures of the things we are replacing. const URLComponentSource& repl_source = repl.sources(); - const url_parse::Parsed& repl_parsed = repl.components(); + const Parsed& repl_parsed = repl.components(); DoOverrideComponent(repl_source.scheme, repl_parsed.scheme, &source->scheme, &parsed->scheme); @@ -314,12 +313,12 @@ bool SetupUTF16OverrideComponents(const char* base, const Replacements& repl, CanonOutput* utf8_buffer, URLComponentSource* source, - url_parse::Parsed* parsed) { + Parsed* parsed) { bool success = true; // Get the source and parsed structures of the things we are replacing. const URLComponentSource& repl_source = repl.sources(); - const url_parse::Parsed& repl_parsed = repl.components(); + const Parsed& repl_parsed = repl.components(); success &= PrepareUTF16OverrideComponent( repl_source.scheme, repl_parsed.scheme, @@ -402,4 +401,4 @@ int _itow_s(int value, base::char16* buffer, size_t size_in_chars, int radix) { #endif // !WIN32 -} // namespace url_canon +} // namespace url diff --git a/url/url_canon_internal.h b/url/url_canon_internal.h index b76f8879fcc2..e8efd8234131 100644 --- a/url/url_canon_internal.h +++ b/url/url_canon_internal.h @@ -15,7 +15,7 @@ #include "base/logging.h" #include "url/url_canon.h" -namespace url_canon { +namespace url { // Character type handling ----------------------------------------------------- @@ -354,7 +354,7 @@ URL_EXPORT bool ConvertUTF8ToUTF16(const char* input, int input_len, // Converts from UTF-16 to 8-bit using the character set converter. If the // converter is NULL, this will use UTF-8. void ConvertUTF16ToQueryEncoding(const base::char16* input, - const url_parse::Component& query, + const Component& query, CharsetConverter* converter, CanonOutput* output); @@ -370,7 +370,7 @@ void ConvertUTF16ToQueryEncoding(const base::char16* input, void SetupOverrideComponents(const char* base, const Replacements& repl, URLComponentSource* source, - url_parse::Parsed* parsed); + Parsed* parsed); // Like the above 8-bit version, except that it additionally converts the // UTF-16 input to UTF-8 before doing the overrides. @@ -392,16 +392,16 @@ bool SetupUTF16OverrideComponents(const char* base, const Replacements& repl, CanonOutput* utf8_buffer, URLComponentSource* source, - url_parse::Parsed* parsed); + Parsed* parsed); // Implemented in url_canon_path.cc, these are required by the relative URL // resolver as well, so we declare them here. bool CanonicalizePartialPath(const char* spec, - const url_parse::Component& path, + const Component& path, int path_begin_in_output, CanonOutput* output); bool CanonicalizePartialPath(const base::char16* spec, - const url_parse::Component& path, + const Component& path, int path_begin_in_output, CanonOutput* output); @@ -432,6 +432,6 @@ inline unsigned long long _strtoui64(const char* nptr, #endif // WIN32 -} // namespace url_canon +} // namespace url #endif // URL_URL_CANON_INTERNAL_H_ diff --git a/url/url_canon_internal_file.h b/url/url_canon_internal_file.h index eadc79c075b5..69030982d516 100644 --- a/url/url_canon_internal_file.h +++ b/url/url_canon_internal_file.h @@ -18,7 +18,7 @@ #include "url/url_file.h" #include "url/url_parse_internal.h" -using namespace url_canon; +namespace url { // Given a pointer into the spec, this copies and canonicalizes the drive // letter and colon to the output, if one is found. If there is not a drive @@ -66,11 +66,11 @@ static void FileDoPath(const CHAR* spec, int begin, int end, // path. We supply it with the path following the slashes. It won't prepend // a slash because it assumes any nonempty path already starts with one. // We explicitly filter out calls with no path here to prevent that case. - ParsedURL::Component sub_path(after_slashes, end - after_slashes); + ParsedComponent sub_path(after_slashes, end - after_slashes); if (sub_path.len > 0) { // Give it a fake output component to write into. DoCanonicalizeFile will // compute the full path component. - ParsedURL::Component fake_output_path; + ParsedComponent fake_output_path; URLCanonInternal::DoPath( spec, sub_path, output, &fake_output_path); } @@ -82,9 +82,9 @@ static bool DoCanonicalizeFileURL(const URLComponentSource& source, CanonOutput* output, ParsedURL* new_parsed) { // Things we don't set in file: URLs. - new_parsed->username = ParsedURL::Component(0, -1); - new_parsed->password = ParsedURL::Component(0, -1); - new_parsed->port = ParsedURL::Component(0, -1); + new_parsed->username = ParsedComponent(0, -1); + new_parsed->password = ParsedComponent(0, -1); + new_parsed->port = ParsedComponent(0, -1); // Scheme (known, so we don't bother running it through the more // complicated scheme canonicalizer). @@ -130,4 +130,6 @@ static bool DoCanonicalizeFileURL(const URLComponentSource& source, return success; } +} // namespace url + #endif // URL_URL_CANON_INTERNAL_FILE_H_ diff --git a/url/url_canon_ip.cc b/url/url_canon_ip.cc index f884c2eba991..6ed8ba7203e9 100644 --- a/url/url_canon_ip.cc +++ b/url/url_canon_ip.cc @@ -10,7 +10,7 @@ #include "base/logging.h" #include "url/url_canon_internal.h" -namespace url_canon { +namespace url { namespace { @@ -31,8 +31,8 @@ int BaseForType(SharedCharTypes type) { template bool DoFindIPv4Components(const CHAR* spec, - const url_parse::Component& host, - url_parse::Component components[4]) { + const Component& host, + Component components[4]) { if (!host.is_nonempty()) return false; @@ -43,8 +43,7 @@ bool DoFindIPv4Components(const CHAR* spec, if (i >= end || spec[i] == '.') { // Found the end of the current component. int component_len = i - cur_component_begin; - components[cur_component] = - url_parse::Component(cur_component_begin, component_len); + components[cur_component] = Component(cur_component_begin, component_len); // The next component starts after the dot. cur_component_begin = i + 1; @@ -76,7 +75,7 @@ bool DoFindIPv4Components(const CHAR* spec, // Fill in any unused components. while (cur_component < 4) - components[cur_component++] = url_parse::Component(); + components[cur_component++] = Component(); return true; } @@ -91,10 +90,9 @@ bool DoFindIPv4Components(const CHAR* spec, // out any input that is greater than 7 bits. The components are assumed // to be non-empty. template -CanonHostInfo::Family IPv4ComponentToNumber( - const CHAR* spec, - const url_parse::Component& component, - uint32* number) { +CanonHostInfo::Family IPv4ComponentToNumber(const CHAR* spec, + const Component& component, + uint32* number) { // Figure out the base SharedCharTypes base; int base_prefix_len = 0; // Size of the prefix for this base. @@ -159,11 +157,11 @@ CanonHostInfo::Family IPv4ComponentToNumber( // See declaration of IPv4AddressToNumber for documentation. template CanonHostInfo::Family DoIPv4AddressToNumber(const CHAR* spec, - const url_parse::Component& host, + const Component& host, unsigned char address[4], int* num_ipv4_components) { // The identified components. Not all may exist. - url_parse::Component components[4]; + Component components[4]; if (!FindIPv4Components(spec, host, components)) return CanonHostInfo::NEUTRAL; @@ -227,7 +225,7 @@ CanonHostInfo::Family DoIPv4AddressToNumber(const CHAR* spec, // is NEUTRAL, and we could use a second opinion. template bool DoCanonicalizeIPv4Address(const CHAR* spec, - const url_parse::Component& host, + const Component& host, CanonOutput* output, CanonHostInfo* host_info) { host_info->family = IPv4AddressToNumber( @@ -295,7 +293,7 @@ struct IPv6Parsed { } // There can be up to 8 hex components (colon separated) in the literal. - url_parse::Component hex_components[8]; + Component hex_components[8]; // The count of hex components present. Ranges from [0,8]. int num_hex_components; @@ -305,16 +303,14 @@ struct IPv6Parsed { int index_of_contraction; // The range of characters which are an IPv4 literal. - url_parse::Component ipv4_component; + Component ipv4_component; }; // Parse the IPv6 input string. If parsing succeeded returns true and fills // |parsed| with the information. If parsing failed (because the input is // invalid) returns false. template -bool DoParseIPv6(const CHAR* spec, - const url_parse::Component& host, - IPv6Parsed* parsed) { +bool DoParseIPv6(const CHAR* spec, const Component& host, IPv6Parsed* parsed) { // Zero-out the info. parsed->reset(); @@ -359,7 +355,7 @@ bool DoParseIPv6(const CHAR* spec, return false; parsed->hex_components[parsed->num_hex_components++] = - url_parse::Component(cur_component_begin, component_len); + Component(cur_component_begin, component_len); } } @@ -390,8 +386,8 @@ bool DoParseIPv6(const CHAR* spec, // Since IPv4 address can only appear at the end, assume the rest // of the string is an IPv4 address. (We will parse this separately // later). - parsed->ipv4_component = url_parse::Component( - cur_component_begin, end - cur_component_begin); + parsed->ipv4_component = + Component(cur_component_begin, end - cur_component_begin); break; } else { // The character was neither a hex digit, nor an IPv4 character. @@ -440,8 +436,7 @@ bool CheckIPv6ComponentsSize(const IPv6Parsed& parsed, // already verified that each character in the string was a hex digit, and // that there were no more than 4 characters. template -uint16 IPv6HexComponentToNumber(const CHAR* spec, - const url_parse::Component& component) { +uint16 IPv6HexComponentToNumber(const CHAR* spec, const Component& component) { DCHECK(component.len <= 4); // Copy the hex string into a C-string. @@ -459,7 +454,7 @@ uint16 IPv6HexComponentToNumber(const CHAR* spec, // true on success. False means that the input was not a valid IPv6 address. template bool DoIPv6AddressToNumber(const CHAR* spec, - const url_parse::Component& host, + const Component& host, unsigned char address[16]) { // Make sure the component is bounded by '[' and ']'. int end = host.end(); @@ -467,7 +462,7 @@ bool DoIPv6AddressToNumber(const CHAR* spec, return false; // Exclude the square brackets. - url_parse::Component ipv6_comp(host.begin + 1, host.len - 2); + Component ipv6_comp(host.begin + 1, host.len - 2); // Parse the IPv6 address -- identify where all the colon separated hex // components are, the "::" contraction, and the embedded IPv4 address. @@ -522,12 +517,12 @@ bool DoIPv6AddressToNumber(const CHAR* spec, // range into |contraction_range|. The run of zeros must be at least 16 bits, // and if there is a tie the first is chosen. void ChooseIPv6ContractionRange(const unsigned char address[16], - url_parse::Component* contraction_range) { + Component* contraction_range) { // The longest run of zeros in |address| seen so far. - url_parse::Component max_range; + Component max_range; // The current run of zeros in |address| being iterated over. - url_parse::Component cur_range; + Component cur_range; for (int i = 0; i < 16; i += 2) { // Test for 16 bits worth of zero. @@ -536,7 +531,7 @@ void ChooseIPv6ContractionRange(const unsigned char address[16], if (is_zero) { // Add the zero to the current range (or start a new one). if (!cur_range.is_valid()) - cur_range = url_parse::Component(i, 0); + cur_range = Component(i, 0); cur_range.len += 2; } @@ -556,7 +551,7 @@ void ChooseIPv6ContractionRange(const unsigned char address[16], // is NEUTRAL, and we could use a second opinion. template bool DoCanonicalizeIPv6Address(const CHAR* spec, - const url_parse::Component& host, + const Component& host, CanonOutput* output, CanonHostInfo* host_info) { // Turn the IP address into a 128 bit number. @@ -608,7 +603,7 @@ void AppendIPv6Address(const unsigned char address[16], CanonOutput* output) { // http://tools.ietf.org/html/draft-kawamura-ipv6-text-representation-01#section-4 // Start by finding where to place the "::" contraction (if any). - url_parse::Component contraction_range; + Component contraction_range; ChooseIPv6ContractionRange(address, &contraction_range); for (int i = 0; i <= 14;) { @@ -640,20 +635,20 @@ void AppendIPv6Address(const unsigned char address[16], CanonOutput* output) { } bool FindIPv4Components(const char* spec, - const url_parse::Component& host, - url_parse::Component components[4]) { + const Component& host, + Component components[4]) { return DoFindIPv4Components(spec, host, components); } bool FindIPv4Components(const base::char16* spec, - const url_parse::Component& host, - url_parse::Component components[4]) { + const Component& host, + Component components[4]) { return DoFindIPv4Components( spec, host, components); } void CanonicalizeIPAddress(const char* spec, - const url_parse::Component& host, + const Component& host, CanonOutput* output, CanonHostInfo* host_info) { if (DoCanonicalizeIPv4Address( @@ -665,7 +660,7 @@ void CanonicalizeIPAddress(const char* spec, } void CanonicalizeIPAddress(const base::char16* spec, - const url_parse::Component& host, + const Component& host, CanonOutput* output, CanonHostInfo* host_info) { if (DoCanonicalizeIPv4Address( @@ -677,14 +672,14 @@ void CanonicalizeIPAddress(const base::char16* spec, } CanonHostInfo::Family IPv4AddressToNumber(const char* spec, - const url_parse::Component& host, + const Component& host, unsigned char address[4], int* num_ipv4_components) { return DoIPv4AddressToNumber(spec, host, address, num_ipv4_components); } CanonHostInfo::Family IPv4AddressToNumber(const base::char16* spec, - const url_parse::Component& host, + const Component& host, unsigned char address[4], int* num_ipv4_components) { return DoIPv4AddressToNumber( @@ -692,15 +687,15 @@ CanonHostInfo::Family IPv4AddressToNumber(const base::char16* spec, } bool IPv6AddressToNumber(const char* spec, - const url_parse::Component& host, + const Component& host, unsigned char address[16]) { return DoIPv6AddressToNumber(spec, host, address); } bool IPv6AddressToNumber(const base::char16* spec, - const url_parse::Component& host, + const Component& host, unsigned char address[16]) { return DoIPv6AddressToNumber(spec, host, address); } -} // namespace url_canon +} // namespace url diff --git a/url/url_canon_ip.h b/url/url_canon_ip.h index b2e4a7e7d848..19ecfdb4f069 100644 --- a/url/url_canon_ip.h +++ b/url/url_canon_ip.h @@ -10,7 +10,7 @@ #include "url/url_export.h" #include "url/url_parse.h" -namespace url_canon { +namespace url { // Writes the given IPv4 address to |output|. URL_EXPORT void AppendIPv4Address(const unsigned char address[4], @@ -39,11 +39,11 @@ URL_EXPORT void AppendIPv6Address(const unsigned char address[16], // notice these spaces and escape them, which will make IP address finding // fail. This seems like better behavior than stripping after a space. URL_EXPORT bool FindIPv4Components(const char* spec, - const url_parse::Component& host, - url_parse::Component components[4]); + const Component& host, + Component components[4]); URL_EXPORT bool FindIPv4Components(const base::char16* spec, - const url_parse::Component& host, - url_parse::Component components[4]); + const Component& host, + Component components[4]); // Converts an IPv4 address to a 32-bit number (network byte order). // @@ -56,16 +56,14 @@ URL_EXPORT bool FindIPv4Components(const base::char16* spec, // // On success, |num_ipv4_components| will be populated with the number of // components in the IPv4 address. -URL_EXPORT CanonHostInfo::Family IPv4AddressToNumber( - const char* spec, - const url_parse::Component& host, - unsigned char address[4], - int* num_ipv4_components); -URL_EXPORT CanonHostInfo::Family IPv4AddressToNumber( - const base::char16* spec, - const url_parse::Component& host, - unsigned char address[4], - int* num_ipv4_components); +URL_EXPORT CanonHostInfo::Family IPv4AddressToNumber(const char* spec, + const Component& host, + unsigned char address[4], + int* num_ipv4_components); +URL_EXPORT CanonHostInfo::Family IPv4AddressToNumber(const base::char16* spec, + const Component& host, + unsigned char address[4], + int* num_ipv4_components); // Converts an IPv6 address to a 128-bit number (network byte order), returning // true on success. False means that the input was not a valid IPv6 address. @@ -73,12 +71,12 @@ URL_EXPORT CanonHostInfo::Family IPv4AddressToNumber( // NOTE that |host| is expected to be surrounded by square brackets. // i.e. "[::1]" rather than "::1". URL_EXPORT bool IPv6AddressToNumber(const char* spec, - const url_parse::Component& host, + const Component& host, unsigned char address[16]); URL_EXPORT bool IPv6AddressToNumber(const base::char16* spec, - const url_parse::Component& host, + const Component& host, unsigned char address[16]); -} // namespace url_canon +} // namespace url #endif // URL_URL_CANON_IP_H_ diff --git a/url/url_canon_mailtourl.cc b/url/url_canon_mailtourl.cc index 7d9d18a4bd54..7c48b9590862 100644 --- a/url/url_canon_mailtourl.cc +++ b/url/url_canon_mailtourl.cc @@ -9,23 +9,21 @@ #include "url/url_file.h" #include "url/url_parse_internal.h" -namespace url_canon { +namespace url { namespace { - -template +template bool DoCanonicalizeMailtoURL(const URLComponentSource& source, - const url_parse::Parsed& parsed, + const Parsed& parsed, CanonOutput* output, - url_parse::Parsed* new_parsed) { - + Parsed* new_parsed) { // mailto: only uses {scheme, path, query} -- clear the rest. - new_parsed->username = url_parse::Component(); - new_parsed->password = url_parse::Component(); - new_parsed->host = url_parse::Component(); - new_parsed->port = url_parse::Component(); - new_parsed->ref = url_parse::Component(); + new_parsed->username = Component(); + new_parsed->password = Component(); + new_parsed->host = Component(); + new_parsed->port = Component(); + new_parsed->ref = Component(); // Scheme (known, so we don't bother running it through the more // complicated scheme canonicalizer). @@ -67,46 +65,46 @@ bool DoCanonicalizeMailtoURL(const URLComponentSource& source, } // namespace bool CanonicalizeMailtoURL(const char* spec, - int spec_len, - const url_parse::Parsed& parsed, - CanonOutput* output, - url_parse::Parsed* new_parsed) { + int spec_len, + const Parsed& parsed, + CanonOutput* output, + Parsed* new_parsed) { return DoCanonicalizeMailtoURL( URLComponentSource(spec), parsed, output, new_parsed); } bool CanonicalizeMailtoURL(const base::char16* spec, int spec_len, - const url_parse::Parsed& parsed, + const Parsed& parsed, CanonOutput* output, - url_parse::Parsed* new_parsed) { + Parsed* new_parsed) { return DoCanonicalizeMailtoURL( URLComponentSource(spec), parsed, output, new_parsed); } bool ReplaceMailtoURL(const char* base, - const url_parse::Parsed& base_parsed, + const Parsed& base_parsed, const Replacements& replacements, CanonOutput* output, - url_parse::Parsed* new_parsed) { + Parsed* new_parsed) { URLComponentSource source(base); - url_parse::Parsed parsed(base_parsed); + Parsed parsed(base_parsed); SetupOverrideComponents(base, replacements, &source, &parsed); return DoCanonicalizeMailtoURL( source, parsed, output, new_parsed); } bool ReplaceMailtoURL(const char* base, - const url_parse::Parsed& base_parsed, + const Parsed& base_parsed, const Replacements& replacements, CanonOutput* output, - url_parse::Parsed* new_parsed) { + Parsed* new_parsed) { RawCanonOutput<1024> utf8; URLComponentSource source(base); - url_parse::Parsed parsed(base_parsed); + Parsed parsed(base_parsed); SetupUTF16OverrideComponents(base, replacements, &utf8, &source, &parsed); return DoCanonicalizeMailtoURL( source, parsed, output, new_parsed); } -} // namespace url_canon +} // namespace url diff --git a/url/url_canon_path.cc b/url/url_canon_path.cc index f42af6899e71..ceff68963199 100644 --- a/url/url_canon_path.cc +++ b/url/url_canon_path.cc @@ -7,7 +7,7 @@ #include "url/url_canon_internal.h" #include "url/url_parse_internal.h" -namespace url_canon { +namespace url { namespace { @@ -105,7 +105,7 @@ DotDisposition ClassifyAfterDot(const CHAR* spec, int after_dot, *consumed_len = 0; return DIRECTORY_CUR; } - if (url_parse::IsURLSlash(spec[after_dot])) { + if (IsURLSlash(spec[after_dot])) { // Single dot followed by a slash. *consumed_len = 1; // Consume the slash return DIRECTORY_CUR; @@ -119,7 +119,7 @@ DotDisposition ClassifyAfterDot(const CHAR* spec, int after_dot, *consumed_len = second_dot_len; return DIRECTORY_UP; } - if (url_parse::IsURLSlash(spec[after_second_dot])) { + if (IsURLSlash(spec[after_second_dot])) { // Double dot followed by a slash. *consumed_len = second_dot_len + 1; return DIRECTORY_UP; @@ -177,7 +177,7 @@ void BackUpToPreviousSlash(int path_begin_in_output, // it would be correct for most systems. template bool DoPartialPath(const CHAR* spec, - const url_parse::Component& path, + const Component& path, int path_begin_in_output, CanonOutput* output) { int end = path.end(); @@ -295,9 +295,9 @@ bool DoPartialPath(const CHAR* spec, template bool DoPath(const CHAR* spec, - const url_parse::Component& path, + const Component& path, CanonOutput* output, - url_parse::Component* out_path) { + Component* out_path) { bool success = true; out_path->begin = output->length(); if (path.len > 0) { @@ -305,7 +305,7 @@ bool DoPath(const CHAR* spec, // and then canonicalize it, it will of course have a slash already. This // check is for the replacement and relative URL resolving cases of file // URLs. - if (!url_parse::IsURLSlash(spec[path.begin])) + if (!IsURLSlash(spec[path.begin])) output->push_back('/'); success = DoPartialPath(spec, path, out_path->begin, output); @@ -320,21 +320,21 @@ bool DoPath(const CHAR* spec, } // namespace bool CanonicalizePath(const char* spec, - const url_parse::Component& path, + const Component& path, CanonOutput* output, - url_parse::Component* out_path) { + Component* out_path) { return DoPath(spec, path, output, out_path); } bool CanonicalizePath(const base::char16* spec, - const url_parse::Component& path, + const Component& path, CanonOutput* output, - url_parse::Component* out_path) { + Component* out_path) { return DoPath(spec, path, output, out_path); } bool CanonicalizePartialPath(const char* spec, - const url_parse::Component& path, + const Component& path, int path_begin_in_output, CanonOutput* output) { return DoPartialPath(spec, path, path_begin_in_output, @@ -342,7 +342,7 @@ bool CanonicalizePartialPath(const char* spec, } bool CanonicalizePartialPath(const base::char16* spec, - const url_parse::Component& path, + const Component& path, int path_begin_in_output, CanonOutput* output) { return DoPartialPath(spec, path, @@ -350,4 +350,4 @@ bool CanonicalizePartialPath(const base::char16* spec, output); } -} // namespace url_canon +} // namespace url diff --git a/url/url_canon_pathurl.cc b/url/url_canon_pathurl.cc index 8f7dee48f738..e81a4afec6a1 100644 --- a/url/url_canon_pathurl.cc +++ b/url/url_canon_pathurl.cc @@ -9,7 +9,7 @@ #include "url/url_canon.h" #include "url/url_canon_internal.h" -namespace url_canon { +namespace url { namespace { @@ -18,10 +18,10 @@ namespace { // prior to the canonicalized component; i.e. for the '?' or '#' characters. template bool DoCanonicalizePathComponent(const CHAR* source, - const url_parse::Component& component, + const Component& component, CHAR seperator, CanonOutput* output, - url_parse::Component* new_component) { + Component* new_component) { bool success = true; if (component.is_valid()) { if (seperator) @@ -46,11 +46,11 @@ bool DoCanonicalizePathComponent(const CHAR* source, return success; } -template +template bool DoCanonicalizePathURL(const URLComponentSource& source, - const url_parse::Parsed& parsed, + const Parsed& parsed, CanonOutput* output, - url_parse::Parsed* new_parsed) { + Parsed* new_parsed) { // Scheme: this will append the colon. bool success = CanonicalizeScheme(source.scheme, parsed.scheme, output, &new_parsed->scheme); @@ -77,45 +77,45 @@ bool DoCanonicalizePathURL(const URLComponentSource& source, bool CanonicalizePathURL(const char* spec, int spec_len, - const url_parse::Parsed& parsed, + const Parsed& parsed, CanonOutput* output, - url_parse::Parsed* new_parsed) { + Parsed* new_parsed) { return DoCanonicalizePathURL( URLComponentSource(spec), parsed, output, new_parsed); } bool CanonicalizePathURL(const base::char16* spec, int spec_len, - const url_parse::Parsed& parsed, + const Parsed& parsed, CanonOutput* output, - url_parse::Parsed* new_parsed) { + Parsed* new_parsed) { return DoCanonicalizePathURL( URLComponentSource(spec), parsed, output, new_parsed); } bool ReplacePathURL(const char* base, - const url_parse::Parsed& base_parsed, + const Parsed& base_parsed, const Replacements& replacements, CanonOutput* output, - url_parse::Parsed* new_parsed) { + Parsed* new_parsed) { URLComponentSource source(base); - url_parse::Parsed parsed(base_parsed); + Parsed parsed(base_parsed); SetupOverrideComponents(base, replacements, &source, &parsed); return DoCanonicalizePathURL( source, parsed, output, new_parsed); } bool ReplacePathURL(const char* base, - const url_parse::Parsed& base_parsed, + const Parsed& base_parsed, const Replacements& replacements, CanonOutput* output, - url_parse::Parsed* new_parsed) { + Parsed* new_parsed) { RawCanonOutput<1024> utf8; URLComponentSource source(base); - url_parse::Parsed parsed(base_parsed); + Parsed parsed(base_parsed); SetupUTF16OverrideComponents(base, replacements, &utf8, &source, &parsed); return DoCanonicalizePathURL( source, parsed, output, new_parsed); } -} // namespace url_canon +} // namespace url diff --git a/url/url_canon_query.cc b/url/url_canon_query.cc index b17a73b2d973..5494ddfe896c 100644 --- a/url/url_canon_query.cc +++ b/url/url_canon_query.cc @@ -35,14 +35,14 @@ // replace all invalid sequences (including invalid UTF-16 sequences, which IE // doesn't) with the "invalid character," and we will escape it. -namespace url_canon { +namespace url { namespace { // Returns true if the characters starting at |begin| and going until |end| // (non-inclusive) are all representable in 7-bits. template -bool IsAllASCII(const CHAR* spec, const url_parse::Component& query) { +bool IsAllASCII(const CHAR* spec, const Component& query) { int end = query.end(); for (int i = query.begin; i < end; i++) { if (static_cast(spec[i]) >= 0x80) @@ -69,7 +69,7 @@ void AppendRaw8BitQueryString(const CHAR* source, int length, // Runs the converter on the given UTF-8 input. Since the converter expects // UTF-16, we have to convert first. The converter must be non-NULL. void RunConverter(const char* spec, - const url_parse::Component& query, + const Component& query, CharsetConverter* converter, CanonOutput* output) { // This function will replace any misencoded values with the invalid @@ -83,7 +83,7 @@ void RunConverter(const char* spec, // anything, but this overriddden function allows us to use the same code // for both UTF-8 and UTF-16 input. void RunConverter(const base::char16* spec, - const url_parse::Component& query, + const Component& query, CharsetConverter* converter, CanonOutput* output) { converter->ConvertFromUTF16(&spec[query.begin], query.len, output); @@ -91,7 +91,7 @@ void RunConverter(const base::char16* spec, template void DoConvertToQueryEncoding(const CHAR* spec, - const url_parse::Component& query, + const Component& query, CharsetConverter* converter, CanonOutput* output) { if (IsAllASCII(spec, query)) { @@ -116,12 +116,12 @@ void DoConvertToQueryEncoding(const CHAR* spec, template void DoCanonicalizeQuery(const CHAR* spec, - const url_parse::Component& query, + const Component& query, CharsetConverter* converter, CanonOutput* output, - url_parse::Component* out_query) { + Component* out_query) { if (query.len < 0) { - *out_query = url_parse::Component(); + *out_query = Component(); return; } @@ -136,29 +136,29 @@ void DoCanonicalizeQuery(const CHAR* spec, } // namespace void CanonicalizeQuery(const char* spec, - const url_parse::Component& query, + const Component& query, CharsetConverter* converter, CanonOutput* output, - url_parse::Component* out_query) { + Component* out_query) { DoCanonicalizeQuery(spec, query, converter, output, out_query); } void CanonicalizeQuery(const base::char16* spec, - const url_parse::Component& query, + const Component& query, CharsetConverter* converter, CanonOutput* output, - url_parse::Component* out_query) { + Component* out_query) { DoCanonicalizeQuery(spec, query, converter, output, out_query); } void ConvertUTF16ToQueryEncoding(const base::char16* input, - const url_parse::Component& query, + const Component& query, CharsetConverter* converter, CanonOutput* output) { DoConvertToQueryEncoding(input, query, converter, output); } -} // namespace url_canon +} // namespace url diff --git a/url/url_canon_relative.cc b/url/url_canon_relative.cc index c210587d22d8..275a6fdadd06 100644 --- a/url/url_canon_relative.cc +++ b/url/url_canon_relative.cc @@ -11,7 +11,7 @@ #include "url/url_parse_internal.h" #include "url/url_util_internal.h" -namespace url_canon { +namespace url { namespace { @@ -26,9 +26,9 @@ namespace { // The base URL should always be canonical, therefore is ASCII. template bool AreSchemesEqual(const char* base, - const url_parse::Component& base_scheme, + const Component& base_scheme, const CHAR* cmp, - const url_parse::Component& cmp_scheme) { + const Component& cmp_scheme) { if (base_scheme.len != cmp_scheme.len) return false; for (int i = 0; i < base_scheme.len; i++) { @@ -52,8 +52,8 @@ bool DoesBeginSlashWindowsDriveSpec(const CHAR* spec, int start_offset, int spec_len) { if (start_offset >= spec_len) return false; - return url_parse::IsURLSlash(spec[start_offset]) && - url_parse::DoesBeginWindowsDriveSpec(spec, start_offset + 1, spec_len); + return IsURLSlash(spec[start_offset]) && + DoesBeginWindowsDriveSpec(spec, start_offset + 1, spec_len); } #endif // WIN32 @@ -61,20 +61,20 @@ bool DoesBeginSlashWindowsDriveSpec(const CHAR* spec, int start_offset, // See IsRelativeURL in the header file for usage. template bool DoIsRelativeURL(const char* base, - const url_parse::Parsed& base_parsed, + const Parsed& base_parsed, const CHAR* url, int url_len, bool is_base_hierarchical, bool* is_relative, - url_parse::Component* relative_component) { + Component* relative_component) { *is_relative = false; // So we can default later to not relative. // Trim whitespace and construct a new range for the substring. int begin = 0; - url_parse::TrimURL(url, &begin, &url_len); + TrimURL(url, &begin, &url_len); if (begin >= url_len) { // Empty URLs are relative, but do nothing. - *relative_component = url_parse::Component(begin, 0); + *relative_component = Component(begin, 0); *is_relative = true; return true; } @@ -91,8 +91,8 @@ bool DoIsRelativeURL(const char* base, // // We require strict backslashes when detecting UNC since two forward // shashes should be treated a a relative URL with a hostname. - if (url_parse::DoesBeginWindowsDriveSpec(url, begin, url_len) || - url_parse::DoesBeginUNCPath(url, begin, url_len, true)) + if (DoesBeginWindowsDriveSpec(url, begin, url_len) || + DoesBeginUNCPath(url, begin, url_len, true)) return true; #endif // WIN32 @@ -100,9 +100,9 @@ bool DoIsRelativeURL(const char* base, // BUT: Just because we have a scheme, doesn't make it absolute. // "http:foo.html" is a relative URL with path "foo.html". If the scheme is // empty, we treat it as relative (":foo") like IE does. - url_parse::Component scheme; + Component scheme; const bool scheme_is_empty = - !url_parse::ExtractScheme(url, url_len, &scheme) || scheme.len == 0; + !ExtractScheme(url, url_len, &scheme) || scheme.len == 0; if (scheme_is_empty) { if (url[begin] == '#') { // |url| is a bare fragement (e.g. "#foo"). This can be resolved against @@ -112,7 +112,7 @@ bool DoIsRelativeURL(const char* base, return false; } - *relative_component = url_parse::MakeRange(begin, url_len); + *relative_component = MakeRange(begin, url_len); *is_relative = true; return true; } @@ -125,7 +125,7 @@ bool DoIsRelativeURL(const char* base, // Don't allow relative URLs if the base scheme doesn't support it. return false; } - *relative_component = url_parse::MakeRange(begin, url_len); + *relative_component = MakeRange(begin, url_len); *is_relative = true; return true; } @@ -145,20 +145,19 @@ bool DoIsRelativeURL(const char* base, // If it's a filesystem URL, the only valid way to make it relative is not to // supply a scheme. There's no equivalent to e.g. http:index.html. - if (url_util::CompareSchemeComponent(url, scheme, "filesystem")) + if (CompareSchemeComponent(url, scheme, "filesystem")) return true; // ExtractScheme guarantees that the colon immediately follows what it // considers to be the scheme. CountConsecutiveSlashes will handle the // case where the begin offset is the end of the input. - int num_slashes = url_parse::CountConsecutiveSlashes(url, colon_offset + 1, - url_len); + int num_slashes = CountConsecutiveSlashes(url, colon_offset + 1, url_len); if (num_slashes == 0 || num_slashes == 1) { // No slashes means it's a relative path like "http:foo.html". One slash // is an absolute path. "http:/home/foo.html" *is_relative = true; - *relative_component = url_parse::MakeRange(colon_offset + 1, url_len); + *relative_component = MakeRange(colon_offset + 1, url_len); return true; } @@ -197,12 +196,12 @@ void CopyToLastSlash(const char* spec, // source should already be canonical, we don't have to do anything special, // and the input is ASCII. void CopyOneComponent(const char* source, - const url_parse::Component& source_component, + const Component& source_component, CanonOutput* output, - url_parse::Component* output_component) { + Component* output_component) { if (source_component.len < 0) { // This component is not present. - *output_component = url_parse::Component(); + *output_component = Component(); return; } @@ -237,8 +236,7 @@ int CopyBaseDriveSpecIfNecessary(const char* base_url, // If the relative begins with a drive spec, don't do anything. The existing // drive spec in the base will be replaced. - if (url_parse::DoesBeginWindowsDriveSpec(relative_url, - path_start, relative_url_len)) { + if (DoesBeginWindowsDriveSpec(relative_url, path_start, relative_url_len)) { return base_path_begin; // Relative URL path is "C:/foo" } @@ -264,23 +262,19 @@ int CopyBaseDriveSpecIfNecessary(const char* base_url, // the input is a relative path or less (qyuery or ref). template bool DoResolveRelativePath(const char* base_url, - const url_parse::Parsed& base_parsed, + const Parsed& base_parsed, bool base_is_file, const CHAR* relative_url, - const url_parse::Component& relative_component, + const Component& relative_component, CharsetConverter* query_converter, CanonOutput* output, - url_parse::Parsed* out_parsed) { + Parsed* out_parsed) { bool success = true; // We know the authority section didn't change, copy it to the output. We // also know we have a path so can copy up to there. - url_parse::Component path, query, ref; - url_parse::ParsePathInternal(relative_url, - relative_component, - &path, - &query, - &ref); + Component path, query, ref; + ParsePathInternal(relative_url, relative_component, &path, &query, &ref); // Canonical URLs always have a path, so we can use that offset. output->Append(base_url, base_parsed.path.begin); @@ -305,7 +299,7 @@ bool DoResolveRelativePath(const char* base_url, } #endif // WIN32 - if (url_parse::IsURLSlash(relative_url[path.begin])) { + if (IsURLSlash(relative_url[path.begin])) { // Easy case: the path is an absolute path on the server, so we can // just replace everything from the path on with the new versions. // Since the input should be canonical hierarchical URL, we should @@ -321,7 +315,7 @@ bool DoResolveRelativePath(const char* base_url, output); success &= CanonicalizePartialPath(relative_url, path, path_begin, output); - out_parsed->path = url_parse::MakeRange(path_begin, output->length()); + out_parsed->path = MakeRange(path_begin, output->length()); // Copy the rest of the stuff after the path from the relative path. } @@ -332,8 +326,7 @@ bool DoResolveRelativePath(const char* base_url, CanonicalizeRef(relative_url, ref, output, &out_parsed->ref); // Fix the path beginning to add back the "C:" we may have written above. - out_parsed->path = url_parse::MakeRange(true_path_begin, - out_parsed->path.end()); + out_parsed->path = MakeRange(true_path_begin, out_parsed->path.end()); return success; } @@ -373,17 +366,17 @@ bool DoResolveRelativePath(const char* base_url, // should be kept from the original URL is the scheme. template bool DoResolveRelativeHost(const char* base_url, - const url_parse::Parsed& base_parsed, + const Parsed& base_parsed, const CHAR* relative_url, - const url_parse::Component& relative_component, + const Component& relative_component, CharsetConverter* query_converter, CanonOutput* output, - url_parse::Parsed* out_parsed) { + Parsed* out_parsed) { // Parse the relative URL, just like we would for anything following a // scheme. - url_parse::Parsed relative_parsed; // Everything but the scheme is valid. - url_parse::ParseAfterScheme(relative_url, relative_component.end(), - relative_component.begin, &relative_parsed); + Parsed relative_parsed; // Everything but the scheme is valid. + ParseAfterScheme(relative_url, relative_component.end(), + relative_component.begin, &relative_parsed); // Now we can just use the replacement function to replace all the necessary // parts of the old URL with the new one. @@ -404,16 +397,16 @@ bool DoResolveRelativeHost(const char* base_url, // include: "//hostname/path", "/c:/foo", and "//hostname/c:/foo". template bool DoResolveAbsoluteFile(const CHAR* relative_url, - const url_parse::Component& relative_component, + const Component& relative_component, CharsetConverter* query_converter, CanonOutput* output, - url_parse::Parsed* out_parsed) { + Parsed* out_parsed) { // Parse the file URL. The file URl parsing function uses the same logic // as we do for determining if the file is absolute, in which case it will // not bother to look for a scheme. - url_parse::Parsed relative_parsed; - url_parse::ParseFileURL(&relative_url[relative_component.begin], - relative_component.len, &relative_parsed); + Parsed relative_parsed; + ParseFileURL(&relative_url[relative_component.begin], relative_component.len, + &relative_parsed); return CanonicalizeFileURL(&relative_url[relative_component.begin], relative_component.len, relative_parsed, @@ -423,13 +416,13 @@ bool DoResolveAbsoluteFile(const CHAR* relative_url, // TODO(brettw) treat two slashes as root like Mozilla for FTP? template bool DoResolveRelativeURL(const char* base_url, - const url_parse::Parsed& base_parsed, + const Parsed& base_parsed, bool base_is_file, const CHAR* relative_url, - const url_parse::Component& relative_component, + const Component& relative_component, CharsetConverter* query_converter, CanonOutput* output, - url_parse::Parsed* out_parsed) { + Parsed* out_parsed) { // Starting point for our output parsed. We'll fix what we change. *out_parsed = base_parsed; @@ -456,7 +449,7 @@ bool DoResolveRelativeURL(const char* base_url, return true; } - int num_slashes = url_parse::CountConsecutiveSlashes( + int num_slashes = CountConsecutiveSlashes( relative_url, relative_component.begin, relative_component.end()); #ifdef WIN32 @@ -472,13 +465,13 @@ bool DoResolveRelativeURL(const char* base_url, // be setting the path. // // This assumes the absolute path resolver handles absolute URLs like this - // properly. url_util::DoCanonicalize does this. + // properly. DoCanonicalize does this. int after_slashes = relative_component.begin + num_slashes; - if (url_parse::DoesBeginUNCPath(relative_url, relative_component.begin, - relative_component.end(), !base_is_file) || + if (DoesBeginUNCPath(relative_url, relative_component.begin, + relative_component.end(), !base_is_file) || ((num_slashes == 0 || base_is_file) && - url_parse::DoesBeginWindowsDriveSpec(relative_url, after_slashes, - relative_component.end()))) { + DoesBeginWindowsDriveSpec( + relative_url, after_slashes, relative_component.end()))) { return DoResolveAbsoluteFile(relative_url, relative_component, query_converter, output, out_parsed); } @@ -514,53 +507,53 @@ bool DoResolveRelativeURL(const char* base_url, } // namespace bool IsRelativeURL(const char* base, - const url_parse::Parsed& base_parsed, + const Parsed& base_parsed, const char* fragment, int fragment_len, bool is_base_hierarchical, bool* is_relative, - url_parse::Component* relative_component) { + Component* relative_component) { return DoIsRelativeURL( base, base_parsed, fragment, fragment_len, is_base_hierarchical, is_relative, relative_component); } bool IsRelativeURL(const char* base, - const url_parse::Parsed& base_parsed, + const Parsed& base_parsed, const base::char16* fragment, int fragment_len, bool is_base_hierarchical, bool* is_relative, - url_parse::Component* relative_component) { + Component* relative_component) { return DoIsRelativeURL( base, base_parsed, fragment, fragment_len, is_base_hierarchical, is_relative, relative_component); } bool ResolveRelativeURL(const char* base_url, - const url_parse::Parsed& base_parsed, + const Parsed& base_parsed, bool base_is_file, const char* relative_url, - const url_parse::Component& relative_component, + const Component& relative_component, CharsetConverter* query_converter, CanonOutput* output, - url_parse::Parsed* out_parsed) { + Parsed* out_parsed) { return DoResolveRelativeURL( base_url, base_parsed, base_is_file, relative_url, relative_component, query_converter, output, out_parsed); } bool ResolveRelativeURL(const char* base_url, - const url_parse::Parsed& base_parsed, + const Parsed& base_parsed, bool base_is_file, const base::char16* relative_url, - const url_parse::Component& relative_component, + const Component& relative_component, CharsetConverter* query_converter, CanonOutput* output, - url_parse::Parsed* out_parsed) { + Parsed* out_parsed) { return DoResolveRelativeURL( base_url, base_parsed, base_is_file, relative_url, relative_component, query_converter, output, out_parsed); } -} // namespace url_canon +} // namespace url diff --git a/url/url_canon_stdstring.cc b/url/url_canon_stdstring.cc index ad81a2ff09ac..366a2e070fc2 100644 --- a/url/url_canon_stdstring.cc +++ b/url/url_canon_stdstring.cc @@ -4,7 +4,7 @@ #include "url/url_canon_stdstring.h" -namespace url_canon { +namespace url { StdStringCanonOutput::StdStringCanonOutput(std::string* str) : CanonOutput(), str_(str) { @@ -29,4 +29,4 @@ void StdStringCanonOutput::Resize(int sz) { buffer_len_ = sz; } -} // namespace url_canon +} // namespace url diff --git a/url/url_canon_stdstring.h b/url/url_canon_stdstring.h index 0915672c371b..e859fe2301dc 100644 --- a/url/url_canon_stdstring.h +++ b/url/url_canon_stdstring.h @@ -15,7 +15,7 @@ #include "url/url_canon.h" #include "url/url_export.h" -namespace url_canon { +namespace url { // Write into a std::string given in the constructor. This object does not own // the string itself, and the user must ensure that the string stays alive @@ -53,43 +53,34 @@ class URL_EXPORT StdStringCanonOutput : public CanonOutput { // The strings passed as arguments are not copied and must remain valid until // this class goes out of scope. template -class StdStringReplacements : - public url_canon::Replacements { +class StdStringReplacements : public Replacements { public: void SetSchemeStr(const STR& s) { - this->SetScheme(s.data(), - url_parse::Component(0, static_cast(s.length()))); + this->SetScheme(s.data(), Component(0, static_cast(s.length()))); } void SetUsernameStr(const STR& s) { - this->SetUsername(s.data(), - url_parse::Component(0, static_cast(s.length()))); + this->SetUsername(s.data(), Component(0, static_cast(s.length()))); } void SetPasswordStr(const STR& s) { - this->SetPassword(s.data(), - url_parse::Component(0, static_cast(s.length()))); + this->SetPassword(s.data(), Component(0, static_cast(s.length()))); } void SetHostStr(const STR& s) { - this->SetHost(s.data(), - url_parse::Component(0, static_cast(s.length()))); + this->SetHost(s.data(), Component(0, static_cast(s.length()))); } void SetPortStr(const STR& s) { - this->SetPort(s.data(), - url_parse::Component(0, static_cast(s.length()))); + this->SetPort(s.data(), Component(0, static_cast(s.length()))); } void SetPathStr(const STR& s) { - this->SetPath(s.data(), - url_parse::Component(0, static_cast(s.length()))); + this->SetPath(s.data(), Component(0, static_cast(s.length()))); } void SetQueryStr(const STR& s) { - this->SetQuery(s.data(), - url_parse::Component(0, static_cast(s.length()))); + this->SetQuery(s.data(), Component(0, static_cast(s.length()))); } void SetRefStr(const STR& s) { - this->SetRef(s.data(), - url_parse::Component(0, static_cast(s.length()))); + this->SetRef(s.data(), Component(0, static_cast(s.length()))); } }; -} // namespace url_canon +} // namespace url #endif // URL_URL_CANON_STDSTRING_H_ diff --git a/url/url_canon_stdurl.cc b/url/url_canon_stdurl.cc index 548dc99ac3ff..1f5000e72c6d 100644 --- a/url/url_canon_stdurl.cc +++ b/url/url_canon_stdurl.cc @@ -8,16 +8,16 @@ #include "url/url_canon.h" #include "url/url_canon_internal.h" -namespace url_canon { +namespace url { namespace { template bool DoCanonicalizeStandardURL(const URLComponentSource& source, - const url_parse::Parsed& parsed, + const Parsed& parsed, CharsetConverter* query_converter, CanonOutput* output, - url_parse::Parsed* new_parsed) { + Parsed* new_parsed) { // Scheme: this will append the colon. bool success = CanonicalizeScheme(source.scheme, parsed.scheme, output, &new_parsed->scheme); @@ -72,7 +72,7 @@ bool DoCanonicalizeStandardURL(const URLComponentSource& source, // When we have an empty path, make up a path when we have an authority // or something following the path. The only time we allow an empty // output path is when there is nothing else. - new_parsed->path = url_parse::Component(output->length(), 1); + new_parsed->path = Component(output->length(), 1); output->push_back('/'); } else { // No path at all @@ -95,7 +95,7 @@ bool DoCanonicalizeStandardURL(const URLComponentSource& source, // Returns the default port for the given canonical scheme, or PORT_UNSPECIFIED // if the scheme is unknown. int DefaultPortForScheme(const char* scheme, int scheme_len) { - int default_port = url_parse::PORT_UNSPECIFIED; + int default_port = PORT_UNSPECIFIED; switch (scheme_len) { case 4: if (!strncmp(scheme, "http", scheme_len)) @@ -125,10 +125,10 @@ int DefaultPortForScheme(const char* scheme, int scheme_len) { bool CanonicalizeStandardURL(const char* spec, int spec_len, - const url_parse::Parsed& parsed, + const Parsed& parsed, CharsetConverter* query_converter, CanonOutput* output, - url_parse::Parsed* new_parsed) { + Parsed* new_parsed) { return DoCanonicalizeStandardURL( URLComponentSource(spec), parsed, query_converter, output, new_parsed); @@ -136,10 +136,10 @@ bool CanonicalizeStandardURL(const char* spec, bool CanonicalizeStandardURL(const base::char16* spec, int spec_len, - const url_parse::Parsed& parsed, + const Parsed& parsed, CharsetConverter* query_converter, CanonOutput* output, - url_parse::Parsed* new_parsed) { + Parsed* new_parsed) { return DoCanonicalizeStandardURL( URLComponentSource(spec), parsed, query_converter, output, new_parsed); @@ -155,13 +155,13 @@ bool CanonicalizeStandardURL(const base::char16* spec, // You would also need to update DoReplaceComponents in url_util.cc which // relies on this re-checking everything (see the comment there for why). bool ReplaceStandardURL(const char* base, - const url_parse::Parsed& base_parsed, + const Parsed& base_parsed, const Replacements& replacements, CharsetConverter* query_converter, CanonOutput* output, - url_parse::Parsed* new_parsed) { + Parsed* new_parsed) { URLComponentSource source(base); - url_parse::Parsed parsed(base_parsed); + Parsed parsed(base_parsed); SetupOverrideComponents(base, replacements, &source, &parsed); return DoCanonicalizeStandardURL( source, parsed, query_converter, output, new_parsed); @@ -170,17 +170,17 @@ bool ReplaceStandardURL(const char* base, // For 16-bit replacements, we turn all the replacements into UTF-8 so the // regular codepath can be used. bool ReplaceStandardURL(const char* base, - const url_parse::Parsed& base_parsed, + const Parsed& base_parsed, const Replacements& replacements, CharsetConverter* query_converter, CanonOutput* output, - url_parse::Parsed* new_parsed) { + Parsed* new_parsed) { RawCanonOutput<1024> utf8; URLComponentSource source(base); - url_parse::Parsed parsed(base_parsed); + Parsed parsed(base_parsed); SetupUTF16OverrideComponents(base, replacements, &utf8, &source, &parsed); return DoCanonicalizeStandardURL( source, parsed, query_converter, output, new_parsed); } -} // namespace url_canon +} // namespace url diff --git a/url/url_canon_unittest.cc b/url/url_canon_unittest.cc index 9997afa82760..55f9608006c8 100644 --- a/url/url_canon_unittest.cc +++ b/url/url_canon_unittest.cc @@ -20,17 +20,18 @@ #define ARRAYSIZE ARRAYSIZE_UNSAFE #endif -using url_test_utils::WStringToUTF16; -using url_test_utils::ConvertUTF8ToUTF16; -using url_test_utils::ConvertUTF16ToUTF8; -using url_canon::CanonHostInfo; +namespace url { + +using test_utils::WStringToUTF16; +using test_utils::ConvertUTF8ToUTF16; +using test_utils::ConvertUTF16ToUTF8; namespace { struct ComponentCase { const char* input; const char* expected; - url_parse::Component expected_component; + Component expected_component; bool expected_success; }; @@ -41,7 +42,7 @@ struct DualComponentCase { const char* input8; const wchar_t* input16; const char* expected; - url_parse::Component expected_component; + Component expected_component; bool expected_success; }; @@ -51,7 +52,7 @@ struct IPAddressCase { const char* input8; const wchar_t* input16; const char* expected; - url_parse::Component expected_component; + Component expected_component; // CanonHostInfo fields, for verbose output. CanonHostInfo::Family expected_family; @@ -64,8 +65,8 @@ std::string BytesToHexString(unsigned char bytes[16], int length) { << "Bad IP address length: " << length; std::string result; for (int i = 0; i < length; ++i) { - result.push_back(url_canon::kHexCharLookup[(bytes[i] >> 4) & 0xf]); - result.push_back(url_canon::kHexCharLookup[bytes[i] & 0xf]); + result.push_back(kHexCharLookup[(bytes[i] >> 4) & 0xf]); + result.push_back(kHexCharLookup[bytes[i] & 0xf]); } return result; } @@ -117,15 +118,14 @@ const char kDeleteComp[] = "|"; // tests for wide replacements. template void SetupReplComp( - void (url_canon::Replacements::*set)(const CHAR*, - const url_parse::Component&), - void (url_canon::Replacements::*clear)(), - url_canon::Replacements* rep, + void (Replacements::*set)(const CHAR*, const Component&), + void (Replacements::*clear)(), + Replacements* rep, const CHAR* str) { if (str && str[0] == kDeleteComp[0]) { (rep->*clear)(); } else if (str) { - (rep->*set)(str, url_parse::Component(0, static_cast(strlen(str)))); + (rep->*set)(str, Component(0, static_cast(strlen(str)))); } } @@ -146,8 +146,8 @@ TEST(URLCanonTest, DoAppendUTF8) { std::string out_str; for (size_t i = 0; i < ARRAYSIZE(utf_cases); i++) { out_str.clear(); - url_canon::StdStringCanonOutput output(&out_str); - url_canon::AppendUTF8Value(utf_cases[i].input, &output); + StdStringCanonOutput output(&out_str); + AppendUTF8Value(utf_cases[i].input, &output); output.Complete(); EXPECT_EQ(utf_cases[i].output, out_str); } @@ -159,10 +159,10 @@ TEST(URLCanonTest, DoAppendUTF8) { #if defined(GTEST_HAS_DEATH_TEST) && defined(NDEBUG) TEST(URLCanonTest, DoAppendUTF8Invalid) { std::string out_str; - url_canon::StdStringCanonOutput output(&out_str); + StdStringCanonOutput output(&out_str); // Invalid code point (too large). ASSERT_DEBUG_DEATH({ - url_canon::AppendUTF8Value(0x110000, &output); + AppendUTF8Value(0x110000, &output); output.Complete(); EXPECT_EQ("", out_str); }, ""); @@ -201,7 +201,7 @@ TEST(URLCanonTest, UTF) { for (size_t i = 0; i < ARRAYSIZE(utf_cases); i++) { if (utf_cases[i].input8) { out_str.clear(); - url_canon::StdStringCanonOutput output(&out_str); + StdStringCanonOutput output(&out_str); int input_len = static_cast(strlen(utf_cases[i].input8)); bool success = true; @@ -215,7 +215,7 @@ TEST(URLCanonTest, UTF) { } if (utf_cases[i].input16) { out_str.clear(); - url_canon::StdStringCanonOutput output(&out_str); + StdStringCanonOutput output(&out_str); base::string16 input_str(WStringToUTF16(utf_cases[i].input16)); int input_len = static_cast(input_str.length()); @@ -264,10 +264,10 @@ TEST(URLCanonTest, ICUCharsetConverter) { for (size_t i = 0; i < ARRAYSIZE(icu_cases); i++) { UConvScoper conv(icu_cases[i].encoding); ASSERT_TRUE(conv.converter() != NULL); - url_canon::ICUCharsetConverter converter(conv.converter()); + ICUCharsetConverter converter(conv.converter()); std::string str; - url_canon::StdStringCanonOutput output(&str); + StdStringCanonOutput output(&str); base::string16 input_str(WStringToUTF16(icu_cases[i].input)); int input_len = static_cast(input_str.length()); @@ -282,14 +282,14 @@ TEST(URLCanonTest, ICUCharsetConverter) { const int static_size = 16; UConvScoper conv("utf-8"); ASSERT_TRUE(conv.converter()); - url_canon::ICUCharsetConverter converter(conv.converter()); + ICUCharsetConverter converter(conv.converter()); for (int i = static_size - 2; i <= static_size + 2; i++) { // Make a string with the appropriate length. base::string16 input; for (int ch = 0; ch < i; ch++) input.push_back('a'); - url_canon::RawCanonOutput output; + RawCanonOutput output; converter.ConvertFromUTF16(input.c_str(), static_cast(input.length()), &output); EXPECT_EQ(input.length(), static_cast(output.length())); @@ -306,27 +306,27 @@ TEST(URLCanonTest, Scheme) { // out the rest of the URL, which is not present in the input. We check, // however, that the output range includes everything but the colon. ComponentCase scheme_cases[] = { - {"http", "http:", url_parse::Component(0, 4), true}, - {"HTTP", "http:", url_parse::Component(0, 4), true}, - {" HTTP ", "%20http%20:", url_parse::Component(0, 10), false}, - {"htt: ", "htt%3A%20:", url_parse::Component(0, 9), false}, - {"\xe4\xbd\xa0\xe5\xa5\xbdhttp", "%E4%BD%A0%E5%A5%BDhttp:", url_parse::Component(0, 22), false}, + {"http", "http:", Component(0, 4), true}, + {"HTTP", "http:", Component(0, 4), true}, + {" HTTP ", "%20http%20:", Component(0, 10), false}, + {"htt: ", "htt%3A%20:", Component(0, 9), false}, + {"\xe4\xbd\xa0\xe5\xa5\xbdhttp", "%E4%BD%A0%E5%A5%BDhttp:", Component(0, 22), false}, // Don't re-escape something already escaped. Note that it will // "canonicalize" the 'A' to 'a', but that's OK. - {"ht%3Atp", "ht%3atp:", url_parse::Component(0, 7), false}, + {"ht%3Atp", "ht%3atp:", Component(0, 7), false}, }; std::string out_str; for (size_t i = 0; i < arraysize(scheme_cases); i++) { int url_len = static_cast(strlen(scheme_cases[i].input)); - url_parse::Component in_comp(0, url_len); - url_parse::Component out_comp; + Component in_comp(0, url_len); + Component out_comp; out_str.clear(); - url_canon::StdStringCanonOutput output1(&out_str); - bool success = url_canon::CanonicalizeScheme(scheme_cases[i].input, - in_comp, &output1, &out_comp); + StdStringCanonOutput output1(&out_str); + bool success = CanonicalizeScheme(scheme_cases[i].input, in_comp, &output1, + &out_comp); output1.Complete(); EXPECT_EQ(scheme_cases[i].expected_success, success); @@ -336,12 +336,12 @@ TEST(URLCanonTest, Scheme) { // Now try the wide version out_str.clear(); - url_canon::StdStringCanonOutput output2(&out_str); + StdStringCanonOutput output2(&out_str); base::string16 wide_input(ConvertUTF8ToUTF16(scheme_cases[i].input)); in_comp.len = static_cast(wide_input.length()); - success = url_canon::CanonicalizeScheme(wide_input.c_str(), in_comp, - &output2, &out_comp); + success = CanonicalizeScheme(wide_input.c_str(), in_comp, &output2, + &out_comp); output2.Complete(); EXPECT_EQ(scheme_cases[i].expected_success, success); @@ -352,12 +352,11 @@ TEST(URLCanonTest, Scheme) { // Test the case where the scheme is declared nonexistant, it should be // converted into an empty scheme. - url_parse::Component out_comp; + Component out_comp; out_str.clear(); - url_canon::StdStringCanonOutput output(&out_str); + StdStringCanonOutput output(&out_str); - EXPECT_TRUE(url_canon::CanonicalizeScheme("", url_parse::Component(0, -1), - &output, &out_comp)); + EXPECT_TRUE(CanonicalizeScheme("", Component(0, -1), &output, &out_comp)); output.Complete(); EXPECT_EQ(std::string(":"), out_str); @@ -368,37 +367,37 @@ TEST(URLCanonTest, Scheme) { TEST(URLCanonTest, Host) { IPAddressCase host_cases[] = { // Basic canonicalization, uppercase should be converted to lowercase. - {"GoOgLe.CoM", L"GoOgLe.CoM", "google.com", url_parse::Component(0, 10), CanonHostInfo::NEUTRAL, -1, ""}, + {"GoOgLe.CoM", L"GoOgLe.CoM", "google.com", Component(0, 10), CanonHostInfo::NEUTRAL, -1, ""}, // Spaces and some other characters should be escaped. - {"Goo%20 goo%7C|.com", L"Goo%20 goo%7C|.com", "goo%20%20goo%7C%7C.com", url_parse::Component(0, 22), CanonHostInfo::NEUTRAL, -1, ""}, + {"Goo%20 goo%7C|.com", L"Goo%20 goo%7C|.com", "goo%20%20goo%7C%7C.com", Component(0, 22), CanonHostInfo::NEUTRAL, -1, ""}, // Exciting different types of spaces! - {NULL, L"GOO\x00a0\x3000goo.com", "goo%20%20goo.com", url_parse::Component(0, 16), CanonHostInfo::NEUTRAL, -1, ""}, + {NULL, L"GOO\x00a0\x3000goo.com", "goo%20%20goo.com", Component(0, 16), CanonHostInfo::NEUTRAL, -1, ""}, // Other types of space (no-break, zero-width, zero-width-no-break) are // name-prepped away to nothing. - {NULL, L"GOO\x200b\x2060\xfeffgoo.com", "googoo.com", url_parse::Component(0, 10), CanonHostInfo::NEUTRAL, -1, ""}, + {NULL, L"GOO\x200b\x2060\xfeffgoo.com", "googoo.com", Component(0, 10), CanonHostInfo::NEUTRAL, -1, ""}, // Ideographic full stop (full-width period for Chinese, etc.) should be // treated as a dot. - {NULL, L"www.foo\x3002" L"bar.com", "www.foo.bar.com", url_parse::Component(0, 15), CanonHostInfo::NEUTRAL, -1, ""}, + {NULL, L"www.foo\x3002" L"bar.com", "www.foo.bar.com", Component(0, 15), CanonHostInfo::NEUTRAL, -1, ""}, // Invalid unicode characters should fail... // ...In wide input, ICU will barf and we'll end up with the input as // escaped UTF-8 (the invalid character should be replaced with the // replacement character). - {"\xef\xb7\x90zyx.com", L"\xfdd0zyx.com", "%EF%BF%BDzyx.com", url_parse::Component(0, 16), CanonHostInfo::BROKEN, -1, ""}, + {"\xef\xb7\x90zyx.com", L"\xfdd0zyx.com", "%EF%BF%BDzyx.com", Component(0, 16), CanonHostInfo::BROKEN, -1, ""}, // ...This is the same as previous but with with escaped. - {"%ef%b7%90zyx.com", L"%ef%b7%90zyx.com", "%EF%BF%BDzyx.com", url_parse::Component(0, 16), CanonHostInfo::BROKEN, -1, ""}, + {"%ef%b7%90zyx.com", L"%ef%b7%90zyx.com", "%EF%BF%BDzyx.com", Component(0, 16), CanonHostInfo::BROKEN, -1, ""}, // Test name prepping, fullwidth input should be converted to ASCII and NOT // IDN-ized. This is "Go" in fullwidth UTF-8/UTF-16. - {"\xef\xbc\xa7\xef\xbd\x8f.com", L"\xff27\xff4f.com", "go.com", url_parse::Component(0, 6), CanonHostInfo::NEUTRAL, -1, ""}, + {"\xef\xbc\xa7\xef\xbd\x8f.com", L"\xff27\xff4f.com", "go.com", Component(0, 6), CanonHostInfo::NEUTRAL, -1, ""}, // Test that fullwidth escaped values are properly name-prepped, // then converted or rejected. // ...%41 in fullwidth = 'A' (also as escaped UTF-8 input) - {"\xef\xbc\x85\xef\xbc\x94\xef\xbc\x91.com", L"\xff05\xff14\xff11.com", "a.com", url_parse::Component(0, 5), CanonHostInfo::NEUTRAL, -1, ""}, - {"%ef%bc%85%ef%bc%94%ef%bc%91.com", L"%ef%bc%85%ef%bc%94%ef%bc%91.com", "a.com", url_parse::Component(0, 5), CanonHostInfo::NEUTRAL, -1, ""}, + {"\xef\xbc\x85\xef\xbc\x94\xef\xbc\x91.com", L"\xff05\xff14\xff11.com", "a.com", Component(0, 5), CanonHostInfo::NEUTRAL, -1, ""}, + {"%ef%bc%85%ef%bc%94%ef%bc%91.com", L"%ef%bc%85%ef%bc%94%ef%bc%91.com", "a.com", Component(0, 5), CanonHostInfo::NEUTRAL, -1, ""}, // ...%00 in fullwidth should fail (also as escaped UTF-8 input) - {"\xef\xbc\x85\xef\xbc\x90\xef\xbc\x90.com", L"\xff05\xff10\xff10.com", "%00.com", url_parse::Component(0, 7), CanonHostInfo::BROKEN, -1, ""}, - {"%ef%bc%85%ef%bc%90%ef%bc%90.com", L"%ef%bc%85%ef%bc%90%ef%bc%90.com", "%00.com", url_parse::Component(0, 7), CanonHostInfo::BROKEN, -1, ""}, + {"\xef\xbc\x85\xef\xbc\x90\xef\xbc\x90.com", L"\xff05\xff10\xff10.com", "%00.com", Component(0, 7), CanonHostInfo::BROKEN, -1, ""}, + {"%ef%bc%85%ef%bc%90%ef%bc%90.com", L"%ef%bc%85%ef%bc%90%ef%bc%90.com", "%00.com", Component(0, 7), CanonHostInfo::BROKEN, -1, ""}, // Basic IDN support, UTF-8 and UTF-16 input should be converted to IDN - {"\xe4\xbd\xa0\xe5\xa5\xbd\xe4\xbd\xa0\xe5\xa5\xbd", L"\x4f60\x597d\x4f60\x597d", "xn--6qqa088eba", url_parse::Component(0, 14), CanonHostInfo::NEUTRAL, -1, ""}, + {"\xe4\xbd\xa0\xe5\xa5\xbd\xe4\xbd\xa0\xe5\xa5\xbd", L"\x4f60\x597d\x4f60\x597d", "xn--6qqa088eba", Component(0, 14), CanonHostInfo::NEUTRAL, -1, ""}, // See http://unicode.org/cldr/utility/idna.jsp for other // examples/experiments and http://goo.gl/7yG11o // for the full list of characters handled differently by @@ -409,153 +408,153 @@ TEST(URLCanonTest, Host) { // Sharp-s is mapped to 'ss' in UTS 46 and IDNA 2003. // Otherwise, it'd be "xn--fuball-cta.de". {"fu\xc3\x9f" "ball.de", L"fu\x00df" L"ball.de", "fussball.de", - url_parse::Component(0, 11), CanonHostInfo::NEUTRAL, -1, ""}, + Component(0, 11), CanonHostInfo::NEUTRAL, -1, ""}, // Final-sigma (U+03C3) is mapped to regular sigma (U+03C2). // Otherwise, it'd be "xn--wxaijb9b". {"\xcf\x83\xcf\x8c\xce\xbb\xce\xbf\xcf\x82", L"\x3c3\x3cc\x3bb\x3bf\x3c2", - "xn--wxaikc6b", url_parse::Component(0, 12), + "xn--wxaikc6b", Component(0, 12), CanonHostInfo::NEUTRAL, -1, ""}, // ZWNJ (U+200C) and ZWJ (U+200D) are mapped away in UTS 46 transitional // handling as well as in IDNA 2003. {"a\xe2\x80\x8c" "b\xe2\x80\x8d" "c", L"a\x200c" L"b\x200d" L"c", "abc", - url_parse::Component(0, 3), CanonHostInfo::NEUTRAL, -1, ""}, + Component(0, 3), CanonHostInfo::NEUTRAL, -1, ""}, // ZWJ between Devanagari characters is still mapped away in UTS 46 // transitional handling. IDNA 2008 would give xn--11bo0mv54g. {"\xe0\xa4\x95\xe0\xa5\x8d\xe2\x80\x8d\xe0\xa4\x9c", L"\x915\x94d\x200d\x91c", "xn--11bo0m", - url_parse::Component(0, 10), CanonHostInfo::NEUTRAL, -1, ""}, + Component(0, 10), CanonHostInfo::NEUTRAL, -1, ""}, // Fullwidth exclamation mark is disallowed. UTS 46, table 4, row (b) // However, we do allow this at the moment because we don't use // STD3 rules and canonicalize full-width ASCII to ASCII. {"wow\xef\xbc\x81", L"wow\xff01", "wow%21", - url_parse::Component(0, 6), CanonHostInfo::NEUTRAL, -1, ""}, + Component(0, 6), CanonHostInfo::NEUTRAL, -1, ""}, // U+2132 (turned capital F) is disallowed. UTS 46, table 4, row (c) // Allowed in IDNA 2003, but the mapping changed after Unicode 3.2 {"\xe2\x84\xb2oo", L"\x2132oo", "%E2%84%B2oo", - url_parse::Component(0, 11), CanonHostInfo::BROKEN, -1, ""}, + Component(0, 11), CanonHostInfo::BROKEN, -1, ""}, // U+2F868 (CJK Comp) is disallowed. UTS 46, table 4, row (d) // Allowed in IDNA 2003, but the mapping changed after Unicode 3.2 {"\xf0\xaf\xa1\xa8\xe5\xa7\xbb.cn", L"\xd87e\xdc68\x59fb.cn", "%F0%AF%A1%A8%E5%A7%BB.cn", - url_parse::Component(0, 24), CanonHostInfo::BROKEN, -1, ""}, + Component(0, 24), CanonHostInfo::BROKEN, -1, ""}, // Maps uppercase letters to lower case letters. UTS 46 table 4 row (e) {"M\xc3\x9cNCHEN", L"M\xdcNCHEN", "xn--mnchen-3ya", - url_parse::Component(0, 14), CanonHostInfo::NEUTRAL, -1, ""}, + Component(0, 14), CanonHostInfo::NEUTRAL, -1, ""}, // Symbol/punctuations are allowed in IDNA 2003/UTS46. // Not allowed in IDNA 2008. UTS 46 table 4 row (f). {"\xe2\x99\xa5ny.us", L"\x2665ny.us", "xn--ny-s0x.us", - url_parse::Component(0, 13), CanonHostInfo::NEUTRAL, -1, ""}, + Component(0, 13), CanonHostInfo::NEUTRAL, -1, ""}, // U+11013 is new in Unicode 6.0 and is allowed. UTS 46 table 4, row (h) // We used to allow it because we passed through unassigned code points. {"\xf0\x91\x80\x93.com", L"\xd804\xdc13.com", "xn--n00d.com", - url_parse::Component(0, 12), CanonHostInfo::NEUTRAL, -1, ""}, + Component(0, 12), CanonHostInfo::NEUTRAL, -1, ""}, // U+0602 is disallowed in UTS46/IDNA 2008. UTS 46 table 4, row(i) // Used to be allowed in INDA 2003. {"\xd8\x82.eg", L"\x602.eg", "%D8%82.eg", - url_parse::Component(0, 9), CanonHostInfo::BROKEN, -1, ""}, + Component(0, 9), CanonHostInfo::BROKEN, -1, ""}, // U+20B7 is new in Unicode 5.2 (not a part of IDNA 2003 based // on Unicode 3.2). We did allow it in the past because we let unassigned // code point pass. We continue to allow it even though it's a // "punctuation and symbol" blocked in IDNA 2008. // UTS 46 table 4, row (j) {"\xe2\x82\xb7.com", L"\x20b7.com", "xn--wzg.com", - url_parse::Component(0, 11), CanonHostInfo::NEUTRAL, -1, ""}, + Component(0, 11), CanonHostInfo::NEUTRAL, -1, ""}, // Maps uppercase letters to lower case letters. // In IDNA 2003, it's allowed without case-folding // ( xn--bc-7cb.com ) because it's not defined in Unicode 3.2 // (added in Unicode 4.1). UTS 46 table 4 row (k) {"bc\xc8\xba.com", L"bc\x23a.com", "xn--bc-is1a.com", - url_parse::Component(0, 15), CanonHostInfo::NEUTRAL, -1, ""}, + Component(0, 15), CanonHostInfo::NEUTRAL, -1, ""}, // BiDi check test // "Divehi" in Divehi (Thaana script) ends with BidiClass=NSM. // Disallowed in IDNA 2003 but now allowed in UTS 46/IDNA 2008. {"\xde\x8b\xde\xa8\xde\x88\xde\xac\xde\x80\xde\xa8", L"\x78b\x7a8\x788\x7ac\x780\x7a8", "xn--hqbpi0jcw", - url_parse::Component(0, 13), CanonHostInfo::NEUTRAL, -1, ""}, + Component(0, 13), CanonHostInfo::NEUTRAL, -1, ""}, // Disallowed in both IDNA 2003 and 2008 with BiDi check. // Labels starting with a RTL character cannot end with a LTR character. {"\xd8\xac\xd8\xa7\xd8\xb1xyz", L"\x62c\x627\x631xyz", - "%D8%AC%D8%A7%D8%B1xyz", url_parse::Component(0, 21), + "%D8%AC%D8%A7%D8%B1xyz", Component(0, 21), CanonHostInfo::BROKEN, -1, ""}, // Labels starting with a RTL character can end with BC=EN (European // number). Disallowed in IDNA 2003 but now allowed. {"\xd8\xac\xd8\xa7\xd8\xb1" "2", L"\x62c\x627\x631" L"2", - "xn--2-ymcov", url_parse::Component(0, 11), + "xn--2-ymcov", Component(0, 11), CanonHostInfo::NEUTRAL, -1, ""}, // Labels starting with a RTL character cannot have "L" characters // even if it ends with an BC=EN. Disallowed in both IDNA 2003/2008. {"\xd8\xac\xd8\xa7\xd8\xb1xy2", L"\x62c\x627\x631xy2", - "%D8%AC%D8%A7%D8%B1xy2", url_parse::Component(0, 21), + "%D8%AC%D8%A7%D8%B1xy2", Component(0, 21), CanonHostInfo::BROKEN, -1, ""}, // Labels starting with a RTL character can end with BC=AN (Arabic number) // Disallowed in IDNA 2003, but now allowed. {"\xd8\xac\xd8\xa7\xd8\xb1\xd9\xa2", L"\x62c\x627\x631\x662", - "xn--mgbjq0r", url_parse::Component(0, 11), + "xn--mgbjq0r", Component(0, 11), CanonHostInfo::NEUTRAL, -1, ""}, // Labels starting with a RTL character cannot have "L" characters // even if it ends with an BC=AN (Arabic number). // Disallowed in both IDNA 2003/2008. {"\xd8\xac\xd8\xa7\xd8\xb1xy\xd9\xa2", L"\x62c\x627\x631xy\x662", - "%D8%AC%D8%A7%D8%B1xy%D9%A2", url_parse::Component(0, 26), + "%D8%AC%D8%A7%D8%B1xy%D9%A2", Component(0, 26), CanonHostInfo::BROKEN, -1, ""}, // Labels starting with a RTL character cannot mix BC=EN and BC=AN {"\xd8\xac\xd8\xa7\xd8\xb1xy2\xd9\xa2", L"\x62c\x627\x631xy2\x662", - "%D8%AC%D8%A7%D8%B1xy2%D9%A2", url_parse::Component(0, 27), + "%D8%AC%D8%A7%D8%B1xy2%D9%A2", Component(0, 27), CanonHostInfo::BROKEN, -1, ""}, // As of Unicode 6.2, U+20CF is not assigned. We do not allow it. {"\xe2\x83\x8f.com", L"\x20cf.com", "%E2%83%8F.com", - url_parse::Component(0, 13), CanonHostInfo::BROKEN, -1, ""}, + Component(0, 13), CanonHostInfo::BROKEN, -1, ""}, // U+0080 is not allowed. {"\xc2\x80.com", L"\x80.com", "%C2%80.com", - url_parse::Component(0, 10), CanonHostInfo::BROKEN, -1, ""}, + Component(0, 10), CanonHostInfo::BROKEN, -1, ""}, // Mixed UTF-8 and escaped UTF-8 (narrow case) and UTF-16 and escaped // Mixed UTF-8 and escaped UTF-8 (narrow case) and UTF-16 and escaped // UTF-8 (wide case). The output should be equivalent to the true wide // character input above). {"%E4%BD%A0%E5%A5%BD\xe4\xbd\xa0\xe5\xa5\xbd", L"%E4%BD%A0%E5%A5%BD\x4f60\x597d", "xn--6qqa088eba", - url_parse::Component(0, 14), CanonHostInfo::NEUTRAL, -1, ""}, + Component(0, 14), CanonHostInfo::NEUTRAL, -1, ""}, // Invalid escaped characters should fail and the percents should be // escaped. - {"%zz%66%a", L"%zz%66%a", "%25zzf%25a", url_parse::Component(0, 10), + {"%zz%66%a", L"%zz%66%a", "%25zzf%25a", Component(0, 10), CanonHostInfo::BROKEN, -1, ""}, // If we get an invalid character that has been escaped. - {"%25", L"%25", "%25", url_parse::Component(0, 3), + {"%25", L"%25", "%25", Component(0, 3), CanonHostInfo::BROKEN, -1, ""}, - {"hello%00", L"hello%00", "hello%00", url_parse::Component(0, 8), + {"hello%00", L"hello%00", "hello%00", Component(0, 8), CanonHostInfo::BROKEN, -1, ""}, // Escaped numbers should be treated like IP addresses if they are. {"%30%78%63%30%2e%30%32%35%30.01", L"%30%78%63%30%2e%30%32%35%30.01", - "192.168.0.1", url_parse::Component(0, 11), CanonHostInfo::IPV4, 3, + "192.168.0.1", Component(0, 11), CanonHostInfo::IPV4, 3, "C0A80001"}, {"%30%78%63%30%2e%30%32%35%30.01%2e", L"%30%78%63%30%2e%30%32%35%30.01%2e", - "192.168.0.1", url_parse::Component(0, 11), CanonHostInfo::IPV4, 3, + "192.168.0.1", Component(0, 11), CanonHostInfo::IPV4, 3, "C0A80001"}, // Invalid escaping should trigger the regular host error handling. - {"%3g%78%63%30%2e%30%32%35%30%2E.01", L"%3g%78%63%30%2e%30%32%35%30%2E.01", "%253gxc0.0250..01", url_parse::Component(0, 17), CanonHostInfo::BROKEN, -1, ""}, + {"%3g%78%63%30%2e%30%32%35%30%2E.01", L"%3g%78%63%30%2e%30%32%35%30%2E.01", "%253gxc0.0250..01", Component(0, 17), CanonHostInfo::BROKEN, -1, ""}, // Something that isn't exactly an IP should get treated as a host and // spaces escaped. - {"192.168.0.1 hello", L"192.168.0.1 hello", "192.168.0.1%20hello", url_parse::Component(0, 19), CanonHostInfo::NEUTRAL, -1, ""}, + {"192.168.0.1 hello", L"192.168.0.1 hello", "192.168.0.1%20hello", Component(0, 19), CanonHostInfo::NEUTRAL, -1, ""}, // Fullwidth and escaped UTF-8 fullwidth should still be treated as IP. // These are "0Xc0.0250.01" in fullwidth. - {"\xef\xbc\x90%Ef%bc\xb8%ef%Bd%83\xef\xbc\x90%EF%BC%8E\xef\xbc\x90\xef\xbc\x92\xef\xbc\x95\xef\xbc\x90\xef\xbc%8E\xef\xbc\x90\xef\xbc\x91", L"\xff10\xff38\xff43\xff10\xff0e\xff10\xff12\xff15\xff10\xff0e\xff10\xff11", "192.168.0.1", url_parse::Component(0, 11), CanonHostInfo::IPV4, 3, "C0A80001"}, + {"\xef\xbc\x90%Ef%bc\xb8%ef%Bd%83\xef\xbc\x90%EF%BC%8E\xef\xbc\x90\xef\xbc\x92\xef\xbc\x95\xef\xbc\x90\xef\xbc%8E\xef\xbc\x90\xef\xbc\x91", L"\xff10\xff38\xff43\xff10\xff0e\xff10\xff12\xff15\xff10\xff0e\xff10\xff11", "192.168.0.1", Component(0, 11), CanonHostInfo::IPV4, 3, "C0A80001"}, // Broken IP addresses get marked as such. - {"192.168.0.257", L"192.168.0.257", "192.168.0.257", url_parse::Component(0, 13), CanonHostInfo::BROKEN, -1, ""}, - {"[google.com]", L"[google.com]", "[google.com]", url_parse::Component(0, 12), CanonHostInfo::BROKEN, -1, ""}, + {"192.168.0.257", L"192.168.0.257", "192.168.0.257", Component(0, 13), CanonHostInfo::BROKEN, -1, ""}, + {"[google.com]", L"[google.com]", "[google.com]", Component(0, 12), CanonHostInfo::BROKEN, -1, ""}, // Cyrillic letter followed by '(' should return punycode for '(' escaped // before punycode string was created. I.e. // if '(' is escaped after punycode is created we would get xn--%28-8tb // (incorrect). - {"\xd1\x82(", L"\x0442(", "xn--%28-7ed", url_parse::Component(0, 11), + {"\xd1\x82(", L"\x0442(", "xn--%28-7ed", Component(0, 11), CanonHostInfo::NEUTRAL, -1, ""}, // Address with all hexidecimal characters with leading number of 1<<32 // or greater and should return NEUTRAL rather than BROKEN if not all // components are numbers. - {"12345678912345.de", L"12345678912345.de", "12345678912345.de", url_parse::Component(0, 17), CanonHostInfo::NEUTRAL, -1, ""}, - {"1.12345678912345.de", L"1.12345678912345.de", "1.12345678912345.de", url_parse::Component(0, 19), CanonHostInfo::NEUTRAL, -1, ""}, - {"12345678912345.12345678912345.de", L"12345678912345.12345678912345.de", "12345678912345.12345678912345.de", url_parse::Component(0, 32), CanonHostInfo::NEUTRAL, -1, ""}, - {"1.2.0xB3A73CE5B59.de", L"1.2.0xB3A73CE5B59.de", "1.2.0xb3a73ce5b59.de", url_parse::Component(0, 20), CanonHostInfo::NEUTRAL, -1, ""}, - {"12345678912345.0xde", L"12345678912345.0xde", "12345678912345.0xde", url_parse::Component(0, 19), CanonHostInfo::BROKEN, -1, ""}, + {"12345678912345.de", L"12345678912345.de", "12345678912345.de", Component(0, 17), CanonHostInfo::NEUTRAL, -1, ""}, + {"1.12345678912345.de", L"1.12345678912345.de", "1.12345678912345.de", Component(0, 19), CanonHostInfo::NEUTRAL, -1, ""}, + {"12345678912345.12345678912345.de", L"12345678912345.12345678912345.de", "12345678912345.12345678912345.de", Component(0, 32), CanonHostInfo::NEUTRAL, -1, ""}, + {"1.2.0xB3A73CE5B59.de", L"1.2.0xB3A73CE5B59.de", "1.2.0xb3a73ce5b59.de", Component(0, 20), CanonHostInfo::NEUTRAL, -1, ""}, + {"12345678912345.0xde", L"12345678912345.0xde", "12345678912345.0xde", Component(0, 19), CanonHostInfo::BROKEN, -1, ""}, }; // CanonicalizeHost() non-verbose. @@ -564,14 +563,14 @@ TEST(URLCanonTest, Host) { // Narrow version. if (host_cases[i].input8) { int host_len = static_cast(strlen(host_cases[i].input8)); - url_parse::Component in_comp(0, host_len); - url_parse::Component out_comp; + Component in_comp(0, host_len); + Component out_comp; out_str.clear(); - url_canon::StdStringCanonOutput output(&out_str); + StdStringCanonOutput output(&out_str); - bool success = url_canon::CanonicalizeHost(host_cases[i].input8, in_comp, - &output, &out_comp); + bool success = CanonicalizeHost(host_cases[i].input8, in_comp, &output, + &out_comp); output.Complete(); EXPECT_EQ(host_cases[i].expected_family != CanonHostInfo::BROKEN, @@ -588,14 +587,14 @@ TEST(URLCanonTest, Host) { if (host_cases[i].input16) { base::string16 input16(WStringToUTF16(host_cases[i].input16)); int host_len = static_cast(input16.length()); - url_parse::Component in_comp(0, host_len); - url_parse::Component out_comp; + Component in_comp(0, host_len); + Component out_comp; out_str.clear(); - url_canon::StdStringCanonOutput output(&out_str); + StdStringCanonOutput output(&out_str); - bool success = url_canon::CanonicalizeHost(input16.c_str(), in_comp, - &output, &out_comp); + bool success = CanonicalizeHost(input16.c_str(), in_comp, &output, + &out_comp); output.Complete(); EXPECT_EQ(host_cases[i].expected_family != CanonHostInfo::BROKEN, @@ -611,14 +610,14 @@ TEST(URLCanonTest, Host) { // Narrow version. if (host_cases[i].input8) { int host_len = static_cast(strlen(host_cases[i].input8)); - url_parse::Component in_comp(0, host_len); + Component in_comp(0, host_len); out_str.clear(); - url_canon::StdStringCanonOutput output(&out_str); + StdStringCanonOutput output(&out_str); CanonHostInfo host_info; - url_canon::CanonicalizeHostVerbose(host_cases[i].input8, in_comp, - &output, &host_info); + CanonicalizeHostVerbose(host_cases[i].input8, in_comp, &output, + &host_info); output.Complete(); EXPECT_EQ(host_cases[i].expected_family, host_info.family); @@ -638,14 +637,13 @@ TEST(URLCanonTest, Host) { if (host_cases[i].input16) { base::string16 input16(WStringToUTF16(host_cases[i].input16)); int host_len = static_cast(input16.length()); - url_parse::Component in_comp(0, host_len); + Component in_comp(0, host_len); out_str.clear(); - url_canon::StdStringCanonOutput output(&out_str); + StdStringCanonOutput output(&out_str); CanonHostInfo host_info; - url_canon::CanonicalizeHostVerbose(input16.c_str(), in_comp, - &output, &host_info); + CanonicalizeHostVerbose(input16.c_str(), in_comp, &output, &host_info); output.Complete(); EXPECT_EQ(host_cases[i].expected_family, host_info.family); @@ -666,87 +664,85 @@ TEST(URLCanonTest, Host) { TEST(URLCanonTest, IPv4) { IPAddressCase cases[] = { // Empty is not an IP address. - {"", L"", "", url_parse::Component(), CanonHostInfo::NEUTRAL, -1, ""}, - {".", L".", "", url_parse::Component(), CanonHostInfo::NEUTRAL, -1, ""}, + {"", L"", "", Component(), CanonHostInfo::NEUTRAL, -1, ""}, + {".", L".", "", Component(), CanonHostInfo::NEUTRAL, -1, ""}, // Regular IP addresses in different bases. - {"192.168.0.1", L"192.168.0.1", "192.168.0.1", url_parse::Component(0, 11), CanonHostInfo::IPV4, 4, "C0A80001"}, - {"0300.0250.00.01", L"0300.0250.00.01", "192.168.0.1", url_parse::Component(0, 11), CanonHostInfo::IPV4, 4, "C0A80001"}, - {"0xC0.0Xa8.0x0.0x1", L"0xC0.0Xa8.0x0.0x1", "192.168.0.1", url_parse::Component(0, 11), CanonHostInfo::IPV4, 4, "C0A80001"}, + {"192.168.0.1", L"192.168.0.1", "192.168.0.1", Component(0, 11), CanonHostInfo::IPV4, 4, "C0A80001"}, + {"0300.0250.00.01", L"0300.0250.00.01", "192.168.0.1", Component(0, 11), CanonHostInfo::IPV4, 4, "C0A80001"}, + {"0xC0.0Xa8.0x0.0x1", L"0xC0.0Xa8.0x0.0x1", "192.168.0.1", Component(0, 11), CanonHostInfo::IPV4, 4, "C0A80001"}, // Non-IP addresses due to invalid characters. - {"192.168.9.com", L"192.168.9.com", "", url_parse::Component(), CanonHostInfo::NEUTRAL, -1, ""}, + {"192.168.9.com", L"192.168.9.com", "", Component(), CanonHostInfo::NEUTRAL, -1, ""}, // Invalid characters for the base should be rejected. - {"19a.168.0.1", L"19a.168.0.1", "", url_parse::Component(), CanonHostInfo::NEUTRAL, -1, ""}, - {"0308.0250.00.01", L"0308.0250.00.01", "", url_parse::Component(), CanonHostInfo::NEUTRAL, -1, ""}, - {"0xCG.0xA8.0x0.0x1", L"0xCG.0xA8.0x0.0x1", "", url_parse::Component(), CanonHostInfo::NEUTRAL, -1, ""}, + {"19a.168.0.1", L"19a.168.0.1", "", Component(), CanonHostInfo::NEUTRAL, -1, ""}, + {"0308.0250.00.01", L"0308.0250.00.01", "", Component(), CanonHostInfo::NEUTRAL, -1, ""}, + {"0xCG.0xA8.0x0.0x1", L"0xCG.0xA8.0x0.0x1", "", Component(), CanonHostInfo::NEUTRAL, -1, ""}, // If there are not enough components, the last one should fill them out. - {"192", L"192", "0.0.0.192", url_parse::Component(0, 9), CanonHostInfo::IPV4, 1, "000000C0"}, - {"0xC0a80001", L"0xC0a80001", "192.168.0.1", url_parse::Component(0, 11), CanonHostInfo::IPV4, 1, "C0A80001"}, - {"030052000001", L"030052000001", "192.168.0.1", url_parse::Component(0, 11), CanonHostInfo::IPV4, 1, "C0A80001"}, - {"000030052000001", L"000030052000001", "192.168.0.1", url_parse::Component(0, 11), CanonHostInfo::IPV4, 1, "C0A80001"}, - {"192.168", L"192.168", "192.0.0.168", url_parse::Component(0, 11), CanonHostInfo::IPV4, 2, "C00000A8"}, - {"192.0x00A80001", L"192.0x000A80001", "192.168.0.1", url_parse::Component(0, 11), CanonHostInfo::IPV4, 2, "C0A80001"}, - {"0xc0.052000001", L"0xc0.052000001", "192.168.0.1", url_parse::Component(0, 11), CanonHostInfo::IPV4, 2, "C0A80001"}, - {"192.168.1", L"192.168.1", "192.168.0.1", url_parse::Component(0, 11), CanonHostInfo::IPV4, 3, "C0A80001"}, + {"192", L"192", "0.0.0.192", Component(0, 9), CanonHostInfo::IPV4, 1, "000000C0"}, + {"0xC0a80001", L"0xC0a80001", "192.168.0.1", Component(0, 11), CanonHostInfo::IPV4, 1, "C0A80001"}, + {"030052000001", L"030052000001", "192.168.0.1", Component(0, 11), CanonHostInfo::IPV4, 1, "C0A80001"}, + {"000030052000001", L"000030052000001", "192.168.0.1", Component(0, 11), CanonHostInfo::IPV4, 1, "C0A80001"}, + {"192.168", L"192.168", "192.0.0.168", Component(0, 11), CanonHostInfo::IPV4, 2, "C00000A8"}, + {"192.0x00A80001", L"192.0x000A80001", "192.168.0.1", Component(0, 11), CanonHostInfo::IPV4, 2, "C0A80001"}, + {"0xc0.052000001", L"0xc0.052000001", "192.168.0.1", Component(0, 11), CanonHostInfo::IPV4, 2, "C0A80001"}, + {"192.168.1", L"192.168.1", "192.168.0.1", Component(0, 11), CanonHostInfo::IPV4, 3, "C0A80001"}, // Too many components means not an IP address. - {"192.168.0.0.1", L"192.168.0.0.1", "", url_parse::Component(), CanonHostInfo::NEUTRAL, -1, ""}, + {"192.168.0.0.1", L"192.168.0.0.1", "", Component(), CanonHostInfo::NEUTRAL, -1, ""}, // We allow a single trailing dot. - {"192.168.0.1.", L"192.168.0.1.", "192.168.0.1", url_parse::Component(0, 11), CanonHostInfo::IPV4, 4, "C0A80001"}, - {"192.168.0.1. hello", L"192.168.0.1. hello", "", url_parse::Component(), CanonHostInfo::NEUTRAL, -1, ""}, - {"192.168.0.1..", L"192.168.0.1..", "", url_parse::Component(), CanonHostInfo::NEUTRAL, -1, ""}, + {"192.168.0.1.", L"192.168.0.1.", "192.168.0.1", Component(0, 11), CanonHostInfo::IPV4, 4, "C0A80001"}, + {"192.168.0.1. hello", L"192.168.0.1. hello", "", Component(), CanonHostInfo::NEUTRAL, -1, ""}, + {"192.168.0.1..", L"192.168.0.1..", "", Component(), CanonHostInfo::NEUTRAL, -1, ""}, // Two dots in a row means not an IP address. - {"192.168..1", L"192.168..1", "", url_parse::Component(), CanonHostInfo::NEUTRAL, -1, ""}, + {"192.168..1", L"192.168..1", "", Component(), CanonHostInfo::NEUTRAL, -1, ""}, // Any numerical overflow should be marked as BROKEN. - {"0x100.0", L"0x100.0", "", url_parse::Component(), CanonHostInfo::BROKEN, -1, ""}, - {"0x100.0.0", L"0x100.0.0", "", url_parse::Component(), CanonHostInfo::BROKEN, -1, ""}, - {"0x100.0.0.0", L"0x100.0.0.0", "", url_parse::Component(), CanonHostInfo::BROKEN, -1, ""}, - {"0.0x100.0.0", L"0.0x100.0.0", "", url_parse::Component(), CanonHostInfo::BROKEN, -1, ""}, - {"0.0.0x100.0", L"0.0.0x100.0", "", url_parse::Component(), CanonHostInfo::BROKEN, -1, ""}, - {"0.0.0.0x100", L"0.0.0.0x100", "", url_parse::Component(), CanonHostInfo::BROKEN, -1, ""}, - {"0.0.0x10000", L"0.0.0x10000", "", url_parse::Component(), CanonHostInfo::BROKEN, -1, ""}, - {"0.0x1000000", L"0.0x1000000", "", url_parse::Component(), CanonHostInfo::BROKEN, -1, ""}, - {"0x100000000", L"0x100000000", "", url_parse::Component(), CanonHostInfo::BROKEN, -1, ""}, + {"0x100.0", L"0x100.0", "", Component(), CanonHostInfo::BROKEN, -1, ""}, + {"0x100.0.0", L"0x100.0.0", "", Component(), CanonHostInfo::BROKEN, -1, ""}, + {"0x100.0.0.0", L"0x100.0.0.0", "", Component(), CanonHostInfo::BROKEN, -1, ""}, + {"0.0x100.0.0", L"0.0x100.0.0", "", Component(), CanonHostInfo::BROKEN, -1, ""}, + {"0.0.0x100.0", L"0.0.0x100.0", "", Component(), CanonHostInfo::BROKEN, -1, ""}, + {"0.0.0.0x100", L"0.0.0.0x100", "", Component(), CanonHostInfo::BROKEN, -1, ""}, + {"0.0.0x10000", L"0.0.0x10000", "", Component(), CanonHostInfo::BROKEN, -1, ""}, + {"0.0x1000000", L"0.0x1000000", "", Component(), CanonHostInfo::BROKEN, -1, ""}, + {"0x100000000", L"0x100000000", "", Component(), CanonHostInfo::BROKEN, -1, ""}, // Repeat the previous tests, minus 1, to verify boundaries. - {"0xFF.0", L"0xFF.0", "255.0.0.0", url_parse::Component(0, 9), CanonHostInfo::IPV4, 2, "FF000000"}, - {"0xFF.0.0", L"0xFF.0.0", "255.0.0.0", url_parse::Component(0, 9), CanonHostInfo::IPV4, 3, "FF000000"}, - {"0xFF.0.0.0", L"0xFF.0.0.0", "255.0.0.0", url_parse::Component(0, 9), CanonHostInfo::IPV4, 4, "FF000000"}, - {"0.0xFF.0.0", L"0.0xFF.0.0", "0.255.0.0", url_parse::Component(0, 9), CanonHostInfo::IPV4, 4, "00FF0000"}, - {"0.0.0xFF.0", L"0.0.0xFF.0", "0.0.255.0", url_parse::Component(0, 9), CanonHostInfo::IPV4, 4, "0000FF00"}, - {"0.0.0.0xFF", L"0.0.0.0xFF", "0.0.0.255", url_parse::Component(0, 9), CanonHostInfo::IPV4, 4, "000000FF"}, - {"0.0.0xFFFF", L"0.0.0xFFFF", "0.0.255.255", url_parse::Component(0, 11), CanonHostInfo::IPV4, 3, "0000FFFF"}, - {"0.0xFFFFFF", L"0.0xFFFFFF", "0.255.255.255", url_parse::Component(0, 13), CanonHostInfo::IPV4, 2, "00FFFFFF"}, - {"0xFFFFFFFF", L"0xFFFFFFFF", "255.255.255.255", url_parse::Component(0, 15), CanonHostInfo::IPV4, 1, "FFFFFFFF"}, + {"0xFF.0", L"0xFF.0", "255.0.0.0", Component(0, 9), CanonHostInfo::IPV4, 2, "FF000000"}, + {"0xFF.0.0", L"0xFF.0.0", "255.0.0.0", Component(0, 9), CanonHostInfo::IPV4, 3, "FF000000"}, + {"0xFF.0.0.0", L"0xFF.0.0.0", "255.0.0.0", Component(0, 9), CanonHostInfo::IPV4, 4, "FF000000"}, + {"0.0xFF.0.0", L"0.0xFF.0.0", "0.255.0.0", Component(0, 9), CanonHostInfo::IPV4, 4, "00FF0000"}, + {"0.0.0xFF.0", L"0.0.0xFF.0", "0.0.255.0", Component(0, 9), CanonHostInfo::IPV4, 4, "0000FF00"}, + {"0.0.0.0xFF", L"0.0.0.0xFF", "0.0.0.255", Component(0, 9), CanonHostInfo::IPV4, 4, "000000FF"}, + {"0.0.0xFFFF", L"0.0.0xFFFF", "0.0.255.255", Component(0, 11), CanonHostInfo::IPV4, 3, "0000FFFF"}, + {"0.0xFFFFFF", L"0.0xFFFFFF", "0.255.255.255", Component(0, 13), CanonHostInfo::IPV4, 2, "00FFFFFF"}, + {"0xFFFFFFFF", L"0xFFFFFFFF", "255.255.255.255", Component(0, 15), CanonHostInfo::IPV4, 1, "FFFFFFFF"}, // Old trunctations tests. They're all "BROKEN" now. - {"276.256.0xf1a2.077777", L"276.256.0xf1a2.077777", "", url_parse::Component(), CanonHostInfo::BROKEN, -1, ""}, - {"192.168.0.257", L"192.168.0.257", "", url_parse::Component(), CanonHostInfo::BROKEN, -1, ""}, - {"192.168.0xa20001", L"192.168.0xa20001", "", url_parse::Component(), CanonHostInfo::BROKEN, -1, ""}, - {"192.015052000001", L"192.015052000001", "", url_parse::Component(), CanonHostInfo::BROKEN, -1, ""}, - {"0X12C0a80001", L"0X12C0a80001", "", url_parse::Component(), CanonHostInfo::BROKEN, -1, ""}, - {"276.1.2", L"276.1.2", "", url_parse::Component(), CanonHostInfo::BROKEN, -1, ""}, + {"276.256.0xf1a2.077777", L"276.256.0xf1a2.077777", "", Component(), CanonHostInfo::BROKEN, -1, ""}, + {"192.168.0.257", L"192.168.0.257", "", Component(), CanonHostInfo::BROKEN, -1, ""}, + {"192.168.0xa20001", L"192.168.0xa20001", "", Component(), CanonHostInfo::BROKEN, -1, ""}, + {"192.015052000001", L"192.015052000001", "", Component(), CanonHostInfo::BROKEN, -1, ""}, + {"0X12C0a80001", L"0X12C0a80001", "", Component(), CanonHostInfo::BROKEN, -1, ""}, + {"276.1.2", L"276.1.2", "", Component(), CanonHostInfo::BROKEN, -1, ""}, // Spaces should be rejected. - {"192.168.0.1 hello", L"192.168.0.1 hello", "", url_parse::Component(), CanonHostInfo::NEUTRAL, -1, ""}, + {"192.168.0.1 hello", L"192.168.0.1 hello", "", Component(), CanonHostInfo::NEUTRAL, -1, ""}, // Very large numbers. - {"0000000000000300.0x00000000000000fF.00000000000000001", L"0000000000000300.0x00000000000000fF.00000000000000001", "192.255.0.1", url_parse::Component(0, 11), CanonHostInfo::IPV4, 3, "C0FF0001"}, - {"0000000000000300.0xffffffffFFFFFFFF.3022415481470977", L"0000000000000300.0xffffffffFFFFFFFF.3022415481470977", "", url_parse::Component(0, 11), CanonHostInfo::BROKEN, -1, ""}, + {"0000000000000300.0x00000000000000fF.00000000000000001", L"0000000000000300.0x00000000000000fF.00000000000000001", "192.255.0.1", Component(0, 11), CanonHostInfo::IPV4, 3, "C0FF0001"}, + {"0000000000000300.0xffffffffFFFFFFFF.3022415481470977", L"0000000000000300.0xffffffffFFFFFFFF.3022415481470977", "", Component(0, 11), CanonHostInfo::BROKEN, -1, ""}, // A number has no length limit, but long numbers can still overflow. - {"00000000000000000001", L"00000000000000000001", "0.0.0.1", url_parse::Component(0, 7), CanonHostInfo::IPV4, 1, "00000001"}, - {"0000000000000000100000000000000001", L"0000000000000000100000000000000001", "", url_parse::Component(), CanonHostInfo::BROKEN, -1, ""}, + {"00000000000000000001", L"00000000000000000001", "0.0.0.1", Component(0, 7), CanonHostInfo::IPV4, 1, "00000001"}, + {"0000000000000000100000000000000001", L"0000000000000000100000000000000001", "", Component(), CanonHostInfo::BROKEN, -1, ""}, // If a long component is non-numeric, it's a hostname, *not* a broken IP. - {"0.0.0.000000000000000000z", L"0.0.0.000000000000000000z", "", url_parse::Component(), CanonHostInfo::NEUTRAL, -1, ""}, - {"0.0.0.100000000000000000z", L"0.0.0.100000000000000000z", "", url_parse::Component(), CanonHostInfo::NEUTRAL, -1, ""}, + {"0.0.0.000000000000000000z", L"0.0.0.000000000000000000z", "", Component(), CanonHostInfo::NEUTRAL, -1, ""}, + {"0.0.0.100000000000000000z", L"0.0.0.100000000000000000z", "", Component(), CanonHostInfo::NEUTRAL, -1, ""}, // Truncation of all zeros should still result in 0. - {"0.00.0x.0x0", L"0.00.0x.0x0", "0.0.0.0", url_parse::Component(0, 7), CanonHostInfo::IPV4, 4, "00000000"}, + {"0.00.0x.0x0", L"0.00.0x.0x0", "0.0.0.0", Component(0, 7), CanonHostInfo::IPV4, 4, "00000000"}, }; for (size_t i = 0; i < arraysize(cases); i++) { // 8-bit version. - url_parse::Component component(0, - static_cast(strlen(cases[i].input8))); + Component component(0, static_cast(strlen(cases[i].input8))); std::string out_str1; - url_canon::StdStringCanonOutput output1(&out_str1); - url_canon::CanonHostInfo host_info; - url_canon::CanonicalizeIPAddress(cases[i].input8, component, &output1, - &host_info); + StdStringCanonOutput output1(&out_str1); + CanonHostInfo host_info; + CanonicalizeIPAddress(cases[i].input8, component, &output1, &host_info); output1.Complete(); EXPECT_EQ(cases[i].expected_family, host_info.family); @@ -762,12 +758,11 @@ TEST(URLCanonTest, IPv4) { // 16-bit version. base::string16 input16(WStringToUTF16(cases[i].input16)); - component = url_parse::Component(0, static_cast(input16.length())); + component = Component(0, static_cast(input16.length())); std::string out_str2; - url_canon::StdStringCanonOutput output2(&out_str2); - url_canon::CanonicalizeIPAddress(input16.c_str(), component, &output2, - &host_info); + StdStringCanonOutput output2(&out_str2); + CanonicalizeIPAddress(input16.c_str(), component, &output2, &host_info); output2.Complete(); EXPECT_EQ(cases[i].expected_family, host_info.family); @@ -786,83 +781,83 @@ TEST(URLCanonTest, IPv4) { TEST(URLCanonTest, IPv6) { IPAddressCase cases[] = { // Empty is not an IP address. - {"", L"", "", url_parse::Component(), CanonHostInfo::NEUTRAL, -1, ""}, + {"", L"", "", Component(), CanonHostInfo::NEUTRAL, -1, ""}, // Non-IPs with [:] characters are marked BROKEN. - {":", L":", "", url_parse::Component(), CanonHostInfo::BROKEN, -1, ""}, - {"[", L"[", "", url_parse::Component(), CanonHostInfo::BROKEN, -1, ""}, - {"[:", L"[:", "", url_parse::Component(), CanonHostInfo::BROKEN, -1, ""}, - {"]", L"]", "", url_parse::Component(), CanonHostInfo::BROKEN, -1, ""}, - {":]", L":]", "", url_parse::Component(), CanonHostInfo::BROKEN, -1, ""}, - {"[]", L"[]", "", url_parse::Component(), CanonHostInfo::BROKEN, -1, ""}, - {"[:]", L"[:]", "", url_parse::Component(), CanonHostInfo::BROKEN, -1, ""}, + {":", L":", "", Component(), CanonHostInfo::BROKEN, -1, ""}, + {"[", L"[", "", Component(), CanonHostInfo::BROKEN, -1, ""}, + {"[:", L"[:", "", Component(), CanonHostInfo::BROKEN, -1, ""}, + {"]", L"]", "", Component(), CanonHostInfo::BROKEN, -1, ""}, + {":]", L":]", "", Component(), CanonHostInfo::BROKEN, -1, ""}, + {"[]", L"[]", "", Component(), CanonHostInfo::BROKEN, -1, ""}, + {"[:]", L"[:]", "", Component(), CanonHostInfo::BROKEN, -1, ""}, // Regular IP address is invalid without bounding '[' and ']'. - {"2001:db8::1", L"2001:db8::1", "", url_parse::Component(), CanonHostInfo::BROKEN, -1, ""}, - {"[2001:db8::1", L"[2001:db8::1", "", url_parse::Component(), CanonHostInfo::BROKEN, -1, ""}, - {"2001:db8::1]", L"2001:db8::1]", "", url_parse::Component(), CanonHostInfo::BROKEN, -1, ""}, + {"2001:db8::1", L"2001:db8::1", "", Component(), CanonHostInfo::BROKEN, -1, ""}, + {"[2001:db8::1", L"[2001:db8::1", "", Component(), CanonHostInfo::BROKEN, -1, ""}, + {"2001:db8::1]", L"2001:db8::1]", "", Component(), CanonHostInfo::BROKEN, -1, ""}, // Regular IP addresses. - {"[::]", L"[::]", "[::]", url_parse::Component(0,4), CanonHostInfo::IPV6, -1, "00000000000000000000000000000000"}, - {"[::1]", L"[::1]", "[::1]", url_parse::Component(0,5), CanonHostInfo::IPV6, -1, "00000000000000000000000000000001"}, - {"[1::]", L"[1::]", "[1::]", url_parse::Component(0,5), CanonHostInfo::IPV6, -1, "00010000000000000000000000000000"}, + {"[::]", L"[::]", "[::]", Component(0,4), CanonHostInfo::IPV6, -1, "00000000000000000000000000000000"}, + {"[::1]", L"[::1]", "[::1]", Component(0,5), CanonHostInfo::IPV6, -1, "00000000000000000000000000000001"}, + {"[1::]", L"[1::]", "[1::]", Component(0,5), CanonHostInfo::IPV6, -1, "00010000000000000000000000000000"}, // Leading zeros should be stripped. - {"[000:01:02:003:004:5:6:007]", L"[000:01:02:003:004:5:6:007]", "[0:1:2:3:4:5:6:7]", url_parse::Component(0,17), CanonHostInfo::IPV6, -1, "00000001000200030004000500060007"}, + {"[000:01:02:003:004:5:6:007]", L"[000:01:02:003:004:5:6:007]", "[0:1:2:3:4:5:6:7]", Component(0,17), CanonHostInfo::IPV6, -1, "00000001000200030004000500060007"}, // Upper case letters should be lowercased. - {"[A:b:c:DE:fF:0:1:aC]", L"[A:b:c:DE:fF:0:1:aC]", "[a:b:c:de:ff:0:1:ac]", url_parse::Component(0,20), CanonHostInfo::IPV6, -1, "000A000B000C00DE00FF0000000100AC"}, + {"[A:b:c:DE:fF:0:1:aC]", L"[A:b:c:DE:fF:0:1:aC]", "[a:b:c:de:ff:0:1:ac]", Component(0,20), CanonHostInfo::IPV6, -1, "000A000B000C00DE00FF0000000100AC"}, // The same address can be written with different contractions, but should // get canonicalized to the same thing. - {"[1:0:0:2::3:0]", L"[1:0:0:2::3:0]", "[1::2:0:0:3:0]", url_parse::Component(0,14), CanonHostInfo::IPV6, -1, "00010000000000020000000000030000"}, - {"[1::2:0:0:3:0]", L"[1::2:0:0:3:0]", "[1::2:0:0:3:0]", url_parse::Component(0,14), CanonHostInfo::IPV6, -1, "00010000000000020000000000030000"}, + {"[1:0:0:2::3:0]", L"[1:0:0:2::3:0]", "[1::2:0:0:3:0]", Component(0,14), CanonHostInfo::IPV6, -1, "00010000000000020000000000030000"}, + {"[1::2:0:0:3:0]", L"[1::2:0:0:3:0]", "[1::2:0:0:3:0]", Component(0,14), CanonHostInfo::IPV6, -1, "00010000000000020000000000030000"}, // Addresses with embedded IPv4. - {"[::192.168.0.1]", L"[::192.168.0.1]", "[::c0a8:1]", url_parse::Component(0,10), CanonHostInfo::IPV6, -1, "000000000000000000000000C0A80001"}, - {"[::ffff:192.168.0.1]", L"[::ffff:192.168.0.1]", "[::ffff:c0a8:1]", url_parse::Component(0,15), CanonHostInfo::IPV6, -1, "00000000000000000000FFFFC0A80001"}, - {"[::eeee:192.168.0.1]", L"[::eeee:192.168.0.1]", "[::eeee:c0a8:1]", url_parse::Component(0, 15), CanonHostInfo::IPV6, -1, "00000000000000000000EEEEC0A80001"}, - {"[2001::192.168.0.1]", L"[2001::192.168.0.1]", "[2001::c0a8:1]", url_parse::Component(0, 14), CanonHostInfo::IPV6, -1, "200100000000000000000000C0A80001"}, - {"[1:2:192.168.0.1:5:6]", L"[1:2:192.168.0.1:5:6]", "", url_parse::Component(), CanonHostInfo::BROKEN, -1, ""}, + {"[::192.168.0.1]", L"[::192.168.0.1]", "[::c0a8:1]", Component(0,10), CanonHostInfo::IPV6, -1, "000000000000000000000000C0A80001"}, + {"[::ffff:192.168.0.1]", L"[::ffff:192.168.0.1]", "[::ffff:c0a8:1]", Component(0,15), CanonHostInfo::IPV6, -1, "00000000000000000000FFFFC0A80001"}, + {"[::eeee:192.168.0.1]", L"[::eeee:192.168.0.1]", "[::eeee:c0a8:1]", Component(0, 15), CanonHostInfo::IPV6, -1, "00000000000000000000EEEEC0A80001"}, + {"[2001::192.168.0.1]", L"[2001::192.168.0.1]", "[2001::c0a8:1]", Component(0, 14), CanonHostInfo::IPV6, -1, "200100000000000000000000C0A80001"}, + {"[1:2:192.168.0.1:5:6]", L"[1:2:192.168.0.1:5:6]", "", Component(), CanonHostInfo::BROKEN, -1, ""}, // IPv4 with last component missing. - {"[::ffff:192.1.2]", L"[::ffff:192.1.2]", "[::ffff:c001:2]", url_parse::Component(0,15), CanonHostInfo::IPV6, -1, "00000000000000000000FFFFC0010002"}, + {"[::ffff:192.1.2]", L"[::ffff:192.1.2]", "[::ffff:c001:2]", Component(0,15), CanonHostInfo::IPV6, -1, "00000000000000000000FFFFC0010002"}, // IPv4 using hex. // TODO(eroman): Should this format be disallowed? - {"[::ffff:0xC0.0Xa8.0x0.0x1]", L"[::ffff:0xC0.0Xa8.0x0.0x1]", "[::ffff:c0a8:1]", url_parse::Component(0,15), CanonHostInfo::IPV6, -1, "00000000000000000000FFFFC0A80001"}, + {"[::ffff:0xC0.0Xa8.0x0.0x1]", L"[::ffff:0xC0.0Xa8.0x0.0x1]", "[::ffff:c0a8:1]", Component(0,15), CanonHostInfo::IPV6, -1, "00000000000000000000FFFFC0A80001"}, // There may be zeros surrounding the "::" contraction. - {"[0:0::0:0:8]", L"[0:0::0:0:8]", "[::8]", url_parse::Component(0,5), CanonHostInfo::IPV6, -1, "00000000000000000000000000000008"}, + {"[0:0::0:0:8]", L"[0:0::0:0:8]", "[::8]", Component(0,5), CanonHostInfo::IPV6, -1, "00000000000000000000000000000008"}, - {"[2001:db8::1]", L"[2001:db8::1]", "[2001:db8::1]", url_parse::Component(0,13), CanonHostInfo::IPV6, -1, "20010DB8000000000000000000000001"}, + {"[2001:db8::1]", L"[2001:db8::1]", "[2001:db8::1]", Component(0,13), CanonHostInfo::IPV6, -1, "20010DB8000000000000000000000001"}, // Can only have one "::" contraction in an IPv6 string literal. - {"[2001::db8::1]", L"[2001::db8::1]", "", url_parse::Component(), CanonHostInfo::BROKEN, -1, ""}, + {"[2001::db8::1]", L"[2001::db8::1]", "", Component(), CanonHostInfo::BROKEN, -1, ""}, // No more than 2 consecutive ':'s. - {"[2001:db8:::1]", L"[2001:db8:::1]", "", url_parse::Component(), CanonHostInfo::BROKEN, -1, ""}, - {"[:::]", L"[:::]", "", url_parse::Component(), CanonHostInfo::BROKEN, -1, ""}, + {"[2001:db8:::1]", L"[2001:db8:::1]", "", Component(), CanonHostInfo::BROKEN, -1, ""}, + {"[:::]", L"[:::]", "", Component(), CanonHostInfo::BROKEN, -1, ""}, // Non-IP addresses due to invalid characters. - {"[2001::.com]", L"[2001::.com]", "", url_parse::Component(), CanonHostInfo::BROKEN, -1, ""}, + {"[2001::.com]", L"[2001::.com]", "", Component(), CanonHostInfo::BROKEN, -1, ""}, // If there are not enough components, the last one should fill them out. // ... omitted at this time ... // Too many components means not an IP address. Similarly with too few if using IPv4 compat or mapped addresses. - {"[::192.168.0.0.1]", L"[::192.168.0.0.1]", "", url_parse::Component(), CanonHostInfo::BROKEN, -1, ""}, - {"[::ffff:192.168.0.0.1]", L"[::ffff:192.168.0.0.1]", "", url_parse::Component(), CanonHostInfo::BROKEN, -1, ""}, - {"[1:2:3:4:5:6:7:8:9]", L"[1:2:3:4:5:6:7:8:9]", "", url_parse::Component(), CanonHostInfo::BROKEN, -1, ""}, + {"[::192.168.0.0.1]", L"[::192.168.0.0.1]", "", Component(), CanonHostInfo::BROKEN, -1, ""}, + {"[::ffff:192.168.0.0.1]", L"[::ffff:192.168.0.0.1]", "", Component(), CanonHostInfo::BROKEN, -1, ""}, + {"[1:2:3:4:5:6:7:8:9]", L"[1:2:3:4:5:6:7:8:9]", "", Component(), CanonHostInfo::BROKEN, -1, ""}, // Too many bits (even though 8 comonents, the last one holds 32 bits). - {"[0:0:0:0:0:0:0:192.168.0.1]", L"[0:0:0:0:0:0:0:192.168.0.1]", "", url_parse::Component(), CanonHostInfo::BROKEN, -1, ""}, + {"[0:0:0:0:0:0:0:192.168.0.1]", L"[0:0:0:0:0:0:0:192.168.0.1]", "", Component(), CanonHostInfo::BROKEN, -1, ""}, // Too many bits specified -- the contraction would have to be zero-length // to not exceed 128 bits. - {"[1:2:3:4:5:6::192.168.0.1]", L"[1:2:3:4:5:6::192.168.0.1]", "", url_parse::Component(), CanonHostInfo::BROKEN, -1, ""}, + {"[1:2:3:4:5:6::192.168.0.1]", L"[1:2:3:4:5:6::192.168.0.1]", "", Component(), CanonHostInfo::BROKEN, -1, ""}, // The contraction is for 16 bits of zero. - {"[1:2:3:4:5:6::8]", L"[1:2:3:4:5:6::8]", "[1:2:3:4:5:6:0:8]", url_parse::Component(0,17), CanonHostInfo::IPV6, -1, "00010002000300040005000600000008"}, + {"[1:2:3:4:5:6::8]", L"[1:2:3:4:5:6::8]", "[1:2:3:4:5:6:0:8]", Component(0,17), CanonHostInfo::IPV6, -1, "00010002000300040005000600000008"}, // Cannot have a trailing colon. - {"[1:2:3:4:5:6:7:8:]", L"[1:2:3:4:5:6:7:8:]", "", url_parse::Component(), CanonHostInfo::BROKEN, -1, ""}, - {"[1:2:3:4:5:6:192.168.0.1:]", L"[1:2:3:4:5:6:192.168.0.1:]", "", url_parse::Component(), CanonHostInfo::BROKEN, -1, ""}, + {"[1:2:3:4:5:6:7:8:]", L"[1:2:3:4:5:6:7:8:]", "", Component(), CanonHostInfo::BROKEN, -1, ""}, + {"[1:2:3:4:5:6:192.168.0.1:]", L"[1:2:3:4:5:6:192.168.0.1:]", "", Component(), CanonHostInfo::BROKEN, -1, ""}, // Cannot have negative numbers. - {"[-1:2:3:4:5:6:7:8]", L"[-1:2:3:4:5:6:7:8]", "", url_parse::Component(), CanonHostInfo::BROKEN, -1, ""}, + {"[-1:2:3:4:5:6:7:8]", L"[-1:2:3:4:5:6:7:8]", "", Component(), CanonHostInfo::BROKEN, -1, ""}, // Scope ID -- the URL may contain an optional ["%" ] section. // The scope_id should be included in the canonicalized URL, and is an @@ -871,37 +866,35 @@ TEST(URLCanonTest, IPv6) { // Invalid because no ID was given after the percent. // Don't allow scope-id - {"[1::%1]", L"[1::%1]", "", url_parse::Component(), CanonHostInfo::BROKEN, -1, ""}, - {"[1::%eth0]", L"[1::%eth0]", "", url_parse::Component(), CanonHostInfo::BROKEN, -1, ""}, - {"[1::%]", L"[1::%]", "", url_parse::Component(), CanonHostInfo::BROKEN, -1, ""}, - {"[%]", L"[%]", "", url_parse::Component(), CanonHostInfo::BROKEN, -1, ""}, - {"[::%:]", L"[::%:]", "", url_parse::Component(), CanonHostInfo::BROKEN, -1, ""}, + {"[1::%1]", L"[1::%1]", "", Component(), CanonHostInfo::BROKEN, -1, ""}, + {"[1::%eth0]", L"[1::%eth0]", "", Component(), CanonHostInfo::BROKEN, -1, ""}, + {"[1::%]", L"[1::%]", "", Component(), CanonHostInfo::BROKEN, -1, ""}, + {"[%]", L"[%]", "", Component(), CanonHostInfo::BROKEN, -1, ""}, + {"[::%:]", L"[::%:]", "", Component(), CanonHostInfo::BROKEN, -1, ""}, // Don't allow leading or trailing colons. - {"[:0:0::0:0:8]", L"[:0:0::0:0:8]", "", url_parse::Component(), CanonHostInfo::BROKEN, -1, ""}, - {"[0:0::0:0:8:]", L"[0:0::0:0:8:]", "", url_parse::Component(), CanonHostInfo::BROKEN, -1, ""}, - {"[:0:0::0:0:8:]", L"[:0:0::0:0:8:]", "", url_parse::Component(), CanonHostInfo::BROKEN, -1, ""}, + {"[:0:0::0:0:8]", L"[:0:0::0:0:8]", "", Component(), CanonHostInfo::BROKEN, -1, ""}, + {"[0:0::0:0:8:]", L"[0:0::0:0:8:]", "", Component(), CanonHostInfo::BROKEN, -1, ""}, + {"[:0:0::0:0:8:]", L"[:0:0::0:0:8:]", "", Component(), CanonHostInfo::BROKEN, -1, ""}, // We allow a single trailing dot. // ... omitted at this time ... // Two dots in a row means not an IP address. - {"[::192.168..1]", L"[::192.168..1]", "", url_parse::Component(), CanonHostInfo::BROKEN, -1, ""}, + {"[::192.168..1]", L"[::192.168..1]", "", Component(), CanonHostInfo::BROKEN, -1, ""}, // Any non-first components get truncated to one byte. // ... omitted at this time ... // Spaces should be rejected. - {"[::1 hello]", L"[::1 hello]", "", url_parse::Component(), CanonHostInfo::BROKEN, -1, ""}, + {"[::1 hello]", L"[::1 hello]", "", Component(), CanonHostInfo::BROKEN, -1, ""}, }; for (size_t i = 0; i < arraysize(cases); i++) { // 8-bit version. - url_parse::Component component(0, - static_cast(strlen(cases[i].input8))); + Component component(0, static_cast(strlen(cases[i].input8))); std::string out_str1; - url_canon::StdStringCanonOutput output1(&out_str1); - url_canon::CanonHostInfo host_info; - url_canon::CanonicalizeIPAddress(cases[i].input8, component, &output1, - &host_info); + StdStringCanonOutput output1(&out_str1); + CanonHostInfo host_info; + CanonicalizeIPAddress(cases[i].input8, component, &output1, &host_info); output1.Complete(); EXPECT_EQ(cases[i].expected_family, host_info.family); @@ -916,12 +909,11 @@ TEST(URLCanonTest, IPv6) { // 16-bit version. base::string16 input16(WStringToUTF16(cases[i].input16)); - component = url_parse::Component(0, static_cast(input16.length())); + component = Component(0, static_cast(input16.length())); std::string out_str2; - url_canon::StdStringCanonOutput output2(&out_str2); - url_canon::CanonicalizeIPAddress(input16.c_str(), component, &output2, - &host_info); + StdStringCanonOutput output2(&out_str2); + CanonicalizeIPAddress(input16.c_str(), component, &output2, &host_info); output2.Complete(); EXPECT_EQ(cases[i].expected_family, host_info.family); @@ -937,17 +929,15 @@ TEST(URLCanonTest, IPv6) { TEST(URLCanonTest, IPEmpty) { std::string out_str1; - url_canon::StdStringCanonOutput output1(&out_str1); - url_canon::CanonHostInfo host_info; + StdStringCanonOutput output1(&out_str1); + CanonHostInfo host_info; // This tests tests. const char spec[] = "192.168.0.1"; - url_canon::CanonicalizeIPAddress(spec, url_parse::Component(), - &output1, &host_info); + CanonicalizeIPAddress(spec, Component(), &output1, &host_info); EXPECT_FALSE(host_info.IsIPAddress()); - url_canon::CanonicalizeIPAddress(spec, url_parse::Component(0, 0), - &output1, &host_info); + CanonicalizeIPAddress(spec, Component(0, 0), &output1, &host_info); EXPECT_FALSE(host_info.IsIPAddress()); } @@ -959,38 +949,39 @@ TEST(URLCanonTest, UserInfo) { struct UserComponentCase { const char* input; const char* expected; - url_parse::Component expected_username; - url_parse::Component expected_password; + Component expected_username; + Component expected_password; bool expected_success; } user_info_cases[] = { - {"http://user:pass@host.com/", "user:pass@", url_parse::Component(0, 4), url_parse::Component(5, 4), true}, - {"http://@host.com/", "", url_parse::Component(0, -1), url_parse::Component(0, -1), true}, - {"http://:@host.com/", "", url_parse::Component(0, -1), url_parse::Component(0, -1), true}, - {"http://foo:@host.com/", "foo@", url_parse::Component(0, 3), url_parse::Component(0, -1), true}, - {"http://:foo@host.com/", ":foo@", url_parse::Component(0, 0), url_parse::Component(1, 3), true}, - {"http://^ :$\t@host.com/", "%5E%20:$%09@", url_parse::Component(0, 6), url_parse::Component(7, 4), true}, - {"http://user:pass@/", "user:pass@", url_parse::Component(0, 4), url_parse::Component(5, 4), true}, - {"http://%2540:bar@domain.com/", "%2540:bar@", url_parse::Component(0, 5), url_parse::Component(6, 3), true }, + {"http://user:pass@host.com/", "user:pass@", Component(0, 4), Component(5, 4), true}, + {"http://@host.com/", "", Component(0, -1), Component(0, -1), true}, + {"http://:@host.com/", "", Component(0, -1), Component(0, -1), true}, + {"http://foo:@host.com/", "foo@", Component(0, 3), Component(0, -1), true}, + {"http://:foo@host.com/", ":foo@", Component(0, 0), Component(1, 3), true}, + {"http://^ :$\t@host.com/", "%5E%20:$%09@", Component(0, 6), Component(7, 4), true}, + {"http://user:pass@/", "user:pass@", Component(0, 4), Component(5, 4), true}, + {"http://%2540:bar@domain.com/", "%2540:bar@", Component(0, 5), Component(6, 3), true }, // IE7 compatability: old versions allowed backslashes in usernames, but // IE7 does not. We disallow it as well. - {"ftp://me\\mydomain:pass@foo.com/", "", url_parse::Component(0, -1), url_parse::Component(0, -1), true}, + {"ftp://me\\mydomain:pass@foo.com/", "", Component(0, -1), Component(0, -1), true}, }; for (size_t i = 0; i < ARRAYSIZE(user_info_cases); i++) { int url_len = static_cast(strlen(user_info_cases[i].input)); - url_parse::Parsed parsed; - url_parse::ParseStandardURL(user_info_cases[i].input, url_len, &parsed); - url_parse::Component out_user, out_pass; + Parsed parsed; + ParseStandardURL(user_info_cases[i].input, url_len, &parsed); + Component out_user, out_pass; std::string out_str; - url_canon::StdStringCanonOutput output1(&out_str); - - bool success = url_canon::CanonicalizeUserInfo(user_info_cases[i].input, - parsed.username, - user_info_cases[i].input, - parsed.password, - &output1, &out_user, - &out_pass); + StdStringCanonOutput output1(&out_str); + + bool success = CanonicalizeUserInfo(user_info_cases[i].input, + parsed.username, + user_info_cases[i].input, + parsed.password, + &output1, + &out_user, + &out_pass); output1.Complete(); EXPECT_EQ(user_info_cases[i].expected_success, success); @@ -1002,13 +993,15 @@ TEST(URLCanonTest, UserInfo) { // Now try the wide version out_str.clear(); - url_canon::StdStringCanonOutput output2(&out_str); + StdStringCanonOutput output2(&out_str); base::string16 wide_input(ConvertUTF8ToUTF16(user_info_cases[i].input)); - success = url_canon::CanonicalizeUserInfo(wide_input.c_str(), - parsed.username, - wide_input.c_str(), - parsed.password, - &output2, &out_user, &out_pass); + success = CanonicalizeUserInfo(wide_input.c_str(), + parsed.username, + wide_input.c_str(), + parsed.password, + &output2, + &out_user, + &out_pass); output2.Complete(); EXPECT_EQ(user_info_cases[i].expected_success, success); @@ -1030,28 +1023,30 @@ TEST(URLCanonTest, Port) { const char* input; int default_port; const char* expected; - url_parse::Component expected_component; + Component expected_component; bool expected_success; } port_cases[] = { // Invalid input should be copied w/ failure. - {"as df", 80, ":as%20df", url_parse::Component(1, 7), false}, - {"-2", 80, ":-2", url_parse::Component(1, 2), false}, + {"as df", 80, ":as%20df", Component(1, 7), false}, + {"-2", 80, ":-2", Component(1, 2), false}, // Default port should be omitted. - {"80", 80, "", url_parse::Component(0, -1), true}, - {"8080", 80, ":8080", url_parse::Component(1, 4), true}, + {"80", 80, "", Component(0, -1), true}, + {"8080", 80, ":8080", Component(1, 4), true}, // PORT_UNSPECIFIED should mean always keep the port. - {"80", url_parse::PORT_UNSPECIFIED, ":80", url_parse::Component(1, 2), true}, + {"80", PORT_UNSPECIFIED, ":80", Component(1, 2), true}, }; for (size_t i = 0; i < ARRAYSIZE(port_cases); i++) { int url_len = static_cast(strlen(port_cases[i].input)); - url_parse::Component in_comp(0, url_len); - url_parse::Component out_comp; + Component in_comp(0, url_len); + Component out_comp; std::string out_str; - url_canon::StdStringCanonOutput output1(&out_str); - bool success = url_canon::CanonicalizePort(port_cases[i].input, in_comp, - port_cases[i].default_port, - &output1, &out_comp); + StdStringCanonOutput output1(&out_str); + bool success = CanonicalizePort(port_cases[i].input, + in_comp, + port_cases[i].default_port, + &output1, + &out_comp); output1.Complete(); EXPECT_EQ(port_cases[i].expected_success, success); @@ -1061,11 +1056,13 @@ TEST(URLCanonTest, Port) { // Now try the wide version out_str.clear(); - url_canon::StdStringCanonOutput output2(&out_str); + StdStringCanonOutput output2(&out_str); base::string16 wide_input(ConvertUTF8ToUTF16(port_cases[i].input)); - success = url_canon::CanonicalizePort(wide_input.c_str(), in_comp, - port_cases[i].default_port, - &output2, &out_comp); + success = CanonicalizePort(wide_input.c_str(), + in_comp, + port_cases[i].default_port, + &output2, + &out_comp); output2.Complete(); EXPECT_EQ(port_cases[i].expected_success, success); @@ -1078,84 +1075,84 @@ TEST(URLCanonTest, Port) { TEST(URLCanonTest, Path) { DualComponentCase path_cases[] = { // ----- path collapsing tests ----- - {"/././foo", L"/././foo", "/foo", url_parse::Component(0, 4), true}, - {"/./.foo", L"/./.foo", "/.foo", url_parse::Component(0, 5), true}, - {"/foo/.", L"/foo/.", "/foo/", url_parse::Component(0, 5), true}, - {"/foo/./", L"/foo/./", "/foo/", url_parse::Component(0, 5), true}, + {"/././foo", L"/././foo", "/foo", Component(0, 4), true}, + {"/./.foo", L"/./.foo", "/.foo", Component(0, 5), true}, + {"/foo/.", L"/foo/.", "/foo/", Component(0, 5), true}, + {"/foo/./", L"/foo/./", "/foo/", Component(0, 5), true}, // double dots followed by a slash or the end of the string count - {"/foo/bar/..", L"/foo/bar/..", "/foo/", url_parse::Component(0, 5), true}, - {"/foo/bar/../", L"/foo/bar/../", "/foo/", url_parse::Component(0, 5), true}, + {"/foo/bar/..", L"/foo/bar/..", "/foo/", Component(0, 5), true}, + {"/foo/bar/../", L"/foo/bar/../", "/foo/", Component(0, 5), true}, // don't count double dots when they aren't followed by a slash - {"/foo/..bar", L"/foo/..bar", "/foo/..bar", url_parse::Component(0, 10), true}, + {"/foo/..bar", L"/foo/..bar", "/foo/..bar", Component(0, 10), true}, // some in the middle - {"/foo/bar/../ton", L"/foo/bar/../ton", "/foo/ton", url_parse::Component(0, 8), true}, - {"/foo/bar/../ton/../../a", L"/foo/bar/../ton/../../a", "/a", url_parse::Component(0, 2), true}, + {"/foo/bar/../ton", L"/foo/bar/../ton", "/foo/ton", Component(0, 8), true}, + {"/foo/bar/../ton/../../a", L"/foo/bar/../ton/../../a", "/a", Component(0, 2), true}, // we should not be able to go above the root - {"/foo/../../..", L"/foo/../../..", "/", url_parse::Component(0, 1), true}, - {"/foo/../../../ton", L"/foo/../../../ton", "/ton", url_parse::Component(0, 4), true}, + {"/foo/../../..", L"/foo/../../..", "/", Component(0, 1), true}, + {"/foo/../../../ton", L"/foo/../../../ton", "/ton", Component(0, 4), true}, // escaped dots should be unescaped and treated the same as dots - {"/foo/%2e", L"/foo/%2e", "/foo/", url_parse::Component(0, 5), true}, - {"/foo/%2e%2", L"/foo/%2e%2", "/foo/.%2", url_parse::Component(0, 8), true}, - {"/foo/%2e./%2e%2e/.%2e/%2e.bar", L"/foo/%2e./%2e%2e/.%2e/%2e.bar", "/..bar", url_parse::Component(0, 6), true}, + {"/foo/%2e", L"/foo/%2e", "/foo/", Component(0, 5), true}, + {"/foo/%2e%2", L"/foo/%2e%2", "/foo/.%2", Component(0, 8), true}, + {"/foo/%2e./%2e%2e/.%2e/%2e.bar", L"/foo/%2e./%2e%2e/.%2e/%2e.bar", "/..bar", Component(0, 6), true}, // Multiple slashes in a row should be preserved and treated like empty // directory names. - {"////../..", L"////../..", "//", url_parse::Component(0, 2), true}, + {"////../..", L"////../..", "//", Component(0, 2), true}, // ----- escaping tests ----- - {"/foo", L"/foo", "/foo", url_parse::Component(0, 4), true}, + {"/foo", L"/foo", "/foo", Component(0, 4), true}, // Valid escape sequence - {"/%20foo", L"/%20foo", "/%20foo", url_parse::Component(0, 7), true}, + {"/%20foo", L"/%20foo", "/%20foo", Component(0, 7), true}, // Invalid escape sequence we should pass through unchanged. - {"/foo%", L"/foo%", "/foo%", url_parse::Component(0, 5), true}, - {"/foo%2", L"/foo%2", "/foo%2", url_parse::Component(0, 6), true}, + {"/foo%", L"/foo%", "/foo%", Component(0, 5), true}, + {"/foo%2", L"/foo%2", "/foo%2", Component(0, 6), true}, // Invalid escape sequence: bad characters should be treated the same as // the sourrounding text, not as escaped (in this case, UTF-8). - {"/foo%2zbar", L"/foo%2zbar", "/foo%2zbar", url_parse::Component(0, 10), true}, - {"/foo%2\xc2\xa9zbar", NULL, "/foo%2%C2%A9zbar", url_parse::Component(0, 16), true}, - {NULL, L"/foo%2\xc2\xa9zbar", "/foo%2%C3%82%C2%A9zbar", url_parse::Component(0, 22), true}, + {"/foo%2zbar", L"/foo%2zbar", "/foo%2zbar", Component(0, 10), true}, + {"/foo%2\xc2\xa9zbar", NULL, "/foo%2%C2%A9zbar", Component(0, 16), true}, + {NULL, L"/foo%2\xc2\xa9zbar", "/foo%2%C3%82%C2%A9zbar", Component(0, 22), true}, // Regular characters that are escaped should be unescaped - {"/foo%41%7a", L"/foo%41%7a", "/fooAz", url_parse::Component(0, 6), true}, + {"/foo%41%7a", L"/foo%41%7a", "/fooAz", Component(0, 6), true}, // Funny characters that are unescaped should be escaped - {"/foo\x09\x91%91", NULL, "/foo%09%91%91", url_parse::Component(0, 13), true}, - {NULL, L"/foo\x09\x91%91", "/foo%09%C2%91%91", url_parse::Component(0, 16), true}, + {"/foo\x09\x91%91", NULL, "/foo%09%91%91", Component(0, 13), true}, + {NULL, L"/foo\x09\x91%91", "/foo%09%C2%91%91", Component(0, 16), true}, // Invalid characters that are escaped should cause a failure. - {"/foo%00%51", L"/foo%00%51", "/foo%00Q", url_parse::Component(0, 8), false}, + {"/foo%00%51", L"/foo%00%51", "/foo%00Q", Component(0, 8), false}, // Some characters should be passed through unchanged regardless of esc. - {"/(%28:%3A%29)", L"/(%28:%3A%29)", "/(%28:%3A%29)", url_parse::Component(0, 13), true}, + {"/(%28:%3A%29)", L"/(%28:%3A%29)", "/(%28:%3A%29)", Component(0, 13), true}, // Characters that are properly escaped should not have the case changed // of hex letters. - {"/%3A%3a%3C%3c", L"/%3A%3a%3C%3c", "/%3A%3a%3C%3c", url_parse::Component(0, 13), true}, + {"/%3A%3a%3C%3c", L"/%3A%3a%3C%3c", "/%3A%3a%3C%3c", Component(0, 13), true}, // Funny characters that are unescaped should be escaped - {"/foo\tbar", L"/foo\tbar", "/foo%09bar", url_parse::Component(0, 10), true}, + {"/foo\tbar", L"/foo\tbar", "/foo%09bar", Component(0, 10), true}, // Backslashes should get converted to forward slashes - {"\\foo\\bar", L"\\foo\\bar", "/foo/bar", url_parse::Component(0, 8), true}, + {"\\foo\\bar", L"\\foo\\bar", "/foo/bar", Component(0, 8), true}, // Hashes found in paths (possibly only when the caller explicitly sets // the path on an already-parsed URL) should be escaped. - {"/foo#bar", L"/foo#bar", "/foo%23bar", url_parse::Component(0, 10), true}, + {"/foo#bar", L"/foo#bar", "/foo%23bar", Component(0, 10), true}, // %7f should be allowed and %3D should not be unescaped (these were wrong // in a previous version). - {"/%7Ffp3%3Eju%3Dduvgw%3Dd", L"/%7Ffp3%3Eju%3Dduvgw%3Dd", "/%7Ffp3%3Eju%3Dduvgw%3Dd", url_parse::Component(0, 24), true}, + {"/%7Ffp3%3Eju%3Dduvgw%3Dd", L"/%7Ffp3%3Eju%3Dduvgw%3Dd", "/%7Ffp3%3Eju%3Dduvgw%3Dd", Component(0, 24), true}, // @ should be passed through unchanged (escaped or unescaped). - {"/@asdf%40", L"/@asdf%40", "/@asdf%40", url_parse::Component(0, 9), true}, + {"/@asdf%40", L"/@asdf%40", "/@asdf%40", Component(0, 9), true}, // ----- encoding tests ----- // Basic conversions - {"/\xe4\xbd\xa0\xe5\xa5\xbd\xe4\xbd\xa0\xe5\xa5\xbd", L"/\x4f60\x597d\x4f60\x597d", "/%E4%BD%A0%E5%A5%BD%E4%BD%A0%E5%A5%BD", url_parse::Component(0, 37), true}, + {"/\xe4\xbd\xa0\xe5\xa5\xbd\xe4\xbd\xa0\xe5\xa5\xbd", L"/\x4f60\x597d\x4f60\x597d", "/%E4%BD%A0%E5%A5%BD%E4%BD%A0%E5%A5%BD", Component(0, 37), true}, // Invalid unicode characters should fail. We only do validation on // UTF-16 input, so this doesn't happen on 8-bit. - {"/\xef\xb7\x90zyx", NULL, "/%EF%B7%90zyx", url_parse::Component(0, 13), true}, - {NULL, L"/\xfdd0zyx", "/%EF%BF%BDzyx", url_parse::Component(0, 13), false}, + {"/\xef\xb7\x90zyx", NULL, "/%EF%B7%90zyx", Component(0, 13), true}, + {NULL, L"/\xfdd0zyx", "/%EF%BF%BDzyx", Component(0, 13), false}, }; for (size_t i = 0; i < arraysize(path_cases); i++) { if (path_cases[i].input8) { int len = static_cast(strlen(path_cases[i].input8)); - url_parse::Component in_comp(0, len); - url_parse::Component out_comp; + Component in_comp(0, len); + Component out_comp; std::string out_str; - url_canon::StdStringCanonOutput output(&out_str); - bool success = url_canon::CanonicalizePath(path_cases[i].input8, in_comp, - &output, &out_comp); + StdStringCanonOutput output(&out_str); + bool success = + CanonicalizePath(path_cases[i].input8, in_comp, &output, &out_comp); output.Complete(); EXPECT_EQ(path_cases[i].expected_success, success); @@ -1167,13 +1164,13 @@ TEST(URLCanonTest, Path) { if (path_cases[i].input16) { base::string16 input16(WStringToUTF16(path_cases[i].input16)); int len = static_cast(input16.length()); - url_parse::Component in_comp(0, len); - url_parse::Component out_comp; + Component in_comp(0, len); + Component out_comp; std::string out_str; - url_canon::StdStringCanonOutput output(&out_str); + StdStringCanonOutput output(&out_str); - bool success = url_canon::CanonicalizePath(input16.c_str(), in_comp, - &output, &out_comp); + bool success = + CanonicalizePath(input16.c_str(), in_comp, &output, &out_comp); output.Complete(); EXPECT_EQ(path_cases[i].expected_success, success); @@ -1186,13 +1183,12 @@ TEST(URLCanonTest, Path) { // Manual test: embedded NULLs should be escaped and the URL should be marked // as invalid. const char path_with_null[] = "/ab\0c"; - url_parse::Component in_comp(0, 5); - url_parse::Component out_comp; + Component in_comp(0, 5); + Component out_comp; std::string out_str; - url_canon::StdStringCanonOutput output(&out_str); - bool success = url_canon::CanonicalizePath(path_with_null, in_comp, - &output, &out_comp); + StdStringCanonOutput output(&out_str); + bool success = CanonicalizePath(path_with_null, in_comp, &output, &out_comp); output.Complete(); EXPECT_FALSE(success); EXPECT_EQ("/ab%00c", out_str); @@ -1235,25 +1231,25 @@ TEST(URLCanonTest, Query) { }; for (size_t i = 0; i < ARRAYSIZE(query_cases); i++) { - url_parse::Component out_comp; + Component out_comp; UConvScoper conv(query_cases[i].encoding); ASSERT_TRUE(!query_cases[i].encoding || conv.converter()); - url_canon::ICUCharsetConverter converter(conv.converter()); + ICUCharsetConverter converter(conv.converter()); // Map NULL to a NULL converter pointer. - url_canon::ICUCharsetConverter* conv_pointer = &converter; + ICUCharsetConverter* conv_pointer = &converter; if (!query_cases[i].encoding) conv_pointer = NULL; if (query_cases[i].input8) { int len = static_cast(strlen(query_cases[i].input8)); - url_parse::Component in_comp(0, len); + Component in_comp(0, len); std::string out_str; - url_canon::StdStringCanonOutput output(&out_str); - url_canon::CanonicalizeQuery(query_cases[i].input8, in_comp, - conv_pointer, &output, &out_comp); + StdStringCanonOutput output(&out_str); + CanonicalizeQuery(query_cases[i].input8, in_comp, conv_pointer, &output, + &out_comp); output.Complete(); EXPECT_EQ(query_cases[i].expected, out_str); @@ -1262,12 +1258,12 @@ TEST(URLCanonTest, Query) { if (query_cases[i].input16) { base::string16 input16(WStringToUTF16(query_cases[i].input16)); int len = static_cast(input16.length()); - url_parse::Component in_comp(0, len); + Component in_comp(0, len); std::string out_str; - url_canon::StdStringCanonOutput output(&out_str); - url_canon::CanonicalizeQuery(input16.c_str(), in_comp, - conv_pointer, &output, &out_comp); + StdStringCanonOutput output(&out_str); + CanonicalizeQuery(input16.c_str(), in_comp, conv_pointer, &output, + &out_comp); output.Complete(); EXPECT_EQ(query_cases[i].expected, out_str); @@ -1276,10 +1272,9 @@ TEST(URLCanonTest, Query) { // Extra test for input with embedded NULL; std::string out_str; - url_canon::StdStringCanonOutput output(&out_str); - url_parse::Component out_comp; - url_canon::CanonicalizeQuery("a \x00z\x01", url_parse::Component(0, 5), NULL, - &output, &out_comp); + StdStringCanonOutput output(&out_str); + Component out_comp; + CanonicalizeQuery("a \x00z\x01", Component(0, 5), NULL, &output, &out_comp); output.Complete(); EXPECT_EQ("?a%20%00z%01", out_str); } @@ -1288,34 +1283,33 @@ TEST(URLCanonTest, Ref) { // Refs are trivial, it just checks the encoding. DualComponentCase ref_cases[] = { // Regular one, we shouldn't escape spaces, et al. - {"hello, world", L"hello, world", "#hello, world", url_parse::Component(1, 12), true}, + {"hello, world", L"hello, world", "#hello, world", Component(1, 12), true}, // UTF-8/wide input should be preserved - {"\xc2\xa9", L"\xa9", "#\xc2\xa9", url_parse::Component(1, 2), true}, + {"\xc2\xa9", L"\xa9", "#\xc2\xa9", Component(1, 2), true}, // Test a characer that takes > 16 bits (U+10300 = old italic letter A) - {"\xF0\x90\x8C\x80ss", L"\xd800\xdf00ss", "#\xF0\x90\x8C\x80ss", url_parse::Component(1, 6), true}, + {"\xF0\x90\x8C\x80ss", L"\xd800\xdf00ss", "#\xF0\x90\x8C\x80ss", Component(1, 6), true}, // Escaping should be preserved unchanged, even invalid ones - {"%41%a", L"%41%a", "#%41%a", url_parse::Component(1, 5), true}, + {"%41%a", L"%41%a", "#%41%a", Component(1, 5), true}, // Invalid UTF-8/16 input should be flagged and the input made valid - {"\xc2", NULL, "#\xef\xbf\xbd", url_parse::Component(1, 3), true}, - {NULL, L"\xd800\x597d", "#\xef\xbf\xbd\xe5\xa5\xbd", url_parse::Component(1, 6), true}, + {"\xc2", NULL, "#\xef\xbf\xbd", Component(1, 3), true}, + {NULL, L"\xd800\x597d", "#\xef\xbf\xbd\xe5\xa5\xbd", Component(1, 6), true}, // Test a Unicode invalid character. - {"a\xef\xb7\x90", L"a\xfdd0", "#a\xef\xbf\xbd", url_parse::Component(1, 4), true}, + {"a\xef\xb7\x90", L"a\xfdd0", "#a\xef\xbf\xbd", Component(1, 4), true}, // Refs can have # signs and we should preserve them. - {"asdf#qwer", L"asdf#qwer", "#asdf#qwer", url_parse::Component(1, 9), true}, - {"#asdf", L"#asdf", "##asdf", url_parse::Component(1, 5), true}, + {"asdf#qwer", L"asdf#qwer", "#asdf#qwer", Component(1, 9), true}, + {"#asdf", L"#asdf", "##asdf", Component(1, 5), true}, }; for (size_t i = 0; i < arraysize(ref_cases); i++) { // 8-bit input if (ref_cases[i].input8) { int len = static_cast(strlen(ref_cases[i].input8)); - url_parse::Component in_comp(0, len); - url_parse::Component out_comp; + Component in_comp(0, len); + Component out_comp; std::string out_str; - url_canon::StdStringCanonOutput output(&out_str); - url_canon::CanonicalizeRef(ref_cases[i].input8, in_comp, - &output, &out_comp); + StdStringCanonOutput output(&out_str); + CanonicalizeRef(ref_cases[i].input8, in_comp, &output, &out_comp); output.Complete(); EXPECT_EQ(ref_cases[i].expected_component.begin, out_comp.begin); @@ -1327,12 +1321,12 @@ TEST(URLCanonTest, Ref) { if (ref_cases[i].input16) { base::string16 input16(WStringToUTF16(ref_cases[i].input16)); int len = static_cast(input16.length()); - url_parse::Component in_comp(0, len); - url_parse::Component out_comp; + Component in_comp(0, len); + Component out_comp; std::string out_str; - url_canon::StdStringCanonOutput output(&out_str); - url_canon::CanonicalizeRef(input16.c_str(), in_comp, &output, &out_comp); + StdStringCanonOutput output(&out_str); + CanonicalizeRef(input16.c_str(), in_comp, &output, &out_comp); output.Complete(); EXPECT_EQ(ref_cases[i].expected_component.begin, out_comp.begin); @@ -1343,13 +1337,12 @@ TEST(URLCanonTest, Ref) { // Try one with an embedded NULL. It should be stripped. const char null_input[5] = "ab\x00z"; - url_parse::Component null_input_component(0, 4); - url_parse::Component out_comp; + Component null_input_component(0, 4); + Component out_comp; std::string out_str; - url_canon::StdStringCanonOutput output(&out_str); - url_canon::CanonicalizeRef(null_input, null_input_component, - &output, &out_comp); + StdStringCanonOutput output(&out_str); + CanonicalizeRef(null_input, null_input_component, &output, &out_comp); output.Complete(); EXPECT_EQ(1, out_comp.begin); @@ -1406,13 +1399,13 @@ TEST(URLCanonTest, CanonicalizeStandardURL) { for (size_t i = 0; i < ARRAYSIZE(cases); i++) { int url_len = static_cast(strlen(cases[i].input)); - url_parse::Parsed parsed; - url_parse::ParseStandardURL(cases[i].input, url_len, &parsed); + Parsed parsed; + ParseStandardURL(cases[i].input, url_len, &parsed); - url_parse::Parsed out_parsed; + Parsed out_parsed; std::string out_str; - url_canon::StdStringCanonOutput output(&out_str); - bool success = url_canon::CanonicalizeStandardURL( + StdStringCanonOutput output(&out_str); + bool success = CanonicalizeStandardURL( cases[i].input, url_len, parsed, NULL, &output, &out_parsed); output.Complete(); @@ -1439,11 +1432,11 @@ TEST(URLCanonTest, ReplaceStandardURL) { for (size_t i = 0; i < arraysize(replace_cases); i++) { const ReplaceCase& cur = replace_cases[i]; int base_len = static_cast(strlen(cur.base)); - url_parse::Parsed parsed; - url_parse::ParseStandardURL(cur.base, base_len, &parsed); + Parsed parsed; + ParseStandardURL(cur.base, base_len, &parsed); - url_canon::Replacements r; - typedef url_canon::Replacements R; // Clean up syntax. + Replacements r; + typedef Replacements R; // Clean up syntax. // Note that for the scheme we pass in a different clear function since // there is no function to clear the scheme. @@ -1457,10 +1450,10 @@ TEST(URLCanonTest, ReplaceStandardURL) { SetupReplComp(&R::SetRef, &R::ClearRef, &r, cur.ref); std::string out_str; - url_canon::StdStringCanonOutput output(&out_str); - url_parse::Parsed out_parsed; - url_canon::ReplaceStandardURL(replace_cases[i].base, parsed, - r, NULL, &output, &out_parsed); + StdStringCanonOutput output(&out_str); + Parsed out_parsed; + ReplaceStandardURL(replace_cases[i].base, parsed, r, NULL, &output, + &out_parsed); output.Complete(); EXPECT_EQ(replace_cases[i].expected, out_str); @@ -1471,25 +1464,25 @@ TEST(URLCanonTest, ReplaceStandardURL) { const char src[] = "http://www.google.com/here_is_the_path"; int src_len = static_cast(strlen(src)); - url_parse::Parsed parsed; - url_parse::ParseStandardURL(src, src_len, &parsed); + Parsed parsed; + ParseStandardURL(src, src_len, &parsed); // Replace the path to 0 length string. By using 1 as the string address, // the test should get an access violation if it tries to dereference it. - url_canon::Replacements r; - r.SetPath(reinterpret_cast(0x00000001), url_parse::Component(0, 0)); + Replacements r; + r.SetPath(reinterpret_cast(0x00000001), Component(0, 0)); std::string out_str1; - url_canon::StdStringCanonOutput output1(&out_str1); - url_parse::Parsed new_parsed; - url_canon::ReplaceStandardURL(src, parsed, r, NULL, &output1, &new_parsed); + StdStringCanonOutput output1(&out_str1); + Parsed new_parsed; + ReplaceStandardURL(src, parsed, r, NULL, &output1, &new_parsed); output1.Complete(); EXPECT_STREQ("http://www.google.com/", out_str1.c_str()); // Same with an "invalid" path. - r.SetPath(reinterpret_cast(0x00000001), url_parse::Component()); + r.SetPath(reinterpret_cast(0x00000001), Component()); std::string out_str2; - url_canon::StdStringCanonOutput output2(&out_str2); - url_canon::ReplaceStandardURL(src, parsed, r, NULL, &output2, &new_parsed); + StdStringCanonOutput output2(&out_str2); + ReplaceStandardURL(src, parsed, r, NULL, &output2, &new_parsed); output2.Complete(); EXPECT_STREQ("http://www.google.com/", out_str2.c_str()); } @@ -1517,11 +1510,11 @@ TEST(URLCanonTest, ReplaceFileURL) { for (size_t i = 0; i < arraysize(replace_cases); i++) { const ReplaceCase& cur = replace_cases[i]; int base_len = static_cast(strlen(cur.base)); - url_parse::Parsed parsed; - url_parse::ParseFileURL(cur.base, base_len, &parsed); + Parsed parsed; + ParseFileURL(cur.base, base_len, &parsed); - url_canon::Replacements r; - typedef url_canon::Replacements R; // Clean up syntax. + Replacements r; + typedef Replacements R; // Clean up syntax. SetupReplComp(&R::SetScheme, &R::ClearRef, &r, cur.scheme); SetupReplComp(&R::SetUsername, &R::ClearUsername, &r, cur.username); SetupReplComp(&R::SetPassword, &R::ClearPassword, &r, cur.password); @@ -1532,10 +1525,9 @@ TEST(URLCanonTest, ReplaceFileURL) { SetupReplComp(&R::SetRef, &R::ClearRef, &r, cur.ref); std::string out_str; - url_canon::StdStringCanonOutput output(&out_str); - url_parse::Parsed out_parsed; - url_canon::ReplaceFileURL(cur.base, parsed, - r, NULL, &output, &out_parsed); + StdStringCanonOutput output(&out_str); + Parsed out_parsed; + ReplaceFileURL(cur.base, parsed, r, NULL, &output, &out_parsed); output.Complete(); EXPECT_EQ(replace_cases[i].expected, out_str); @@ -1568,11 +1560,11 @@ TEST(URLCanonTest, ReplaceFileSystemURL) { for (size_t i = 0; i < arraysize(replace_cases); i++) { const ReplaceCase& cur = replace_cases[i]; int base_len = static_cast(strlen(cur.base)); - url_parse::Parsed parsed; - url_parse::ParseFileSystemURL(cur.base, base_len, &parsed); + Parsed parsed; + ParseFileSystemURL(cur.base, base_len, &parsed); - url_canon::Replacements r; - typedef url_canon::Replacements R; // Clean up syntax. + Replacements r; + typedef Replacements R; // Clean up syntax. SetupReplComp(&R::SetScheme, &R::ClearRef, &r, cur.scheme); SetupReplComp(&R::SetUsername, &R::ClearUsername, &r, cur.username); SetupReplComp(&R::SetPassword, &R::ClearPassword, &r, cur.password); @@ -1583,10 +1575,9 @@ TEST(URLCanonTest, ReplaceFileSystemURL) { SetupReplComp(&R::SetRef, &R::ClearRef, &r, cur.ref); std::string out_str; - url_canon::StdStringCanonOutput output(&out_str); - url_parse::Parsed out_parsed; - url_canon::ReplaceFileSystemURL(cur.base, parsed, r, NULL, - &output, &out_parsed); + StdStringCanonOutput output(&out_str); + Parsed out_parsed; + ReplaceFileSystemURL(cur.base, parsed, r, NULL, &output, &out_parsed); output.Complete(); EXPECT_EQ(replace_cases[i].expected, out_str); @@ -1608,11 +1599,11 @@ TEST(URLCanonTest, ReplacePathURL) { for (size_t i = 0; i < arraysize(replace_cases); i++) { const ReplaceCase& cur = replace_cases[i]; int base_len = static_cast(strlen(cur.base)); - url_parse::Parsed parsed; - url_parse::ParsePathURL(cur.base, base_len, false, &parsed); + Parsed parsed; + ParsePathURL(cur.base, base_len, false, &parsed); - url_canon::Replacements r; - typedef url_canon::Replacements R; // Clean up syntax. + Replacements r; + typedef Replacements R; // Clean up syntax. SetupReplComp(&R::SetScheme, &R::ClearRef, &r, cur.scheme); SetupReplComp(&R::SetUsername, &R::ClearUsername, &r, cur.username); SetupReplComp(&R::SetPassword, &R::ClearPassword, &r, cur.password); @@ -1623,10 +1614,9 @@ TEST(URLCanonTest, ReplacePathURL) { SetupReplComp(&R::SetRef, &R::ClearRef, &r, cur.ref); std::string out_str; - url_canon::StdStringCanonOutput output(&out_str); - url_parse::Parsed out_parsed; - url_canon::ReplacePathURL(cur.base, parsed, - r, &output, &out_parsed); + StdStringCanonOutput output(&out_str); + Parsed out_parsed; + ReplacePathURL(cur.base, parsed, r, &output, &out_parsed); output.Complete(); EXPECT_EQ(replace_cases[i].expected, out_str); @@ -1660,11 +1650,11 @@ TEST(URLCanonTest, ReplaceMailtoURL) { for (size_t i = 0; i < arraysize(replace_cases); i++) { const ReplaceCase& cur = replace_cases[i]; int base_len = static_cast(strlen(cur.base)); - url_parse::Parsed parsed; - url_parse::ParseMailtoURL(cur.base, base_len, &parsed); + Parsed parsed; + ParseMailtoURL(cur.base, base_len, &parsed); - url_canon::Replacements r; - typedef url_canon::Replacements R; + Replacements r; + typedef Replacements R; SetupReplComp(&R::SetScheme, &R::ClearRef, &r, cur.scheme); SetupReplComp(&R::SetUsername, &R::ClearUsername, &r, cur.username); SetupReplComp(&R::SetPassword, &R::ClearPassword, &r, cur.password); @@ -1675,10 +1665,9 @@ TEST(URLCanonTest, ReplaceMailtoURL) { SetupReplComp(&R::SetRef, &R::ClearRef, &r, cur.ref); std::string out_str; - url_canon::StdStringCanonOutput output(&out_str); - url_parse::Parsed out_parsed; - url_canon::ReplaceMailtoURL(cur.base, parsed, - r, &output, &out_parsed); + StdStringCanonOutput output(&out_str); + Parsed out_parsed; + ReplaceMailtoURL(cur.base, parsed, r, &output, &out_parsed); output.Complete(); EXPECT_EQ(replace_cases[i].expected, out_str); @@ -1690,74 +1679,73 @@ TEST(URLCanonTest, CanonicalizeFileURL) { const char* input; const char* expected; bool expected_success; - url_parse::Component expected_host; - url_parse::Component expected_path; + Component expected_host; + Component expected_path; } cases[] = { #ifdef _WIN32 // Windows-style paths - {"file:c:\\foo\\bar.html", "file:///C:/foo/bar.html", true, url_parse::Component(), url_parse::Component(7, 16)}, - {" File:c|////foo\\bar.html", "file:///C:////foo/bar.html", true, url_parse::Component(), url_parse::Component(7, 19)}, - {"file:", "file:///", true, url_parse::Component(), url_parse::Component(7, 1)}, - {"file:UNChost/path", "file://unchost/path", true, url_parse::Component(7, 7), url_parse::Component(14, 5)}, + {"file:c:\\foo\\bar.html", "file:///C:/foo/bar.html", true, Component(), Component(7, 16)}, + {" File:c|////foo\\bar.html", "file:///C:////foo/bar.html", true, Component(), Component(7, 19)}, + {"file:", "file:///", true, Component(), Component(7, 1)}, + {"file:UNChost/path", "file://unchost/path", true, Component(7, 7), Component(14, 5)}, // CanonicalizeFileURL supports absolute Windows style paths for IE // compatability. Note that the caller must decide that this is a file // URL itself so it can call the file canonicalizer. This is usually // done automatically as part of relative URL resolving. - {"c:\\foo\\bar", "file:///C:/foo/bar", true, url_parse::Component(), url_parse::Component(7, 11)}, - {"C|/foo/bar", "file:///C:/foo/bar", true, url_parse::Component(), url_parse::Component(7, 11)}, - {"/C|\\foo\\bar", "file:///C:/foo/bar", true, url_parse::Component(), url_parse::Component(7, 11)}, - {"//C|/foo/bar", "file:///C:/foo/bar", true, url_parse::Component(), url_parse::Component(7, 11)}, - {"//server/file", "file://server/file", true, url_parse::Component(7, 6), url_parse::Component(13, 5)}, - {"\\\\server\\file", "file://server/file", true, url_parse::Component(7, 6), url_parse::Component(13, 5)}, - {"/\\server/file", "file://server/file", true, url_parse::Component(7, 6), url_parse::Component(13, 5)}, + {"c:\\foo\\bar", "file:///C:/foo/bar", true, Component(), Component(7, 11)}, + {"C|/foo/bar", "file:///C:/foo/bar", true, Component(), Component(7, 11)}, + {"/C|\\foo\\bar", "file:///C:/foo/bar", true, Component(), Component(7, 11)}, + {"//C|/foo/bar", "file:///C:/foo/bar", true, Component(), Component(7, 11)}, + {"//server/file", "file://server/file", true, Component(7, 6), Component(13, 5)}, + {"\\\\server\\file", "file://server/file", true, Component(7, 6), Component(13, 5)}, + {"/\\server/file", "file://server/file", true, Component(7, 6), Component(13, 5)}, // We should preserve the number of slashes after the colon for IE // compatability, except when there is none, in which case we should // add one. - {"file:c:foo/bar.html", "file:///C:/foo/bar.html", true, url_parse::Component(), url_parse::Component(7, 16)}, - {"file:/\\/\\C:\\\\//foo\\bar.html", "file:///C:////foo/bar.html", true, url_parse::Component(), url_parse::Component(7, 19)}, + {"file:c:foo/bar.html", "file:///C:/foo/bar.html", true, Component(), Component(7, 16)}, + {"file:/\\/\\C:\\\\//foo\\bar.html", "file:///C:////foo/bar.html", true, Component(), Component(7, 19)}, // Three slashes should be non-UNC, even if there is no drive spec (IE // does this, which makes the resulting request invalid). - {"file:///foo/bar.txt", "file:///foo/bar.txt", true, url_parse::Component(), url_parse::Component(7, 12)}, + {"file:///foo/bar.txt", "file:///foo/bar.txt", true, Component(), Component(7, 12)}, // TODO(brettw) we should probably fail for invalid host names, which // would change the expected result on this test. We also currently allow // colon even though it's probably invalid, because its currently the // "natural" result of the way the canonicalizer is written. There doesn't // seem to be a strong argument for why allowing it here would be bad, so // we just tolerate it and the load will fail later. - {"FILE:/\\/\\7:\\\\//foo\\bar.html", "file://7:////foo/bar.html", false, url_parse::Component(7, 2), url_parse::Component(9, 16)}, - {"file:filer/home\\me", "file://filer/home/me", true, url_parse::Component(7, 5), url_parse::Component(12, 8)}, + {"FILE:/\\/\\7:\\\\//foo\\bar.html", "file://7:////foo/bar.html", false, Component(7, 2), Component(9, 16)}, + {"file:filer/home\\me", "file://filer/home/me", true, Component(7, 5), Component(12, 8)}, // Make sure relative paths can't go above the "C:" - {"file:///C:/foo/../../../bar.html", "file:///C:/bar.html", true, url_parse::Component(), url_parse::Component(7, 12)}, + {"file:///C:/foo/../../../bar.html", "file:///C:/bar.html", true, Component(), Component(7, 12)}, // Busted refs shouldn't make the whole thing fail. - {"file:///C:/asdf#\xc2", "file:///C:/asdf#\xef\xbf\xbd", true, url_parse::Component(), url_parse::Component(7, 8)}, + {"file:///C:/asdf#\xc2", "file:///C:/asdf#\xef\xbf\xbd", true, Component(), Component(7, 8)}, #else // Unix-style paths - {"file:///home/me", "file:///home/me", true, url_parse::Component(), url_parse::Component(7, 8)}, + {"file:///home/me", "file:///home/me", true, Component(), Component(7, 8)}, // Windowsy ones should get still treated as Unix-style. - {"file:c:\\foo\\bar.html", "file:///c:/foo/bar.html", true, url_parse::Component(), url_parse::Component(7, 16)}, - {"file:c|//foo\\bar.html", "file:///c%7C//foo/bar.html", true, url_parse::Component(), url_parse::Component(7, 19)}, + {"file:c:\\foo\\bar.html", "file:///c:/foo/bar.html", true, Component(), Component(7, 16)}, + {"file:c|//foo\\bar.html", "file:///c%7C//foo/bar.html", true, Component(), Component(7, 19)}, // file: tests from WebKit (LayoutTests/fast/loader/url-parse-1.html) - {"//", "file:///", true, url_parse::Component(), url_parse::Component(7, 1)}, - {"///", "file:///", true, url_parse::Component(), url_parse::Component(7, 1)}, - {"///test", "file:///test", true, url_parse::Component(), url_parse::Component(7, 5)}, - {"file://test", "file://test/", true, url_parse::Component(7, 4), url_parse::Component(11, 1)}, - {"file://localhost", "file://localhost/", true, url_parse::Component(7, 9), url_parse::Component(16, 1)}, - {"file://localhost/", "file://localhost/", true, url_parse::Component(7, 9), url_parse::Component(16, 1)}, - {"file://localhost/test", "file://localhost/test", true, url_parse::Component(7, 9), url_parse::Component(16, 5)}, + {"//", "file:///", true, Component(), Component(7, 1)}, + {"///", "file:///", true, Component(), Component(7, 1)}, + {"///test", "file:///test", true, Component(), Component(7, 5)}, + {"file://test", "file://test/", true, Component(7, 4), Component(11, 1)}, + {"file://localhost", "file://localhost/", true, Component(7, 9), Component(16, 1)}, + {"file://localhost/", "file://localhost/", true, Component(7, 9), Component(16, 1)}, + {"file://localhost/test", "file://localhost/test", true, Component(7, 9), Component(16, 5)}, #endif // _WIN32 }; for (size_t i = 0; i < ARRAYSIZE(cases); i++) { int url_len = static_cast(strlen(cases[i].input)); - url_parse::Parsed parsed; - url_parse::ParseFileURL(cases[i].input, url_len, &parsed); + Parsed parsed; + ParseFileURL(cases[i].input, url_len, &parsed); - url_parse::Parsed out_parsed; + Parsed out_parsed; std::string out_str; - url_canon::StdStringCanonOutput output(&out_str); - bool success = url_canon::CanonicalizeFileURL(cases[i].input, url_len, - parsed, NULL, &output, - &out_parsed); + StdStringCanonOutput output(&out_str); + bool success = CanonicalizeFileURL(cases[i].input, url_len, parsed, NULL, + &output, &out_parsed); output.Complete(); EXPECT_EQ(cases[i].expected_success, success); @@ -1793,15 +1781,14 @@ TEST(URLCanonTest, CanonicalizeFileSystemURL) { for (size_t i = 0; i < ARRAYSIZE(cases); i++) { int url_len = static_cast(strlen(cases[i].input)); - url_parse::Parsed parsed; - url_parse::ParseFileSystemURL(cases[i].input, url_len, &parsed); + Parsed parsed; + ParseFileSystemURL(cases[i].input, url_len, &parsed); - url_parse::Parsed out_parsed; + Parsed out_parsed; std::string out_str; - url_canon::StdStringCanonOutput output(&out_str); - bool success = url_canon::CanonicalizeFileSystemURL(cases[i].input, url_len, - parsed, NULL, &output, - &out_parsed); + StdStringCanonOutput output(&out_str); + bool success = CanonicalizeFileSystemURL(cases[i].input, url_len, parsed, + NULL, &output, &out_parsed); output.Complete(); EXPECT_EQ(cases[i].expected_success, success); @@ -1829,15 +1816,14 @@ TEST(URLCanonTest, CanonicalizePathURL) { for (size_t i = 0; i < ARRAYSIZE(path_cases); i++) { int url_len = static_cast(strlen(path_cases[i].input)); - url_parse::Parsed parsed; - url_parse::ParsePathURL(path_cases[i].input, url_len, true, &parsed); + Parsed parsed; + ParsePathURL(path_cases[i].input, url_len, true, &parsed); - url_parse::Parsed out_parsed; + Parsed out_parsed; std::string out_str; - url_canon::StdStringCanonOutput output(&out_str); - bool success = url_canon::CanonicalizePathURL(path_cases[i].input, url_len, - parsed, &output, - &out_parsed); + StdStringCanonOutput output(&out_str); + bool success = CanonicalizePathURL(path_cases[i].input, url_len, parsed, + &output, &out_parsed); output.Complete(); EXPECT_TRUE(success); @@ -1859,28 +1845,28 @@ TEST(URLCanonTest, CanonicalizeMailtoURL) { const char* input; const char* expected; bool expected_success; - url_parse::Component expected_path; - url_parse::Component expected_query; + Component expected_path; + Component expected_query; } cases[] = { - {"mailto:addr1", "mailto:addr1", true, url_parse::Component(7, 5), url_parse::Component()}, - {"mailto:addr1@foo.com", "mailto:addr1@foo.com", true, url_parse::Component(7, 13), url_parse::Component()}, + {"mailto:addr1", "mailto:addr1", true, Component(7, 5), Component()}, + {"mailto:addr1@foo.com", "mailto:addr1@foo.com", true, Component(7, 13), Component()}, // Trailing whitespace is stripped. - {"MaIlTo:addr1 \t ", "mailto:addr1", true, url_parse::Component(7, 5), url_parse::Component()}, - {"MaIlTo:addr1?to=jon", "mailto:addr1?to=jon", true, url_parse::Component(7, 5), url_parse::Component(13,6)}, - {"mailto:addr1,addr2", "mailto:addr1,addr2", true, url_parse::Component(7, 11), url_parse::Component()}, - {"mailto:addr1, addr2", "mailto:addr1, addr2", true, url_parse::Component(7, 12), url_parse::Component()}, - {"mailto:addr1%2caddr2", "mailto:addr1%2caddr2", true, url_parse::Component(7, 13), url_parse::Component()}, - {"mailto:\xF0\x90\x8C\x80", "mailto:%F0%90%8C%80", true, url_parse::Component(7, 12), url_parse::Component()}, + {"MaIlTo:addr1 \t ", "mailto:addr1", true, Component(7, 5), Component()}, + {"MaIlTo:addr1?to=jon", "mailto:addr1?to=jon", true, Component(7, 5), Component(13,6)}, + {"mailto:addr1,addr2", "mailto:addr1,addr2", true, Component(7, 11), Component()}, + {"mailto:addr1, addr2", "mailto:addr1, addr2", true, Component(7, 12), Component()}, + {"mailto:addr1%2caddr2", "mailto:addr1%2caddr2", true, Component(7, 13), Component()}, + {"mailto:\xF0\x90\x8C\x80", "mailto:%F0%90%8C%80", true, Component(7, 12), Component()}, // Null character should be escaped to %00 - {"mailto:addr1\0addr2?foo", "mailto:addr1%00addr2?foo", true, url_parse::Component(7, 13), url_parse::Component(21, 3)}, + {"mailto:addr1\0addr2?foo", "mailto:addr1%00addr2?foo", true, Component(7, 13), Component(21, 3)}, // Invalid -- UTF-8 encoded surrogate value. - {"mailto:\xed\xa0\x80", "mailto:%EF%BF%BD", false, url_parse::Component(7, 9), url_parse::Component()}, - {"mailto:addr1?", "mailto:addr1?", true, url_parse::Component(7, 5), url_parse::Component(13, 0)}, + {"mailto:\xed\xa0\x80", "mailto:%EF%BF%BD", false, Component(7, 9), Component()}, + {"mailto:addr1?", "mailto:addr1?", true, Component(7, 5), Component(13, 0)}, }; // Define outside of loop to catch bugs where components aren't reset - url_parse::Parsed parsed; - url_parse::Parsed out_parsed; + Parsed parsed; + Parsed out_parsed; for (size_t i = 0; i < ARRAYSIZE(cases); i++) { int url_len = static_cast(strlen(cases[i].input)); @@ -1889,13 +1875,12 @@ TEST(URLCanonTest, CanonicalizeMailtoURL) { // as the string terminator. url_len = 22; } - url_parse::ParseMailtoURL(cases[i].input, url_len, &parsed); + ParseMailtoURL(cases[i].input, url_len, &parsed); std::string out_str; - url_canon::StdStringCanonOutput output(&out_str); - bool success = url_canon::CanonicalizeMailtoURL(cases[i].input, url_len, - parsed, &output, - &out_parsed); + StdStringCanonOutput output(&out_str); + bool success = CanonicalizeMailtoURL(cases[i].input, url_len, parsed, + &output, &out_parsed); output.Complete(); EXPECT_EQ(cases[i].expected_success, success); @@ -1921,35 +1906,35 @@ TEST(URLCanonTest, _itoa_s) { // _itoa_s about, and ensure that the extra byte is untouched. char buf[6]; memset(buf, 0xff, sizeof(buf)); - EXPECT_EQ(0, url_canon::_itoa_s(12, buf, sizeof(buf) - 1, 10)); + EXPECT_EQ(0, _itoa_s(12, buf, sizeof(buf) - 1, 10)); EXPECT_STREQ("12", buf); EXPECT_EQ('\xFF', buf[3]); // Test the edge cases - exactly the buffer size and one over memset(buf, 0xff, sizeof(buf)); - EXPECT_EQ(0, url_canon::_itoa_s(1234, buf, sizeof(buf) - 1, 10)); + EXPECT_EQ(0, _itoa_s(1234, buf, sizeof(buf) - 1, 10)); EXPECT_STREQ("1234", buf); EXPECT_EQ('\xFF', buf[5]); memset(buf, 0xff, sizeof(buf)); - EXPECT_EQ(EINVAL, url_canon::_itoa_s(12345, buf, sizeof(buf) - 1, 10)); + EXPECT_EQ(EINVAL, _itoa_s(12345, buf, sizeof(buf) - 1, 10)); EXPECT_EQ('\xFF', buf[5]); // should never write to this location // Test the template overload (note that this will see the full buffer) memset(buf, 0xff, sizeof(buf)); - EXPECT_EQ(0, url_canon::_itoa_s(12, buf, 10)); + EXPECT_EQ(0, _itoa_s(12, buf, 10)); EXPECT_STREQ("12", buf); EXPECT_EQ('\xFF', buf[3]); memset(buf, 0xff, sizeof(buf)); - EXPECT_EQ(0, url_canon::_itoa_s(12345, buf, 10)); + EXPECT_EQ(0, _itoa_s(12345, buf, 10)); EXPECT_STREQ("12345", buf); - EXPECT_EQ(EINVAL, url_canon::_itoa_s(123456, buf, 10)); + EXPECT_EQ(EINVAL, _itoa_s(123456, buf, 10)); // Test that radix 16 is supported. memset(buf, 0xff, sizeof(buf)); - EXPECT_EQ(0, url_canon::_itoa_s(1234, buf, sizeof(buf) - 1, 16)); + EXPECT_EQ(0, _itoa_s(1234, buf, sizeof(buf) - 1, 16)); EXPECT_STREQ("4d2", buf); EXPECT_EQ('\xFF', buf[5]); } @@ -1962,37 +1947,36 @@ TEST(URLCanonTest, _itow_s) { const char fill_mem = 0xff; const base::char16 fill_char = 0xffff; memset(buf, fill_mem, sizeof(buf)); - EXPECT_EQ(0, url_canon::_itow_s(12, buf, sizeof(buf) / 2 - 1, 10)); + EXPECT_EQ(0, _itow_s(12, buf, sizeof(buf) / 2 - 1, 10)); EXPECT_EQ(WStringToUTF16(L"12"), base::string16(buf)); EXPECT_EQ(fill_char, buf[3]); // Test the edge cases - exactly the buffer size and one over - EXPECT_EQ(0, url_canon::_itow_s(1234, buf, sizeof(buf) / 2 - 1, 10)); + EXPECT_EQ(0, _itow_s(1234, buf, sizeof(buf) / 2 - 1, 10)); EXPECT_EQ(WStringToUTF16(L"1234"), base::string16(buf)); EXPECT_EQ(fill_char, buf[5]); memset(buf, fill_mem, sizeof(buf)); - EXPECT_EQ(EINVAL, url_canon::_itow_s(12345, buf, sizeof(buf) / 2 - 1, 10)); + EXPECT_EQ(EINVAL, _itow_s(12345, buf, sizeof(buf) / 2 - 1, 10)); EXPECT_EQ(fill_char, buf[5]); // should never write to this location // Test the template overload (note that this will see the full buffer) memset(buf, fill_mem, sizeof(buf)); - EXPECT_EQ(0, url_canon::_itow_s(12, buf, 10)); + EXPECT_EQ(0, _itow_s(12, buf, 10)); EXPECT_EQ(WStringToUTF16(L"12"), base::string16(buf)); EXPECT_EQ(fill_char, buf[3]); memset(buf, fill_mem, sizeof(buf)); - EXPECT_EQ(0, url_canon::_itow_s(12345, buf, 10)); + EXPECT_EQ(0, _itow_s(12345, buf, 10)); EXPECT_EQ(WStringToUTF16(L"12345"), base::string16(buf)); - EXPECT_EQ(EINVAL, url_canon::_itow_s(123456, buf, 10)); + EXPECT_EQ(EINVAL, _itow_s(123456, buf, 10)); } #endif // !WIN32 // Returns true if the given two structures are the same. -static bool ParsedIsEqual(const url_parse::Parsed& a, - const url_parse::Parsed& b) { +static bool ParsedIsEqual(const Parsed& a, const Parsed& b) { return a.scheme.begin == b.scheme.begin && a.scheme.len == b.scheme.len && a.username.begin == b.username.begin && a.username.len == b.username.len && a.password.begin == b.password.begin && a.password.len == b.password.len && @@ -2150,20 +2134,20 @@ TEST(URLCanonTest, ResolveRelativeURL) { for (size_t i = 0; i < ARRAYSIZE(rel_cases); i++) { const RelativeCase& cur_case = rel_cases[i]; - url_parse::Parsed parsed; + Parsed parsed; int base_len = static_cast(strlen(cur_case.base)); if (cur_case.is_base_file) - url_parse::ParseFileURL(cur_case.base, base_len, &parsed); + ParseFileURL(cur_case.base, base_len, &parsed); else if (cur_case.is_base_hier) - url_parse::ParseStandardURL(cur_case.base, base_len, &parsed); + ParseStandardURL(cur_case.base, base_len, &parsed); else - url_parse::ParsePathURL(cur_case.base, base_len, false, &parsed); + ParsePathURL(cur_case.base, base_len, false, &parsed); // First see if it is relative. int test_len = static_cast(strlen(cur_case.test)); bool is_relative; - url_parse::Component relative_component; - bool succeed_is_rel = url_canon::IsRelativeURL( + Component relative_component; + bool succeed_is_rel = IsRelativeURL( cur_case.base, parsed, cur_case.test, test_len, cur_case.is_base_hier, &is_relative, &relative_component); @@ -2174,12 +2158,12 @@ TEST(URLCanonTest, ResolveRelativeURL) { // Now resolve it. if (succeed_is_rel && is_relative && cur_case.is_rel) { std::string resolved; - url_canon::StdStringCanonOutput output(&resolved); - url_parse::Parsed resolved_parsed; + StdStringCanonOutput output(&resolved); + Parsed resolved_parsed; - bool succeed_resolve = url_canon::ResolveRelativeURL( - cur_case.base, parsed, cur_case.is_base_file, - cur_case.test, relative_component, NULL, &output, &resolved_parsed); + bool succeed_resolve = ResolveRelativeURL( + cur_case.base, parsed, cur_case.is_base_file, cur_case.test, + relative_component, NULL, &output, &resolved_parsed); output.Complete(); EXPECT_EQ(cur_case.succeed_resolve, succeed_resolve); @@ -2187,16 +2171,14 @@ TEST(URLCanonTest, ResolveRelativeURL) { // Verify that the output parsed structure is the same as parsing a // the URL freshly. - url_parse::Parsed ref_parsed; + Parsed ref_parsed; int resolved_len = static_cast(resolved.size()); if (cur_case.is_base_file) { - url_parse::ParseFileURL(resolved.c_str(), resolved_len, &ref_parsed); + ParseFileURL(resolved.c_str(), resolved_len, &ref_parsed); } else if (cur_case.is_base_hier) { - url_parse::ParseStandardURL(resolved.c_str(), resolved_len, - &ref_parsed); + ParseStandardURL(resolved.c_str(), resolved_len, &ref_parsed); } else { - url_parse::ParsePathURL(resolved.c_str(), resolved_len, false, - &ref_parsed); + ParsePathURL(resolved.c_str(), resolved_len, false, &ref_parsed); } EXPECT_TRUE(ParsedIsEqual(ref_parsed, resolved_parsed)); } @@ -2210,28 +2192,28 @@ TEST(URLCanonTest, ResolveRelativeURL) { TEST(URLCanonTest, ReplacementOverflow) { const char src[] = "file:///C:/foo/bar"; int src_len = static_cast(strlen(src)); - url_parse::Parsed parsed; - url_parse::ParseFileURL(src, src_len, &parsed); + Parsed parsed; + ParseFileURL(src, src_len, &parsed); // Override two components, the path with something short, and the query with // sonething long enough to trigger the bug. - url_canon::Replacements repl; + Replacements repl; base::string16 new_query; for (int i = 0; i < 4800; i++) new_query.push_back('a'); base::string16 new_path(WStringToUTF16(L"/foo")); - repl.SetPath(new_path.c_str(), url_parse::Component(0, 4)); + repl.SetPath(new_path.c_str(), Component(0, 4)); repl.SetQuery(new_query.c_str(), - url_parse::Component(0, static_cast(new_query.length()))); + Component(0, static_cast(new_query.length()))); // Call ReplaceComponents on the string. It doesn't matter if we call it for // standard URLs, file URLs, etc, since they will go to the same replacement // function that was buggy. - url_parse::Parsed repl_parsed; + Parsed repl_parsed; std::string repl_str; - url_canon::StdStringCanonOutput repl_output(&repl_str); - url_canon::ReplaceFileURL(src, parsed, repl, NULL, &repl_output, &repl_parsed); + StdStringCanonOutput repl_output(&repl_str); + ReplaceFileURL(src, parsed, repl, NULL, &repl_output, &repl_parsed); repl_output.Complete(); // Generate the expected string and check. @@ -2240,3 +2222,5 @@ TEST(URLCanonTest, ReplacementOverflow) { expected.push_back('a'); EXPECT_TRUE(expected == repl_str); } + +} // namespace url diff --git a/url/url_export.h b/url/url_export.h index 15ef19e23d89..177ec284d5e0 100644 --- a/url/url_export.h +++ b/url/url_export.h @@ -30,4 +30,11 @@ #endif // define(COMPONENT_BUILD) +// TODO(vitalybuka, crbug.com/364747) url_util is deprecated, remove after +// fixing depending code. +namespace url {} +namespace url_util = ::url; +namespace url_parse = ::url; +namespace url_canon = ::url; + #endif // URL_URL_EXPORT_H_ diff --git a/url/url_file.h b/url/url_file.h index f81c21fa8173..540cb2543eb8 100644 --- a/url/url_file.h +++ b/url/url_file.h @@ -10,7 +10,7 @@ #include "url/url_parse_internal.h" -namespace url_parse { +namespace url { #ifdef WIN32 @@ -78,6 +78,6 @@ inline bool DoesBeginUNCPath(const CHAR* text, #endif // WIN32 -} // namespace url_parse +} // namespace url #endif // URL_URL_FILE_H_ diff --git a/url/url_parse_file.cc b/url/url_parse_file.cc index a2f7ce3f5113..c08ddc680717 100644 --- a/url/url_parse_file.cc +++ b/url/url_parse_file.cc @@ -38,7 +38,7 @@ // it looks like an absolute drive path. Also, slashes and backslashes are // equally valid here. -namespace url_parse { +namespace url { namespace { @@ -219,4 +219,4 @@ void ParseFileURL(const base::char16* url, int url_len, Parsed* parsed) { DoParseFileURL(url, url_len, parsed); } -} // namespace url_parse +} // namespace url diff --git a/url/url_parse_internal.h b/url/url_parse_internal.h index e61379ceb1bb..4070b7e071e5 100644 --- a/url/url_parse_internal.h +++ b/url/url_parse_internal.h @@ -9,7 +9,7 @@ #include "url/url_parse.h" -namespace url_parse { +namespace url { // We treat slashes and backslashes the same for IE compatability. inline bool IsURLSlash(base::char16 ch) { @@ -86,6 +86,6 @@ void ParseAfterScheme(const base::char16* spec, int after_scheme, Parsed* parsed); -} // namespace url_parse +} // namespace url #endif // URL_URL_PARSE_INTERNAL_H_ diff --git a/url/url_parse_unittest.cc b/url/url_parse_unittest.cc index f080fb585db1..a8b7f8541ef1 100644 --- a/url/url_parse_unittest.cc +++ b/url/url_parse_unittest.cc @@ -45,7 +45,7 @@ // it looks like an absolute drive path. Also, slashes and backslashes are // equally valid here. -namespace url_parse { +namespace url { namespace { // Used for regular URL parse cases. @@ -96,7 +96,7 @@ struct FileSystemURLParseCase { bool ComponentMatches(const char* input, const char* reference, - const url_parse::Component& component) { + const Component& component) { // If the component is nonexistant (length == -1), it should begin at 0. EXPECT_TRUE(component.len >= 0 || component.len == -1); @@ -116,7 +116,7 @@ bool ComponentMatches(const char* input, return strncmp(reference, &input[component.begin], component.len) == 0; } -void ExpectInvalidComponent(const url_parse::Component& component) { +void ExpectInvalidComponent(const Component& component) { EXPECT_EQ(0, component.begin); EXPECT_EQ(-1, component.len); } @@ -145,8 +145,8 @@ TEST(URLParser, Length) { for (size_t i = 0; i < arraysize(length_cases); i++) { int true_length = static_cast(strlen(length_cases[i])); - url_parse::Parsed parsed; - url_parse::ParseStandardURL(length_cases[i], true_length, &parsed); + Parsed parsed; + ParseStandardURL(length_cases[i], true_length, &parsed); EXPECT_EQ(true_length, parsed.Length()); } @@ -205,11 +205,11 @@ TEST(URLParser, CountCharactersBefore) { int length = static_cast(strlen(count_cases[i].url)); // Simple test to distinguish file and standard URLs. - url_parse::Parsed parsed; + Parsed parsed; if (length > 0 && count_cases[i].url[0] == 'f') - url_parse::ParseFileURL(count_cases[i].url, length, &parsed); + ParseFileURL(count_cases[i].url, length, &parsed); else - url_parse::ParseStandardURL(count_cases[i].url, length, &parsed); + ParseStandardURL(count_cases[i].url, length, &parsed); int chars_before = parsed.CountCharactersBefore( count_cases[i].component, count_cases[i].include_delimiter); @@ -318,11 +318,11 @@ static URLParseCase cases[] = { TEST(URLParser, Standard) { // Declared outside for loop to try to catch cases in init() where we forget // to reset something that is reset by the constructor. - url_parse::Parsed parsed; + Parsed parsed; for (size_t i = 0; i < arraysize(cases); i++) { const char* url = cases[i].input; - url_parse::ParseStandardURL(url, static_cast(strlen(url)), &parsed); - int port = url_parse::ParsePort(url, parsed.port); + ParseStandardURL(url, static_cast(strlen(url)), &parsed); + int port = ParsePort(url, parsed.port); EXPECT_TRUE(ComponentMatches(url, cases[i].scheme, parsed.scheme)); EXPECT_TRUE(ComponentMatches(url, cases[i].username, parsed.username)); @@ -353,10 +353,10 @@ static PathURLParseCase path_cases[] = { TEST(URLParser, PathURL) { // Declared outside for loop to try to catch cases in init() where we forget // to reset something that is reset by the construtor. - url_parse::Parsed parsed; + Parsed parsed; for (size_t i = 0; i < arraysize(path_cases); i++) { const char* url = path_cases[i].input; - url_parse::ParsePathURL(url, static_cast(strlen(url)), false, &parsed); + ParsePathURL(url, static_cast(strlen(url)), false, &parsed); EXPECT_TRUE(ComponentMatches(url, path_cases[i].scheme, parsed.scheme)) << i; @@ -452,11 +452,11 @@ static URLParseCase file_cases[] = { TEST(URLParser, ParseFileURL) { // Declared outside for loop to try to catch cases in init() where we forget // to reset something that is reset by the construtor. - url_parse::Parsed parsed; + Parsed parsed; for (size_t i = 0; i < arraysize(file_cases); i++) { const char* url = file_cases[i].input; - url_parse::ParseFileURL(url, static_cast(strlen(url)), &parsed); - int port = url_parse::ParsePort(url, parsed.port); + ParseFileURL(url, static_cast(strlen(url)), &parsed); + int port = ParsePort(url, parsed.port); EXPECT_TRUE(ComponentMatches(url, file_cases[i].scheme, parsed.scheme)) << " for case #" << i << " [" << url << "] " @@ -513,11 +513,11 @@ TEST(URLParser, ExtractFileName) { const char* url = file_cases[i].input; int len = static_cast(strlen(url)); - url_parse::Parsed parsed; - url_parse::ParseStandardURL(url, len, &parsed); + Parsed parsed; + ParseStandardURL(url, len, &parsed); - url_parse::Component file_name; - url_parse::ExtractFileName(url, parsed.path, &file_name); + Component file_name; + ExtractFileName(url, parsed.path, &file_name); EXPECT_TRUE(ComponentMatches(url, file_cases[i].expected, file_name)); } @@ -530,14 +530,14 @@ static bool NthParameterIs(const char* url, int parameter, const char* expected_key, const char* expected_value) { - url_parse::Parsed parsed; - url_parse::ParseStandardURL(url, static_cast(strlen(url)), &parsed); + Parsed parsed; + ParseStandardURL(url, static_cast(strlen(url)), &parsed); - url_parse::Component query = parsed.query; + Component query = parsed.query; for (int i = 1; i <= parameter; i++) { - url_parse::Component key, value; - if (!url_parse::ExtractQueryKeyValue(url, &query, &key, &value)) { + Component key, value; + if (!ExtractQueryKeyValue(url, &query, &key, &value)) { if (parameter >= i && !expected_key) return true; // Expected nonexistant key, got one. return false; // Not enough keys. @@ -616,16 +616,16 @@ static MailtoURLParseCase mailto_cases[] = { TEST(URLParser, MailtoUrl) { // Declared outside for loop to try to catch cases in init() where we forget // to reset something that is reset by the construtor. - url_parse::Parsed parsed; + Parsed parsed; for (size_t i = 0; i < arraysize(mailto_cases); ++i) { const char* url = mailto_cases[i].input; - url_parse::ParseMailtoURL(url, static_cast(strlen(url)), &parsed); - int port = url_parse::ParsePort(url, parsed.port); + ParseMailtoURL(url, static_cast(strlen(url)), &parsed); + int port = ParsePort(url, parsed.port); EXPECT_TRUE(ComponentMatches(url, mailto_cases[i].scheme, parsed.scheme)); EXPECT_TRUE(ComponentMatches(url, mailto_cases[i].path, parsed.path)); EXPECT_TRUE(ComponentMatches(url, mailto_cases[i].query, parsed.query)); - EXPECT_EQ(url_parse::PORT_UNSPECIFIED, port); + EXPECT_EQ(PORT_UNSPECIFIED, port); // The remaining components are never used for mailto urls. ExpectInvalidComponent(parsed.username); @@ -648,11 +648,11 @@ static FileSystemURLParseCase filesystem_cases[] = { TEST(URLParser, FileSystemURL) { // Declared outside for loop to try to catch cases in init() where we forget // to reset something that is reset by the construtor. - url_parse::Parsed parsed; + Parsed parsed; for (size_t i = 0; i < arraysize(filesystem_cases); i++) { const FileSystemURLParseCase* parsecase = &filesystem_cases[i]; const char* url = parsecase->input; - url_parse::ParseFileSystemURL(url, static_cast(strlen(url)), &parsed); + ParseFileSystemURL(url, static_cast(strlen(url)), &parsed); EXPECT_TRUE(ComponentMatches(url, "filesystem", parsed.scheme)); EXPECT_EQ(!parsecase->inner_scheme, !parsed.inner_parsed()); @@ -666,7 +666,7 @@ TEST(URLParser, FileSystemURL) { parsed.inner_parsed()->password)); EXPECT_TRUE(ComponentMatches(url, parsecase->inner_host, parsed.inner_parsed()->host)); - int port = url_parse::ParsePort(url, parsed.inner_parsed()->port); + int port = ParsePort(url, parsed.inner_parsed()->port); EXPECT_EQ(parsecase->inner_port, port); // The remaining components are never used for filesystem urls. @@ -687,4 +687,4 @@ TEST(URLParser, FileSystemURL) { } } // namespace -} // namespace url_parse +} // namespace url diff --git a/url/url_test_utils.h b/url/url_test_utils.h index 64b4acbeaf33..6400bac7d428 100644 --- a/url/url_test_utils.h +++ b/url/url_test_utils.h @@ -14,7 +14,9 @@ #include "testing/gtest/include/gtest/gtest.h" #include "url/url_canon_internal.h" -namespace url_test_utils { +namespace url { + +namespace test_utils { // Converts a UTF-16 string from native wchar_t format to char16, by // truncating the high 32 bits. This is not meant to handle true UTF-32 @@ -32,22 +34,23 @@ inline base::string16 WStringToUTF16(const wchar_t* src) { inline base::string16 ConvertUTF8ToUTF16(const std::string& src) { int length = static_cast(src.length()); EXPECT_LT(length, 1024); - url_canon::RawCanonOutputW<1024> output; - EXPECT_TRUE(url_canon::ConvertUTF8ToUTF16(src.data(), length, &output)); + RawCanonOutputW<1024> output; + EXPECT_TRUE(ConvertUTF8ToUTF16(src.data(), length, &output)); return base::string16(output.data(), output.length()); } // Converts a string from UTF-16 to UTF-8 inline std::string ConvertUTF16ToUTF8(const base::string16& src) { std::string str; - url_canon::StdStringCanonOutput output(&str); - EXPECT_TRUE(url_canon::ConvertUTF16ToUTF8(src.data(), - static_cast(src.length()), - &output)); + StdStringCanonOutput output(&str); + EXPECT_TRUE(ConvertUTF16ToUTF8(src.data(), static_cast(src.length()), + &output)); output.Complete(); return str; } -} // namespace url_test_utils +} // namespace test_utils + +} // namespace url #endif // URL_URL_TEST_UTILS_H_ diff --git a/url/url_util.cc b/url/url_util.cc index 2b4f7add4f98..ff1fdf905200 100644 --- a/url/url_util.cc +++ b/url/url_util.cc @@ -12,7 +12,7 @@ #include "url/url_file.h" #include "url/url_util_internal.h" -namespace url_util { +namespace url { const char kFileScheme[] = "file"; const char kFileSystemScheme[] = "filesystem"; @@ -22,7 +22,8 @@ namespace { // ASCII-specific tolower. The standard library's tolower is locale sensitive, // so we don't want to use it here. -template inline Char ToLowerASCII(Char c) { +template +inline Char ToLowerASCII(Char c) { return (c >= 'A' && c <= 'Z') ? (c + ('a' - 'A')) : c; } @@ -70,7 +71,7 @@ void InitStandardSchemes() { // lower-case |compare_to| buffer. template inline bool DoCompareSchemeComponent(const CHAR* spec, - const url_parse::Component& component, + const Component& component, const char* compare_to) { if (!component.is_nonempty()) return compare_to[0] == 0; // When component is empty, match empty scheme. @@ -82,7 +83,7 @@ inline bool DoCompareSchemeComponent(const CHAR* spec, // Returns true if the given scheme identified by |scheme| within |spec| is one // of the registered "standard" schemes. template -bool DoIsStandard(const CHAR* spec, const url_parse::Component& scheme) { +bool DoIsStandard(const CHAR* spec, const Component& scheme) { if (!scheme.is_nonempty()) return false; // Empty or invalid schemes are non-standard. @@ -99,19 +100,19 @@ template bool DoFindAndCompareScheme(const CHAR* str, int str_len, const char* compare, - url_parse::Component* found_scheme) { + Component* found_scheme) { // Before extracting scheme, canonicalize the URL to remove any whitespace. // This matches the canonicalization done in DoCanonicalize function. - url_canon::RawCanonOutputT whitespace_buffer; + RawCanonOutputT whitespace_buffer; int spec_len; const CHAR* spec = RemoveURLWhitespace(str, str_len, &whitespace_buffer, &spec_len); - url_parse::Component our_scheme; - if (!url_parse::ExtractScheme(spec, spec_len, &our_scheme)) { + Component our_scheme; + if (!ExtractScheme(spec, spec_len, &our_scheme)) { // No scheme. if (found_scheme) - *found_scheme = url_parse::Component(); + *found_scheme = Component(); return false; } if (found_scheme) @@ -120,19 +121,20 @@ bool DoFindAndCompareScheme(const CHAR* str, } template -bool DoCanonicalize(const CHAR* in_spec, int in_spec_len, +bool DoCanonicalize(const CHAR* in_spec, + int in_spec_len, bool trim_path_end, - url_canon::CharsetConverter* charset_converter, - url_canon::CanonOutput* output, - url_parse::Parsed* output_parsed) { + CharsetConverter* charset_converter, + CanonOutput* output, + Parsed* output_parsed) { // Remove any whitespace from the middle of the relative URL, possibly // copying to the new buffer. - url_canon::RawCanonOutputT whitespace_buffer; + RawCanonOutputT whitespace_buffer; int spec_len; const CHAR* spec = RemoveURLWhitespace(in_spec, in_spec_len, &whitespace_buffer, &spec_len); - url_parse::Parsed parsed_input; + Parsed parsed_input; #ifdef WIN32 // For Windows, we allow things that look like absolute Windows paths to be // fixed up magically to file URLs. This is done for IE compatability. For @@ -144,17 +146,16 @@ bool DoCanonicalize(const CHAR* in_spec, int in_spec_len, // has no meaning as an absolute path name. This is because browsers on Mac // & Unix don't generally do this, so there is no compatibility reason for // doing so. - if (url_parse::DoesBeginUNCPath(spec, 0, spec_len, false) || - url_parse::DoesBeginWindowsDriveSpec(spec, 0, spec_len)) { - url_parse::ParseFileURL(spec, spec_len, &parsed_input); - return url_canon::CanonicalizeFileURL(spec, spec_len, parsed_input, - charset_converter, - output, output_parsed); + if (DoesBeginUNCPath(spec, 0, spec_len, false) || + DoesBeginWindowsDriveSpec(spec, 0, spec_len)) { + ParseFileURL(spec, spec_len, &parsed_input); + return CanonicalizeFileURL(spec, spec_len, parsed_input, charset_converter, + output, output_parsed); } #endif - url_parse::Component scheme; - if (!url_parse::ExtractScheme(spec, spec_len, &scheme)) + Component scheme; + if (!ExtractScheme(spec, spec_len, &scheme)) return false; // This is the parsed version of the input URL, we have to canonicalize it @@ -162,36 +163,33 @@ bool DoCanonicalize(const CHAR* in_spec, int in_spec_len, bool success; if (DoCompareSchemeComponent(spec, scheme, kFileScheme)) { // File URLs are special. - url_parse::ParseFileURL(spec, spec_len, &parsed_input); - success = url_canon::CanonicalizeFileURL(spec, spec_len, parsed_input, - charset_converter, output, - output_parsed); + ParseFileURL(spec, spec_len, &parsed_input); + success = CanonicalizeFileURL(spec, spec_len, parsed_input, + charset_converter, output, output_parsed); } else if (DoCompareSchemeComponent(spec, scheme, kFileSystemScheme)) { // Filesystem URLs are special. - url_parse::ParseFileSystemURL(spec, spec_len, &parsed_input); - success = url_canon::CanonicalizeFileSystemURL(spec, spec_len, - parsed_input, - charset_converter, - output, output_parsed); + ParseFileSystemURL(spec, spec_len, &parsed_input); + success = CanonicalizeFileSystemURL(spec, spec_len, parsed_input, + charset_converter, output, + output_parsed); } else if (DoIsStandard(spec, scheme)) { // All "normal" URLs. - url_parse::ParseStandardURL(spec, spec_len, &parsed_input); - success = url_canon::CanonicalizeStandardURL(spec, spec_len, parsed_input, - charset_converter, - output, output_parsed); + ParseStandardURL(spec, spec_len, &parsed_input); + success = CanonicalizeStandardURL(spec, spec_len, parsed_input, + charset_converter, output, output_parsed); } else if (DoCompareSchemeComponent(spec, scheme, kMailtoScheme)) { // Mailto are treated like a standard url with only a scheme, path, query - url_parse::ParseMailtoURL(spec, spec_len, &parsed_input); - success = url_canon::CanonicalizeMailtoURL(spec, spec_len, parsed_input, - output, output_parsed); + ParseMailtoURL(spec, spec_len, &parsed_input); + success = CanonicalizeMailtoURL(spec, spec_len, parsed_input, output, + output_parsed); } else { // "Weird" URLs like data: and javascript: - url_parse::ParsePathURL(spec, spec_len, trim_path_end, &parsed_input); - success = url_canon::CanonicalizePathURL(spec, spec_len, parsed_input, - output, output_parsed); + ParsePathURL(spec, spec_len, trim_path_end, &parsed_input); + success = CanonicalizePathURL(spec, spec_len, parsed_input, output, + output_parsed); } return success; } @@ -199,15 +197,15 @@ bool DoCanonicalize(const CHAR* in_spec, int in_spec_len, template bool DoResolveRelative(const char* base_spec, int base_spec_len, - const url_parse::Parsed& base_parsed, + const Parsed& base_parsed, const CHAR* in_relative, int in_relative_length, - url_canon::CharsetConverter* charset_converter, - url_canon::CanonOutput* output, - url_parse::Parsed* output_parsed) { + CharsetConverter* charset_converter, + CanonOutput* output, + Parsed* output_parsed) { // Remove any whitespace from the middle of the relative URL, possibly // copying to the new buffer. - url_canon::RawCanonOutputT whitespace_buffer; + RawCanonOutputT whitespace_buffer; int relative_length; const CHAR* relative = RemoveURLWhitespace(in_relative, in_relative_length, &whitespace_buffer, @@ -217,8 +215,8 @@ bool DoResolveRelative(const char* base_spec, if (base_spec && base_parsed.scheme.is_nonempty()) { int after_scheme = base_parsed.scheme.end() + 1; // Skip past the colon. - int num_slashes = url_parse::CountConsecutiveSlashes( - base_spec, after_scheme, base_spec_len); + int num_slashes = CountConsecutiveSlashes(base_spec, after_scheme, + base_spec_len); base_is_authority_based = num_slashes > 1; base_is_hierarchical = num_slashes > 0; } @@ -228,12 +226,10 @@ bool DoResolveRelative(const char* base_spec, DoIsStandard(base_spec, base_parsed.scheme); bool is_relative; - url_parse::Component relative_component; - if (!url_canon::IsRelativeURL(base_spec, base_parsed, - relative, relative_length, - (base_is_hierarchical || standard_base_scheme), - &is_relative, - &relative_component)) { + Component relative_component; + if (!IsRelativeURL(base_spec, base_parsed, relative, relative_length, + (base_is_hierarchical || standard_base_scheme), + &is_relative, &relative_component)) { // Error resolving. return false; } @@ -242,14 +238,13 @@ bool DoResolveRelative(const char* base_spec, // non-standard URLs are treated as PathURLs, but if the base has an // authority we would like to preserve it. if (is_relative && base_is_authority_based && !standard_base_scheme) { - url_parse::Parsed base_parsed_authority; + Parsed base_parsed_authority; ParseStandardURL(base_spec, base_spec_len, &base_parsed_authority); if (base_parsed_authority.host.is_nonempty()) { bool did_resolve_succeed = - url_canon::ResolveRelativeURL(base_spec, base_parsed_authority, - false, relative, - relative_component, charset_converter, - output, output_parsed); + ResolveRelativeURL(base_spec, base_parsed_authority, false, relative, + relative_component, charset_converter, output, + output_parsed); // The output_parsed is incorrect at this point (because it was built // based on base_parsed_authority instead of base_parsed) and needs to be // re-created. @@ -261,10 +256,9 @@ bool DoResolveRelative(const char* base_spec, // Relative, resolve and canonicalize. bool file_base_scheme = base_parsed.scheme.is_nonempty() && DoCompareSchemeComponent(base_spec, base_parsed.scheme, kFileScheme); - return url_canon::ResolveRelativeURL(base_spec, base_parsed, - file_base_scheme, relative, - relative_component, charset_converter, - output, output_parsed); + return ResolveRelativeURL(base_spec, base_parsed, file_base_scheme, relative, + relative_component, charset_converter, output, + output_parsed); } // Not relative, canonicalize the input. @@ -275,11 +269,11 @@ bool DoResolveRelative(const char* base_spec, template bool DoReplaceComponents(const char* spec, int spec_len, - const url_parse::Parsed& parsed, - const url_canon::Replacements& replacements, - url_canon::CharsetConverter* charset_converter, - url_canon::CanonOutput* output, - url_parse::Parsed* out_parsed) { + const Parsed& parsed, + const Replacements& replacements, + CharsetConverter* charset_converter, + CanonOutput* output, + Parsed* out_parsed) { // If the scheme is overridden, just do a simple string substitution and // reparse the whole thing. There are lots of edge cases that we really don't // want to deal with. Like what happens if I replace "http://e:8080/foo" @@ -296,12 +290,11 @@ bool DoReplaceComponents(const char* spec, if (replacements.IsSchemeOverridden()) { // Canonicalize the new scheme so it is 8-bit and can be concatenated with // the existing spec. - url_canon::RawCanonOutput<128> scheme_replaced; - url_parse::Component scheme_replaced_parsed; - url_canon::CanonicalizeScheme( - replacements.sources().scheme, - replacements.components().scheme, - &scheme_replaced, &scheme_replaced_parsed); + RawCanonOutput<128> scheme_replaced; + Component scheme_replaced_parsed; + CanonicalizeScheme(replacements.sources().scheme, + replacements.components().scheme, + &scheme_replaced, &scheme_replaced_parsed); // We can assume that the input is canonicalized, which means it always has // a colon after the scheme (or where the scheme would be). @@ -314,8 +307,8 @@ bool DoReplaceComponents(const char* spec, // We now need to completely re-parse the resulting string since its meaning // may have changed with the different scheme. - url_canon::RawCanonOutput<128> recanonicalized; - url_parse::Parsed recanonicalized_parsed; + RawCanonOutput<128> recanonicalized; + Parsed recanonicalized_parsed; DoCanonicalize(scheme_replaced.data(), scheme_replaced.length(), true, charset_converter, &recanonicalized, &recanonicalized_parsed); @@ -333,8 +326,8 @@ bool DoReplaceComponents(const char* spec, // after this call to check validity (this assumes replacing the scheme is // much much less common than other types of replacements, like clearing the // ref). - url_canon::Replacements replacements_no_scheme = replacements; - replacements_no_scheme.SetScheme(NULL, url_parse::Component()); + Replacements replacements_no_scheme = replacements; + replacements_no_scheme.SetScheme(NULL, Component()); return DoReplaceComponents(recanonicalized.data(), recanonicalized.length(), recanonicalized_parsed, replacements_no_scheme, charset_converter, output, out_parsed); @@ -343,26 +336,23 @@ bool DoReplaceComponents(const char* spec, // If we get here, then we know the scheme doesn't need to be replaced, so can // just key off the scheme in the spec to know how to do the replacements. if (DoCompareSchemeComponent(spec, parsed.scheme, kFileScheme)) { - return url_canon::ReplaceFileURL(spec, parsed, replacements, - charset_converter, output, out_parsed); + return ReplaceFileURL(spec, parsed, replacements, charset_converter, output, + out_parsed); } if (DoCompareSchemeComponent(spec, parsed.scheme, kFileSystemScheme)) { - return url_canon::ReplaceFileSystemURL(spec, parsed, replacements, - charset_converter, output, - out_parsed); + return ReplaceFileSystemURL(spec, parsed, replacements, charset_converter, + output, out_parsed); } if (DoIsStandard(spec, parsed.scheme)) { - return url_canon::ReplaceStandardURL(spec, parsed, replacements, - charset_converter, output, out_parsed); + return ReplaceStandardURL(spec, parsed, replacements, charset_converter, + output, out_parsed); } if (DoCompareSchemeComponent(spec, parsed.scheme, kMailtoScheme)) { - return url_canon::ReplaceMailtoURL(spec, parsed, replacements, - output, out_parsed); + return ReplaceMailtoURL(spec, parsed, replacements, output, out_parsed); } // Default is a path URL. - return url_canon::ReplacePathURL(spec, parsed, replacements, - output, out_parsed); + return ReplacePathURL(spec, parsed, replacements, output, out_parsed); } } // namespace @@ -407,34 +397,34 @@ void LockStandardSchemes() { standard_schemes_locked = true; } -bool IsStandard(const char* spec, const url_parse::Component& scheme) { +bool IsStandard(const char* spec, const Component& scheme) { return DoIsStandard(spec, scheme); } -bool IsStandard(const base::char16* spec, const url_parse::Component& scheme) { +bool IsStandard(const base::char16* spec, const Component& scheme) { return DoIsStandard(spec, scheme); } bool FindAndCompareScheme(const char* str, int str_len, const char* compare, - url_parse::Component* found_scheme) { + Component* found_scheme) { return DoFindAndCompareScheme(str, str_len, compare, found_scheme); } bool FindAndCompareScheme(const base::char16* str, int str_len, const char* compare, - url_parse::Component* found_scheme) { + Component* found_scheme) { return DoFindAndCompareScheme(str, str_len, compare, found_scheme); } bool Canonicalize(const char* spec, int spec_len, bool trim_path_end, - url_canon::CharsetConverter* charset_converter, - url_canon::CanonOutput* output, - url_parse::Parsed* output_parsed) { + CharsetConverter* charset_converter, + CanonOutput* output, + Parsed* output_parsed) { return DoCanonicalize(spec, spec_len, trim_path_end, charset_converter, output, output_parsed); } @@ -442,21 +432,21 @@ bool Canonicalize(const char* spec, bool Canonicalize(const base::char16* spec, int spec_len, bool trim_path_end, - url_canon::CharsetConverter* charset_converter, - url_canon::CanonOutput* output, - url_parse::Parsed* output_parsed) { + CharsetConverter* charset_converter, + CanonOutput* output, + Parsed* output_parsed) { return DoCanonicalize(spec, spec_len, trim_path_end, charset_converter, output, output_parsed); } bool ResolveRelative(const char* base_spec, int base_spec_len, - const url_parse::Parsed& base_parsed, + const Parsed& base_parsed, const char* relative, int relative_length, - url_canon::CharsetConverter* charset_converter, - url_canon::CanonOutput* output, - url_parse::Parsed* output_parsed) { + CharsetConverter* charset_converter, + CanonOutput* output, + Parsed* output_parsed) { return DoResolveRelative(base_spec, base_spec_len, base_parsed, relative, relative_length, charset_converter, output, output_parsed); @@ -464,12 +454,12 @@ bool ResolveRelative(const char* base_spec, bool ResolveRelative(const char* base_spec, int base_spec_len, - const url_parse::Parsed& base_parsed, + const Parsed& base_parsed, const base::char16* relative, int relative_length, - url_canon::CharsetConverter* charset_converter, - url_canon::CanonOutput* output, - url_parse::Parsed* output_parsed) { + CharsetConverter* charset_converter, + CanonOutput* output, + Parsed* output_parsed) { return DoResolveRelative(base_spec, base_spec_len, base_parsed, relative, relative_length, charset_converter, output, output_parsed); @@ -477,23 +467,22 @@ bool ResolveRelative(const char* base_spec, bool ReplaceComponents(const char* spec, int spec_len, - const url_parse::Parsed& parsed, - const url_canon::Replacements& replacements, - url_canon::CharsetConverter* charset_converter, - url_canon::CanonOutput* output, - url_parse::Parsed* out_parsed) { + const Parsed& parsed, + const Replacements& replacements, + CharsetConverter* charset_converter, + CanonOutput* output, + Parsed* out_parsed) { return DoReplaceComponents(spec, spec_len, parsed, replacements, charset_converter, output, out_parsed); } -bool ReplaceComponents( - const char* spec, - int spec_len, - const url_parse::Parsed& parsed, - const url_canon::Replacements& replacements, - url_canon::CharsetConverter* charset_converter, - url_canon::CanonOutput* output, - url_parse::Parsed* out_parsed) { +bool ReplaceComponents(const char* spec, + int spec_len, + const Parsed& parsed, + const Replacements& replacements, + CharsetConverter* charset_converter, + CanonOutput* output, + Parsed* out_parsed) { return DoReplaceComponents(spec, spec_len, parsed, replacements, charset_converter, output, out_parsed); } @@ -523,13 +512,14 @@ bool LowerCaseEqualsASCII(const base::char16* a_begin, return DoLowerCaseEqualsASCII(a_begin, a_end, b); } -void DecodeURLEscapeSequences(const char* input, int length, - url_canon::CanonOutputW* output) { - url_canon::RawCanonOutputT unescaped_chars; +void DecodeURLEscapeSequences(const char* input, + int length, + CanonOutputW* output) { + RawCanonOutputT unescaped_chars; for (int i = 0; i < length; i++) { if (input[i] == '%') { unsigned char ch; - if (url_canon::DecodeEscaped(input, &i, length, &ch)) { + if (DecodeEscaped(input, &i, length, &ch)) { unescaped_chars.push_back(ch); } else { // Invalid escape sequence, copy the percent literal. @@ -553,10 +543,10 @@ void DecodeURLEscapeSequences(const char* input, int length, // character. int next_character = i; unsigned code_point; - if (url_canon::ReadUTFChar(unescaped_chars.data(), &next_character, - unescaped_chars.length(), &code_point)) { + if (ReadUTFChar(unescaped_chars.data(), &next_character, + unescaped_chars.length(), &code_point)) { // Valid UTF-8 character, convert to UTF-16. - url_canon::AppendUTF16Value(code_point, output); + AppendUTF16Value(code_point, output); i = next_character; } else { // If there are any sequences that are not valid UTF-8, we keep @@ -572,11 +562,10 @@ void DecodeURLEscapeSequences(const char* input, int length, } } -void EncodeURIComponent(const char* input, int length, - url_canon::CanonOutput* output) { +void EncodeURIComponent(const char* input, int length, CanonOutput* output) { for (int i = 0; i < length; ++i) { unsigned char c = static_cast(input[i]); - if (url_canon::IsComponentChar(c)) + if (IsComponentChar(c)) output->push_back(c); else AppendEscapedChar(c, output); @@ -584,15 +573,15 @@ void EncodeURIComponent(const char* input, int length, } bool CompareSchemeComponent(const char* spec, - const url_parse::Component& component, + const Component& component, const char* compare_to) { return DoCompareSchemeComponent(spec, component, compare_to); } bool CompareSchemeComponent(const base::char16* spec, - const url_parse::Component& component, + const Component& component, const char* compare_to) { return DoCompareSchemeComponent(spec, component, compare_to); } -} // namespace url_util +} // namespace url diff --git a/url/url_util.h b/url/url_util.h index eff386cf46a9..42295250abd5 100644 --- a/url/url_util.h +++ b/url/url_util.h @@ -12,7 +12,7 @@ #include "url/url_export.h" #include "url/url_parse.h" -namespace url_util { +namespace url { // Init ------------------------------------------------------------------------ @@ -66,35 +66,34 @@ URL_EXPORT void LockStandardSchemes(); URL_EXPORT bool FindAndCompareScheme(const char* str, int str_len, const char* compare, - url_parse::Component* found_scheme); + Component* found_scheme); URL_EXPORT bool FindAndCompareScheme(const base::char16* str, int str_len, const char* compare, - url_parse::Component* found_scheme); + Component* found_scheme); inline bool FindAndCompareScheme(const std::string& str, const char* compare, - url_parse::Component* found_scheme) { + Component* found_scheme) { return FindAndCompareScheme(str.data(), static_cast(str.size()), compare, found_scheme); } inline bool FindAndCompareScheme(const base::string16& str, const char* compare, - url_parse::Component* found_scheme) { + Component* found_scheme) { return FindAndCompareScheme(str.data(), static_cast(str.size()), compare, found_scheme); } // Returns true if the given string represents a standard URL. This means that // either the scheme is in the list of known standard schemes. -URL_EXPORT bool IsStandard(const char* spec, - const url_parse::Component& scheme); -URL_EXPORT bool IsStandard(const base::char16* spec, - const url_parse::Component& scheme); +URL_EXPORT bool IsStandard(const char* spec, const Component& scheme); +URL_EXPORT bool IsStandard(const base::char16* spec, const Component& scheme); // TODO(brettw) remove this. This is a temporary compatibility hack to avoid // breaking the WebKit build when this version is synced via Chrome. -inline bool IsStandard(const char* spec, int spec_len, - const url_parse::Component& scheme) { +inline bool IsStandard(const char* spec, + int spec_len, + const Component& scheme) { return IsStandard(spec, scheme); } @@ -104,7 +103,7 @@ inline bool IsStandard(const char* spec, int spec_len, // should use the URL object, although this may be useful if performance is // critical and you don't want to do the heap allocation for the std::string. // -// As with the url_canon::Canonicalize* functions, the charset converter can +// As with the Canonicalize* functions, the charset converter can // be NULL to use UTF-8 (it will be faster in this case). // // Returns true if a valid URL was produced, false if not. On failure, the @@ -113,15 +112,15 @@ inline bool IsStandard(const char* spec, int spec_len, URL_EXPORT bool Canonicalize(const char* spec, int spec_len, bool trim_path_end, - url_canon::CharsetConverter* charset_converter, - url_canon::CanonOutput* output, - url_parse::Parsed* output_parsed); + CharsetConverter* charset_converter, + CanonOutput* output, + Parsed* output_parsed); URL_EXPORT bool Canonicalize(const base::char16* spec, int spec_len, bool trim_path_end, - url_canon::CharsetConverter* charset_converter, - url_canon::CanonOutput* output, - url_parse::Parsed* output_parsed); + CharsetConverter* charset_converter, + CanonOutput* output, + Parsed* output_parsed); // Resolves a potentially relative URL relative to the given parsed base URL. // The base MUST be valid. The resulting canonical URL and parsed information @@ -135,41 +134,40 @@ URL_EXPORT bool Canonicalize(const base::char16* spec, // a valid URL. URL_EXPORT bool ResolveRelative(const char* base_spec, int base_spec_len, - const url_parse::Parsed& base_parsed, + const Parsed& base_parsed, const char* relative, int relative_length, - url_canon::CharsetConverter* charset_converter, - url_canon::CanonOutput* output, - url_parse::Parsed* output_parsed); + CharsetConverter* charset_converter, + CanonOutput* output, + Parsed* output_parsed); URL_EXPORT bool ResolveRelative(const char* base_spec, int base_spec_len, - const url_parse::Parsed& base_parsed, + const Parsed& base_parsed, const base::char16* relative, int relative_length, - url_canon::CharsetConverter* charset_converter, - url_canon::CanonOutput* output, - url_parse::Parsed* output_parsed); + CharsetConverter* charset_converter, + CanonOutput* output, + Parsed* output_parsed); // Replaces components in the given VALID input url. The new canonical URL info // is written to output and out_parsed. // // Returns true if the resulting URL is valid. +URL_EXPORT bool ReplaceComponents(const char* spec, + int spec_len, + const Parsed& parsed, + const Replacements& replacements, + CharsetConverter* charset_converter, + CanonOutput* output, + Parsed* out_parsed); URL_EXPORT bool ReplaceComponents( const char* spec, int spec_len, - const url_parse::Parsed& parsed, - const url_canon::Replacements& replacements, - url_canon::CharsetConverter* charset_converter, - url_canon::CanonOutput* output, - url_parse::Parsed* out_parsed); -URL_EXPORT bool ReplaceComponents( - const char* spec, - int spec_len, - const url_parse::Parsed& parsed, - const url_canon::Replacements& replacements, - url_canon::CharsetConverter* charset_converter, - url_canon::CanonOutput* output, - url_parse::Parsed* out_parsed); + const Parsed& parsed, + const Replacements& replacements, + CharsetConverter* charset_converter, + CanonOutput* output, + Parsed* out_parsed); // String helper functions ---------------------------------------------------- @@ -191,15 +189,16 @@ URL_EXPORT bool LowerCaseEqualsASCII(const base::char16* a_begin, const char* b); // Unescapes the given string using URL escaping rules. -URL_EXPORT void DecodeURLEscapeSequences(const char* input, int length, - url_canon::CanonOutputW* output); +URL_EXPORT void DecodeURLEscapeSequences(const char* input, + int length, + CanonOutputW* output); // Escapes the given string as defined by the JS method encodeURIComponent. See // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/encodeURIComponent -URL_EXPORT void EncodeURIComponent(const char* input, int length, - url_canon::CanonOutput* output); - +URL_EXPORT void EncodeURIComponent(const char* input, + int length, + CanonOutput* output); -} // namespace url_util +} // namespace url #endif // URL_URL_UTIL_H_ diff --git a/url/url_util_internal.h b/url/url_util_internal.h index af9138939583..c6274cc6cada 100644 --- a/url/url_util_internal.h +++ b/url/url_util_internal.h @@ -10,7 +10,7 @@ #include "base/strings/string16.h" #include "url/url_parse.h" -namespace url_util { +namespace url { extern const char kFileScheme[]; extern const char kFileSystemScheme[]; @@ -19,12 +19,12 @@ extern const char kMailtoScheme[]; // Given a string and a range inside the string, compares it to the given // lower-case |compare_to| buffer. bool CompareSchemeComponent(const char* spec, - const url_parse::Component& component, + const Component& component, const char* compare_to); bool CompareSchemeComponent(const base::char16* spec, - const url_parse::Component& component, + const Component& component, const char* compare_to); -} // namespace url_util +} // namespace url #endif // URL_URL_UTIL_INTERNAL_H_ diff --git a/url/url_util_unittest.cc b/url/url_util_unittest.cc index 70adc5b7fdc0..f84b70d0cfab 100644 --- a/url/url_util_unittest.cc +++ b/url/url_util_unittest.cc @@ -9,102 +9,95 @@ #include "url/url_test_utils.h" #include "url/url_util.h" +namespace url { + TEST(URLUtilTest, FindAndCompareScheme) { - url_parse::Component found_scheme; + Component found_scheme; // Simple case where the scheme is found and matches. const char kStr1[] = "http://www.com/"; - EXPECT_TRUE(url_util::FindAndCompareScheme( + EXPECT_TRUE(FindAndCompareScheme( kStr1, static_cast(strlen(kStr1)), "http", NULL)); - EXPECT_TRUE(url_util::FindAndCompareScheme( + EXPECT_TRUE(FindAndCompareScheme( kStr1, static_cast(strlen(kStr1)), "http", &found_scheme)); - EXPECT_TRUE(found_scheme == url_parse::Component(0, 4)); + EXPECT_TRUE(found_scheme == Component(0, 4)); // A case where the scheme is found and doesn't match. - EXPECT_FALSE(url_util::FindAndCompareScheme( + EXPECT_FALSE(FindAndCompareScheme( kStr1, static_cast(strlen(kStr1)), "https", &found_scheme)); - EXPECT_TRUE(found_scheme == url_parse::Component(0, 4)); + EXPECT_TRUE(found_scheme == Component(0, 4)); // A case where there is no scheme. const char kStr2[] = "httpfoobar"; - EXPECT_FALSE(url_util::FindAndCompareScheme( + EXPECT_FALSE(FindAndCompareScheme( kStr2, static_cast(strlen(kStr2)), "http", &found_scheme)); - EXPECT_TRUE(found_scheme == url_parse::Component()); + EXPECT_TRUE(found_scheme == Component()); // When there is an empty scheme, it should match the empty scheme. const char kStr3[] = ":foo.com/"; - EXPECT_TRUE(url_util::FindAndCompareScheme( + EXPECT_TRUE(FindAndCompareScheme( kStr3, static_cast(strlen(kStr3)), "", &found_scheme)); - EXPECT_TRUE(found_scheme == url_parse::Component(0, 0)); + EXPECT_TRUE(found_scheme == Component(0, 0)); // But when there is no scheme, it should fail. - EXPECT_FALSE(url_util::FindAndCompareScheme("", 0, "", &found_scheme)); - EXPECT_TRUE(found_scheme == url_parse::Component()); + EXPECT_FALSE(FindAndCompareScheme("", 0, "", &found_scheme)); + EXPECT_TRUE(found_scheme == Component()); // When there is a whitespace char in scheme, it should canonicalize the url // before comparison. const char whtspc_str[] = " \r\n\tjav\ra\nscri\tpt:alert(1)"; - EXPECT_TRUE(url_util::FindAndCompareScheme( - whtspc_str, static_cast(strlen(whtspc_str)), "javascript", - &found_scheme)); - EXPECT_TRUE(found_scheme == url_parse::Component(1, 10)); + EXPECT_TRUE(FindAndCompareScheme(whtspc_str, + static_cast(strlen(whtspc_str)), + "javascript", &found_scheme)); + EXPECT_TRUE(found_scheme == Component(1, 10)); // Control characters should be stripped out on the ends, and kept in the // middle. const char ctrl_str[] = "\02jav\02scr\03ipt:alert(1)"; - EXPECT_FALSE(url_util::FindAndCompareScheme( - ctrl_str, static_cast(strlen(ctrl_str)), "javascript", - &found_scheme)); - EXPECT_TRUE(found_scheme == url_parse::Component(1, 11)); + EXPECT_FALSE(FindAndCompareScheme(ctrl_str, + static_cast(strlen(ctrl_str)), + "javascript", &found_scheme)); + EXPECT_TRUE(found_scheme == Component(1, 11)); } TEST(URLUtilTest, ReplaceComponents) { - url_parse::Parsed parsed; - url_canon::RawCanonOutputT output; - url_parse::Parsed new_parsed; + Parsed parsed; + RawCanonOutputT output; + Parsed new_parsed; // Check that the following calls do not cause crash - url_canon::Replacements replacements; - replacements.SetRef("test", url_parse::Component(0, 4)); - url_util::ReplaceComponents(NULL, 0, parsed, replacements, NULL, &output, - &new_parsed); - url_util::ReplaceComponents("", 0, parsed, replacements, NULL, &output, - &new_parsed); + Replacements replacements; + replacements.SetRef("test", Component(0, 4)); + ReplaceComponents(NULL, 0, parsed, replacements, NULL, &output, &new_parsed); + ReplaceComponents("", 0, parsed, replacements, NULL, &output, &new_parsed); replacements.ClearRef(); - replacements.SetHost("test", url_parse::Component(0, 4)); - url_util::ReplaceComponents(NULL, 0, parsed, replacements, NULL, &output, - &new_parsed); - url_util::ReplaceComponents("", 0, parsed, replacements, NULL, &output, - &new_parsed); + replacements.SetHost("test", Component(0, 4)); + ReplaceComponents(NULL, 0, parsed, replacements, NULL, &output, &new_parsed); + ReplaceComponents("", 0, parsed, replacements, NULL, &output, &new_parsed); replacements.ClearHost(); - url_util::ReplaceComponents(NULL, 0, parsed, replacements, NULL, &output, - &new_parsed); - url_util::ReplaceComponents("", 0, parsed, replacements, NULL, &output, - &new_parsed); - url_util::ReplaceComponents(NULL, 0, parsed, replacements, NULL, &output, - &new_parsed); - url_util::ReplaceComponents("", 0, parsed, replacements, NULL, &output, - &new_parsed); + ReplaceComponents(NULL, 0, parsed, replacements, NULL, &output, &new_parsed); + ReplaceComponents("", 0, parsed, replacements, NULL, &output, &new_parsed); + ReplaceComponents(NULL, 0, parsed, replacements, NULL, &output, &new_parsed); + ReplaceComponents("", 0, parsed, replacements, NULL, &output, &new_parsed); } static std::string CheckReplaceScheme(const char* base_url, const char* scheme) { // Make sure the input is canonicalized. - url_canon::RawCanonOutput<32> original; - url_parse::Parsed original_parsed; - url_util::Canonicalize(base_url, strlen(base_url), true, NULL, - &original, &original_parsed); + RawCanonOutput<32> original; + Parsed original_parsed; + Canonicalize(base_url, strlen(base_url), true, NULL, &original, + &original_parsed); - url_canon::Replacements replacements; - replacements.SetScheme(scheme, url_parse::Component(0, strlen(scheme))); + Replacements replacements; + replacements.SetScheme(scheme, Component(0, strlen(scheme))); std::string output_string; - url_canon::StdStringCanonOutput output(&output_string); - url_parse::Parsed output_parsed; - url_util::ReplaceComponents(original.data(), original.length(), - original_parsed, replacements, NULL, - &output, &output_parsed); + StdStringCanonOutput output(&output_string); + Parsed output_parsed; + ReplaceComponents(original.data(), original.length(), original_parsed, + replacements, NULL, &output, &output_parsed); output.Complete(); return output_string; @@ -168,28 +161,26 @@ TEST(URLUtilTest, DecodeURLEscapeSequences) { for (size_t i = 0; i < ARRAYSIZE_UNSAFE(decode_cases); i++) { const char* input = decode_cases[i].input; - url_canon::RawCanonOutputT output; - url_util::DecodeURLEscapeSequences(input, strlen(input), &output); + RawCanonOutputT output; + DecodeURLEscapeSequences(input, strlen(input), &output); EXPECT_EQ(decode_cases[i].output, - url_test_utils::ConvertUTF16ToUTF8( - base::string16(output.data(), output.length()))); + test_utils::ConvertUTF16ToUTF8(base::string16(output.data(), + output.length()))); } // Our decode should decode %00 const char zero_input[] = "%00"; - url_canon::RawCanonOutputT zero_output; - url_util::DecodeURLEscapeSequences(zero_input, strlen(zero_input), - &zero_output); - EXPECT_NE("%00", - url_test_utils::ConvertUTF16ToUTF8( - base::string16(zero_output.data(), zero_output.length()))); + RawCanonOutputT zero_output; + DecodeURLEscapeSequences(zero_input, strlen(zero_input), &zero_output); + EXPECT_NE("%00", test_utils::ConvertUTF16ToUTF8( + base::string16(zero_output.data(), zero_output.length()))); // Test the error behavior for invalid UTF-8. const char invalid_input[] = "%e4%a0%e5%a5%bd"; const base::char16 invalid_expected[4] = {0x00e4, 0x00a0, 0x597d, 0}; - url_canon::RawCanonOutputT invalid_output; - url_util::DecodeURLEscapeSequences(invalid_input, strlen(invalid_input), - &invalid_output); + RawCanonOutputT invalid_output; + DecodeURLEscapeSequences(invalid_input, strlen(invalid_input), + &invalid_output); EXPECT_EQ(base::string16(invalid_expected), base::string16(invalid_output.data(), invalid_output.length())); } @@ -220,15 +211,15 @@ TEST(URLUtilTest, TestEncodeURIComponent) { for (size_t i = 0; i < ARRAYSIZE_UNSAFE(encode_cases); i++) { const char* input = encode_cases[i].input; - url_canon::RawCanonOutputT buffer; - url_util::EncodeURIComponent(input, strlen(input), &buffer); + RawCanonOutputT buffer; + EncodeURIComponent(input, strlen(input), &buffer); std::string output(buffer.data(), buffer.length()); EXPECT_EQ(encode_cases[i].output, output); } } TEST(URLUtilTest, TestResolveRelativeWithNonStandardBase) { - // This tests non-standard (in the sense that GURL::IsStandard() == false) + // This tests non-standard (in the sense that GIsStandard() == false) // hierarchical schemes. struct ResolveRelativeCase { const char* base; @@ -285,18 +276,16 @@ TEST(URLUtilTest, TestResolveRelativeWithNonStandardBase) { for (size_t i = 0; i < ARRAYSIZE_UNSAFE(resolve_non_standard_cases); i++) { const ResolveRelativeCase& test_data = resolve_non_standard_cases[i]; - url_parse::Parsed base_parsed; - url_parse::ParsePathURL(test_data.base, strlen(test_data.base), false, - &base_parsed); + Parsed base_parsed; + ParsePathURL(test_data.base, strlen(test_data.base), false, &base_parsed); std::string resolved; - url_canon::StdStringCanonOutput output(&resolved); - url_parse::Parsed resolved_parsed; - bool valid = - url_util::ResolveRelative(test_data.base, strlen(test_data.base), - base_parsed, - test_data.rel, strlen(test_data.rel), - NULL, &output, &resolved_parsed); + StdStringCanonOutput output(&resolved); + Parsed resolved_parsed; + bool valid = ResolveRelative(test_data.base, strlen(test_data.base), + base_parsed, test_data.rel, + strlen(test_data.rel), NULL, &output, + &resolved_parsed); output.Complete(); EXPECT_EQ(test_data.is_valid, valid) << i; @@ -304,3 +293,5 @@ TEST(URLUtilTest, TestResolveRelativeWithNonStandardBase) { EXPECT_EQ(test_data.out, resolved) << i; } } + +} // namespace url -- 2.11.4.GIT