diff options
author | jochen <jochen@chromium.org> | 2014-11-24 11:47:22 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-11-24 19:47:45 +0000 |
commit | 42450392e0ced0eb6607c5d330170abf677aad89 (patch) | |
tree | 10c155eb847095ad6d62d73adba6960369c43d05 /url | |
parent | 0f8fe370250d830b6c78d9ef60ad343018287721 (diff) | |
download | chromium_src-42450392e0ced0eb6607c5d330170abf677aad89.zip chromium_src-42450392e0ced0eb6607c5d330170abf677aad89.tar.gz chromium_src-42450392e0ced0eb6607c5d330170abf677aad89.tar.bz2 |
Make GURL::GetAsReferrer match KURL::strippedForUseAsReferrer
Esp. if it's an invalid URL or otherwise not a valid referrer (i.e.
non-HTTP(S)) return an empty URL.
BUG=422871
R=brettw@chromium.org
Review URL: https://codereview.chromium.org/736403002
Cr-Commit-Position: refs/heads/master@{#305475}
Diffstat (limited to 'url')
-rw-r--r-- | url/gurl.cc | 6 | ||||
-rw-r--r-- | url/gurl.h | 3 | ||||
-rw-r--r-- | url/gurl_unittest.cc | 4 |
3 files changed, 10 insertions, 3 deletions
diff --git a/url/gurl.cc b/url/gurl.cc index b7374b1..b580125 100644 --- a/url/gurl.cc +++ b/url/gurl.cc @@ -322,8 +322,10 @@ GURL GURL::GetOrigin() const { } GURL GURL::GetAsReferrer() const { - if (!is_valid_ || - (!has_ref() && !has_username() && !has_password())) + if (!is_valid_ || !SchemeIsHTTPOrHTTPS()) + return GURL(); + + if (!has_ref() && !has_username() && !has_password()) return GURL(*this); url::Replacements<char> replacements; @@ -198,7 +198,8 @@ class URL_EXPORT GURL { // A helper function to return a GURL stripped from the elements that are not // supposed to be sent as HTTP referrer: username, password and ref fragment. - // For invalid URLs the original URL will be returned. + // For invalid URLs or URLs that no valid referrers, an empty URL will be + // returned. GURL GetAsReferrer() const; // Returns true if the scheme for the current URL is a known "standard" diff --git a/url/gurl_unittest.cc b/url/gurl_unittest.cc index 3e94550..a699189 100644 --- a/url/gurl_unittest.cc +++ b/url/gurl_unittest.cc @@ -343,6 +343,10 @@ TEST(GURLTest, GetAsReferrer) { {"http://:pass@www.google.com", "http://www.google.com/"}, {"http://:@www.google.com", "http://www.google.com/"}, {"http://www.google.com/temp/foo?q#b", "http://www.google.com/temp/foo?q"}, + {"not a url", ""}, + {"unknown-scheme://foo.html", ""}, + {"file:///tmp/test.html", ""}, + {"https://www.google.com", "https://www.google.com/"}, }; for (size_t i = 0; i < arraysize(cases); i++) { GURL url(cases[i].input); |