| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <errno.h> | 5 #include <errno.h> |
| 6 #include <stddef.h> | 6 #include <stddef.h> |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 1829 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1840 } | 1840 } |
| 1841 | 1841 |
| 1842 TEST(URLCanonTest, CanonicalizeMailtoURL) { | 1842 TEST(URLCanonTest, CanonicalizeMailtoURL) { |
| 1843 struct URLCase { | 1843 struct URLCase { |
| 1844 const char* input; | 1844 const char* input; |
| 1845 const char* expected; | 1845 const char* expected; |
| 1846 bool expected_success; | 1846 bool expected_success; |
| 1847 Component expected_path; | 1847 Component expected_path; |
| 1848 Component expected_query; | 1848 Component expected_query; |
| 1849 } cases[] = { | 1849 } cases[] = { |
| 1850 {"mailto:addr1", "mailto:addr1", true, Component(7, 5), Component()}, | 1850 // Null character should be escaped to %00. |
| 1851 {"mailto:addr1@foo.com", "mailto:addr1@foo.com", true, Component(7, 13), Com
ponent()}, | 1851 // Keep this test first in the list as it is handled specially below. |
| 1852 {"mailto:addr1\0addr2?foo", |
| 1853 "mailto:addr1%00addr2?foo", |
| 1854 true, Component(7, 13), Component(21, 3)}, |
| 1855 {"mailto:addr1", |
| 1856 "mailto:addr1", |
| 1857 true, Component(7, 5), Component()}, |
| 1858 {"mailto:addr1@foo.com", |
| 1859 "mailto:addr1@foo.com", |
| 1860 true, Component(7, 13), Component()}, |
| 1852 // Trailing whitespace is stripped. | 1861 // Trailing whitespace is stripped. |
| 1853 {"MaIlTo:addr1 \t ", "mailto:addr1", true, Component(7, 5), Component()}, | 1862 {"MaIlTo:addr1 \t ", |
| 1854 {"MaIlTo:addr1?to=jon", "mailto:addr1?to=jon", true, Component(7, 5), Compon
ent(13,6)}, | 1863 "mailto:addr1", |
| 1855 {"mailto:addr1,addr2", "mailto:addr1,addr2", true, Component(7, 11), Compone
nt()}, | 1864 true, Component(7, 5), Component()}, |
| 1856 {"mailto:addr1, addr2", "mailto:addr1, addr2", true, Component(7, 12), Compo
nent()}, | 1865 {"MaIlTo:addr1?to=jon", |
| 1857 {"mailto:addr1%2caddr2", "mailto:addr1%2caddr2", true, Component(7, 13), Com
ponent()}, | 1866 "mailto:addr1?to=jon", |
| 1858 {"mailto:\xF0\x90\x8C\x80", "mailto:%F0%90%8C%80", true, Component(7, 12), C
omponent()}, | 1867 true, Component(7, 5), Component(13,6)}, |
| 1859 // Null character should be escaped to %00 | 1868 {"mailto:addr1,addr2", |
| 1860 {"mailto:addr1\0addr2?foo", "mailto:addr1%00addr2?foo", true, Component(7, 1
3), Component(21, 3)}, | 1869 "mailto:addr1,addr2", |
| 1870 true, Component(7, 11), Component()}, |
| 1871 // Embedded spaces must be encoded. |
| 1872 {"mailto:addr1, addr2", |
| 1873 "mailto:addr1,%20addr2", |
| 1874 true, Component(7, 14), Component()}, |
| 1875 {"mailto:addr1, addr2?subject=one two ", |
| 1876 "mailto:addr1,%20addr2?subject=one%20two", |
| 1877 true, Component(7, 14), Component(22, 17)}, |
| 1878 {"mailto:addr1%2caddr2", |
| 1879 "mailto:addr1%2caddr2", |
| 1880 true, Component(7, 13), Component()}, |
| 1881 {"mailto:\xF0\x90\x8C\x80", |
| 1882 "mailto:%F0%90%8C%80", |
| 1883 true, Component(7, 12), Component()}, |
| 1861 // Invalid -- UTF-8 encoded surrogate value. | 1884 // Invalid -- UTF-8 encoded surrogate value. |
| 1862 {"mailto:\xed\xa0\x80", "mailto:%EF%BF%BD", false, Component(7, 9), Componen
t()}, | 1885 {"mailto:\xed\xa0\x80", |
| 1863 {"mailto:addr1?", "mailto:addr1?", true, Component(7, 5), Component(13, 0)}, | 1886 "mailto:%EF%BF%BD", |
| 1887 false, Component(7, 9), Component()}, |
| 1888 {"mailto:addr1?", |
| 1889 "mailto:addr1?", |
| 1890 true, Component(7, 5), Component(13, 0)}, |
| 1891 // Certain characters have special meanings and must be encoded. |
| 1892 {"mailto:! \x22$&()+,-./09:;<=>@AZ[\\]&_`az{|}~\x7f?Query! \x22$&()+,-./09:;
<=>@AZ[\\]&_`az{|}~", |
| 1893 "mailto:!%20%22$&()+,-./09:;%3C=%3E@AZ[\\]&_%60az%7B%7C%7D~%7F?Query!%20%22
$&()+,-./09:;%3C=%3E@AZ[\\]&_`az{|}~", |
| 1894 true, Component(7, 53), Component(61, 47)}, |
| 1864 }; | 1895 }; |
| 1865 | 1896 |
| 1866 // Define outside of loop to catch bugs where components aren't reset | 1897 // Define outside of loop to catch bugs where components aren't reset |
| 1867 Parsed parsed; | 1898 Parsed parsed; |
| 1868 Parsed out_parsed; | 1899 Parsed out_parsed; |
| 1869 | 1900 |
| 1870 for (size_t i = 0; i < arraysize(cases); i++) { | 1901 for (size_t i = 0; i < arraysize(cases); i++) { |
| 1871 int url_len = static_cast<int>(strlen(cases[i].input)); | 1902 int url_len = static_cast<int>(strlen(cases[i].input)); |
| 1872 if (i == 8) { | 1903 if (i == 0) { |
| 1873 // The 9th test case purposely has a '\0' in it -- don't count it | 1904 // The first test case purposely has a '\0' in it -- don't count it |
| 1874 // as the string terminator. | 1905 // as the string terminator. |
| 1875 url_len = 22; | 1906 url_len = 22; |
| 1876 } | 1907 } |
| 1877 ParseMailtoURL(cases[i].input, url_len, &parsed); | 1908 ParseMailtoURL(cases[i].input, url_len, &parsed); |
| 1878 | 1909 |
| 1879 std::string out_str; | 1910 std::string out_str; |
| 1880 StdStringCanonOutput output(&out_str); | 1911 StdStringCanonOutput output(&out_str); |
| 1881 bool success = CanonicalizeMailtoURL(cases[i].input, url_len, parsed, | 1912 bool success = CanonicalizeMailtoURL(cases[i].input, url_len, parsed, |
| 1882 &output, &out_parsed); | 1913 &output, &out_parsed); |
| 1883 output.Complete(); | 1914 output.Complete(); |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2250 }; | 2281 }; |
| 2251 | 2282 |
| 2252 for (auto& test_case : cases) { | 2283 for (auto& test_case : cases) { |
| 2253 SCOPED_TRACE(test_case.scheme); | 2284 SCOPED_TRACE(test_case.scheme); |
| 2254 EXPECT_EQ(test_case.expected_port, | 2285 EXPECT_EQ(test_case.expected_port, |
| 2255 DefaultPortForScheme(test_case.scheme, strlen(test_case.scheme))); | 2286 DefaultPortForScheme(test_case.scheme, strlen(test_case.scheme))); |
| 2256 } | 2287 } |
| 2257 } | 2288 } |
| 2258 | 2289 |
| 2259 } // namespace url | 2290 } // namespace url |
| OLD | NEW |