From 3130a853b69a63f159d9d3e74395eb9332f6bfad Mon Sep 17 00:00:00 2001 From: "ericroman@google.com" Date: Mon, 15 Sep 2008 18:37:11 +0000 Subject: Address a TODO for properly stripping references from request URL. (rfind of # isn't quite right, as reference might contain hashes). Review URL: http://codereview.chromium.org/2827 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2225 0039d316-1c4b-4281-b951-d872f2087c98 --- net/http/http_util_unittest.cc | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'net/http/http_util_unittest.cc') diff --git a/net/http/http_util_unittest.cc b/net/http/http_util_unittest.cc index 14c7724..a531228 100644 --- a/net/http/http_util_unittest.cc +++ b/net/http/http_util_unittest.cc @@ -412,3 +412,35 @@ TEST(HttpUtilTest, AssembleRawHeaders) { } } +// Test SpecForRequest() and PathForRequest(). +TEST(HttpUtilTest, RequestUrlSanitize) { + struct { + const char* url; + const char* expected_spec; + const char* expected_path; + } tests[] = { + { // Check that #hash is removed. + "http://www.google.com:78/foobar?query=1#hash", + "http://www.google.com:78/foobar?query=1", + "/foobar?query=1" + }, + { // The reference may itself contain # -- strip all of it. + "http://192.168.0.1?query=1#hash#10#11#13#14", + "http://192.168.0.1/?query=1", + "/?query=1" + }, + { // Strip username/password. + "http://user:pass@google.com", + "http://google.com/", + "/" + } + }; + for (size_t i = 0; i < arraysize(tests); ++i) { + GURL url(GURL(tests[i].url)); + std::string expected_spec(tests[i].expected_spec); + std::string expected_path(tests[i].expected_path); + + EXPECT_EQ(expected_spec, HttpUtil::SpecForRequest(url)); + EXPECT_EQ(expected_path, HttpUtil::PathForRequest(url)); + } +} -- cgit v1.1