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

Side by Side Diff: net/base/net_util_unittest.cc

Issue 7649024: Fix query string unescaping. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Add comment Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/base/escape.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/base/net_util.h" 5 #include "net/base/net_util.h"
6 6
7 #include <string.h>
8
7 #include <algorithm> 9 #include <algorithm>
8 10
9 #include "base/file_path.h" 11 #include "base/file_path.h"
10 #include "base/format_macros.h" 12 #include "base/format_macros.h"
11 #include "base/string_number_conversions.h" 13 #include "base/string_number_conversions.h"
12 #include "base/string_util.h" 14 #include "base/string_util.h"
13 #include "base/stringprintf.h" 15 #include "base/stringprintf.h"
14 #include "base/sys_string_conversions.h" 16 #include "base/sys_string_conversions.h"
15 #include "base/test/test_file_util.h" 17 #include "base/test/test_file_util.h"
16 #include "base/time.h" 18 #include "base/time.h"
(...skipping 2806 matching lines...) Expand 10 before | Expand all | Expand 10 after
2823 EXPECT_FALSE(parsed.port.is_valid()); 2825 EXPECT_FALSE(parsed.port.is_valid());
2824 EXPECT_TRUE(parsed.path.is_valid()); 2826 EXPECT_TRUE(parsed.path.is_valid());
2825 EXPECT_FALSE(parsed.query.is_valid()); 2827 EXPECT_FALSE(parsed.query.is_valid());
2826 EXPECT_FALSE(parsed.ref.is_valid()); 2828 EXPECT_FALSE(parsed.ref.is_valid());
2827 EXPECT_EQ(WideToUTF16(L"f"), 2829 EXPECT_EQ(WideToUTF16(L"f"),
2828 formatted.substr(parsed.host.begin, parsed.host.len)); 2830 formatted.substr(parsed.host.begin, parsed.host.len));
2829 EXPECT_EQ(WideToUTF16(L"/"), 2831 EXPECT_EQ(WideToUTF16(L"/"),
2830 formatted.substr(parsed.path.begin, parsed.path.len)); 2832 formatted.substr(parsed.path.begin, parsed.path.len));
2831 } 2833 }
2832 2834
2835 // Make sure that calling FormatUrl on a GURL and then converting back to a GURL
2836 // results in the original GURL, for each ASCII character in the path.
2837 TEST(NetUtilTest, FormatUrlRoundTripPathASCII) {
2838 for (unsigned char test_char = 32; test_char < 128; ++test_char) {
2839 GURL url(std::string("http://www.google.com/") +
2840 static_cast<char>(test_char));
2841 size_t prefix_len;
2842 string16 formatted = FormatUrl(
2843 url, "", kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL, NULL,
2844 &prefix_len, NULL);
2845 EXPECT_EQ(url.spec(), GURL(formatted).spec());
2846 }
2847 }
2848
2849 // Make sure that calling FormatUrl on a GURL and then converting back to a GURL
2850 // results in the original GURL, for each escaped ASCII character in the path.
2851 TEST(NetUtilTest, FormatUrlRoundTripPathEscaped) {
2852 for (unsigned char test_char = 32; test_char < 128; ++test_char) {
2853 std::string original_url("http://www.google.com/");
2854 original_url.push_back('%');
2855 original_url.append(base::HexEncode(&test_char, 1));
2856
2857 GURL url(original_url);
2858 size_t prefix_len;
2859 string16 formatted = FormatUrl(
2860 url, "", kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL, NULL,
2861 &prefix_len, NULL);
2862 EXPECT_EQ(url.spec(), GURL(formatted).spec());
2863 }
2864 }
2865
2866 // Make sure that calling FormatUrl on a GURL and then converting back to a GURL
2867 // results in the original GURL, for each ASCII character in the query.
2868 TEST(NetUtilTest, FormatUrlRoundTripQueryASCII) {
2869 for (unsigned char test_char = 32; test_char < 128; ++test_char) {
2870 GURL url(std::string("http://www.google.com/?") +
2871 static_cast<char>(test_char));
2872 size_t prefix_len;
2873 string16 formatted = FormatUrl(
2874 url, "", kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL, NULL,
2875 &prefix_len, NULL);
2876 EXPECT_EQ(url.spec(), GURL(formatted).spec());
2877 }
2878 }
2879
2880 // Make sure that calling FormatUrl on a GURL and then converting back to a GURL
2881 // only results in a different GURL for certain characters.
2882 TEST(NetUtilTest, FormatUrlRoundTripQueryEscaped) {
2883 // A full list of characters which FormatURL should unescape and GURL should
2884 // not escape again, when they appear in a query string.
2885 const char* kUnescapedCharacters =
2886 "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_~";
2887 for (unsigned char test_char = 0; test_char < 128; ++test_char) {
2888 std::string original_url("http://www.google.com/?");
2889 original_url.push_back('%');
2890 original_url.append(base::HexEncode(&test_char, 1));
2891
2892 GURL url(original_url);
2893 size_t prefix_len;
2894 string16 formatted = FormatUrl(
2895 url, "", kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL, NULL,
2896 &prefix_len, NULL);
2897
2898 if (test_char &&
2899 strchr(kUnescapedCharacters, static_cast<char>(test_char))) {
2900 EXPECT_NE(url.spec(), GURL(formatted).spec());
2901 } else {
2902 EXPECT_EQ(url.spec(), GURL(formatted).spec());
2903 }
2904 }
2905 }
2906
2833 TEST(NetUtilTest, FormatUrlWithOffsets) { 2907 TEST(NetUtilTest, FormatUrlWithOffsets) {
2834 const AdjustOffsetCase null_cases[] = { 2908 const AdjustOffsetCase null_cases[] = {
2835 {0, string16::npos}, 2909 {0, string16::npos},
2836 }; 2910 };
2837 CheckAdjustedOffsets(std::string(), "en", kFormatUrlOmitNothing, 2911 CheckAdjustedOffsets(std::string(), "en", kFormatUrlOmitNothing,
2838 UnescapeRule::NORMAL, null_cases, arraysize(null_cases), NULL); 2912 UnescapeRule::NORMAL, null_cases, arraysize(null_cases), NULL);
2839 2913
2840 const AdjustOffsetCase basic_cases[] = { 2914 const AdjustOffsetCase basic_cases[] = {
2841 {0, 0}, 2915 {0, 0},
2842 {3, 3}, 2916 {3, 3},
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
3321 if (it->address[i] != 0) { 3395 if (it->address[i] != 0) {
3322 all_zeroes = false; 3396 all_zeroes = false;
3323 break; 3397 break;
3324 } 3398 }
3325 } 3399 }
3326 EXPECT_FALSE(all_zeroes); 3400 EXPECT_FALSE(all_zeroes);
3327 } 3401 }
3328 } 3402 }
3329 3403
3330 } // namespace net 3404 } // namespace net
OLDNEW
« no previous file with comments | « net/base/escape.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698