summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorviettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-31 06:14:17 +0000
committerviettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-31 06:14:17 +0000
commit9f284f13fd93a37bd8afa4840e91a953f4c9bc51 (patch)
tree4a5e7e73c5ed978b2e18569080a70c18a821da76 /net
parentf33fdc5d17ae9e0439d2e68344da6d5f12dc26a5 (diff)
downloadchromium_src-9f284f13fd93a37bd8afa4840e91a953f4c9bc51.zip
chromium_src-9f284f13fd93a37bd8afa4840e91a953f4c9bc51.tar.gz
chromium_src-9f284f13fd93a37bd8afa4840e91a953f4c9bc51.tar.bz2
Remove the wstring FormatUrl() functions (and convert remaining users to the string16 verison).
Still to do: Actually convert the code underlying FormatUrl(). BUG=23581 TEST=builds and passes tests Review URL: http://codereview.chromium.org/3263005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@57968 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r--net/base/net_util.cc514
-rw-r--r--net/base/net_util.h15
-rw-r--r--net/base/net_util_unittest.cc411
3 files changed, 385 insertions, 555 deletions
diff --git a/net/base/net_util.cc b/net/base/net_util.cc
index 202f5fc..4dd357f 100644
--- a/net/base/net_util.cc
+++ b/net/base/net_util.cc
@@ -69,6 +69,8 @@
using base::Time;
+namespace net {
+
namespace {
// what we prepend to get a file URL
@@ -746,7 +748,15 @@ void AdjustComponents(int delta, url_parse::Parsed* parsed) {
AdjustComponent(delta, &(parsed->ref));
}
-// Helper for FormatUrl().
+std::wstring FormatUrlInternal(const GURL& url,
+ const std::wstring& languages,
+ FormatUrlTypes format_types,
+ UnescapeRule::Type unescape_rules,
+ url_parse::Parsed* new_parsed,
+ size_t* prefix_end,
+ size_t* offset_for_adjustment);
+
+// Helper for FormatUrl()/FormatUrlInternal().
std::wstring FormatViewSourceUrl(const GURL& url,
const std::wstring& languages,
net::FormatUrlTypes format_types,
@@ -763,8 +773,8 @@ std::wstring FormatViewSourceUrl(const GURL& url,
std::wstring::npos : (*offset_for_adjustment - kViewSourceLengthPlus1);
size_t* temp_offset_ptr = (*offset_for_adjustment < kViewSourceLengthPlus1) ?
NULL : &temp_offset;
- std::wstring result = net::FormatUrl(real_url, languages,
- format_types, unescape_rules, new_parsed, prefix_end, temp_offset_ptr);
+ std::wstring result = FormatUrlInternal(real_url, languages, format_types,
+ unescape_rules, new_parsed, prefix_end, temp_offset_ptr);
result.insert(0, kWideViewSource);
// Adjust position values.
@@ -785,19 +795,6 @@ std::wstring FormatViewSourceUrl(const GURL& url,
return result;
}
-} // namespace
-
-namespace net {
-
-const FormatUrlType kFormatUrlOmitNothing = 0;
-const FormatUrlType kFormatUrlOmitUsernamePassword = 1 << 0;
-const FormatUrlType kFormatUrlOmitHTTP = 1 << 1;
-const FormatUrlType kFormatUrlOmitTrailingSlashOnBareHostname = 1 << 2;
-const FormatUrlType kFormatUrlOmitAll = kFormatUrlOmitUsernamePassword |
- kFormatUrlOmitHTTP | kFormatUrlOmitTrailingSlashOnBareHostname;
-
-std::set<int> explicitly_allowed_ports;
-
// Appends the substring |in_component| inside of the URL |spec| to |output|,
// and the resulting range will be filled into |out_component|. |unescape_rules|
// defines how to clean the URL for human readability. |offset_for_adjustment|
@@ -808,12 +805,248 @@ std::set<int> explicitly_allowed_ports;
// components. Otherwise it points into the component being converted, and is
// adjusted to point to the same logical place in |output|.
// |offset_for_adjustment| may not be NULL.
-static void AppendFormattedComponent(const std::string& spec,
- const url_parse::Component& in_component,
- UnescapeRule::Type unescape_rules,
- std::wstring* output,
- url_parse::Component* out_component,
- size_t* offset_for_adjustment);
+void AppendFormattedComponent(const std::string& spec,
+ const url_parse::Component& in_component,
+ UnescapeRule::Type unescape_rules,
+ std::wstring* output,
+ url_parse::Component* out_component,
+ size_t* offset_for_adjustment) {
+ DCHECK(output);
+ DCHECK(offset_for_adjustment);
+ if (in_component.is_nonempty()) {
+ out_component->begin = static_cast<int>(output->length());
+ size_t offset_past_current_output =
+ ((*offset_for_adjustment == std::wstring::npos) ||
+ (*offset_for_adjustment < output->length())) ?
+ std::wstring::npos : (*offset_for_adjustment - output->length());
+ size_t* offset_into_component =
+ (offset_past_current_output >= static_cast<size_t>(in_component.len)) ?
+ NULL : &offset_past_current_output;
+ if (unescape_rules == UnescapeRule::NONE) {
+ output->append(UTF8ToWideAndAdjustOffset(
+ spec.substr(in_component.begin, in_component.len),
+ offset_into_component));
+ } else {
+ output->append(UTF16ToWideHack(UnescapeAndDecodeUTF8URLComponent(
+ spec.substr(in_component.begin, in_component.len), unescape_rules,
+ offset_into_component)));
+ }
+ out_component->len =
+ static_cast<int>(output->length()) - out_component->begin;
+ if (offset_into_component) {
+ *offset_for_adjustment = (*offset_into_component == std::wstring::npos) ?
+ std::wstring::npos : (out_component->begin + *offset_into_component);
+ } else if (offset_past_current_output != std::wstring::npos) {
+ *offset_for_adjustment += out_component->len - in_component.len;
+ }
+ } else {
+ out_component->reset();
+ }
+}
+
+// TODO(viettrungluu): This is really the old-fashioned version, made internal.
+// I need to really convert |FormatUrl()|.
+std::wstring FormatUrlInternal(const GURL& url,
+ const std::wstring& languages,
+ FormatUrlTypes format_types,
+ UnescapeRule::Type unescape_rules,
+ url_parse::Parsed* new_parsed,
+ size_t* prefix_end,
+ size_t* offset_for_adjustment) {
+ url_parse::Parsed parsed_temp;
+ if (!new_parsed)
+ new_parsed = &parsed_temp;
+ else
+ *new_parsed = url_parse::Parsed();
+ size_t offset_temp = std::wstring::npos;
+ if (!offset_for_adjustment)
+ offset_for_adjustment = &offset_temp;
+
+ std::wstring url_string;
+
+ // Check for empty URLs or 0 available text width.
+ if (url.is_empty()) {
+ if (prefix_end)
+ *prefix_end = 0;
+ *offset_for_adjustment = std::wstring::npos;
+ return url_string;
+ }
+
+ // Special handling for view-source:. Don't use chrome::kViewSourceScheme
+ // because this library shouldn't depend on chrome.
+ const char* const kViewSource = "view-source";
+ // Reject "view-source:view-source:..." to avoid deep recursion.
+ const char* const kViewSourceTwice = "view-source:view-source:";
+ if (url.SchemeIs(kViewSource) &&
+ !StartsWithASCII(url.possibly_invalid_spec(), kViewSourceTwice, false)) {
+ return FormatViewSourceUrl(url, languages, format_types,
+ unescape_rules, new_parsed, prefix_end, offset_for_adjustment);
+ }
+
+ // We handle both valid and invalid URLs (this will give us the spec
+ // regardless of validity).
+ const std::string& spec = url.possibly_invalid_spec();
+ const url_parse::Parsed& parsed = url.parsed_for_possibly_invalid_spec();
+ if (*offset_for_adjustment >= spec.length())
+ *offset_for_adjustment = std::wstring::npos;
+
+ // Copy everything before the username (the scheme and the separators.)
+ // These are ASCII.
+ std::copy(spec.begin(),
+ spec.begin() + parsed.CountCharactersBefore(url_parse::Parsed::USERNAME,
+ true),
+ std::back_inserter(url_string));
+
+ const wchar_t kHTTP[] = L"http://";
+ const char kFTP[] = "ftp.";
+ // URLFixerUpper::FixupURL() treats "ftp.foo.com" as ftp://ftp.foo.com. This
+ // means that if we trim "http://" off a URL whose host starts with "ftp." and
+ // the user inputs this into any field subject to fixup (which is basically
+ // all input fields), the meaning would be changed. (In fact, often the
+ // formatted URL is directly pre-filled into an input field.) For this reason
+ // we avoid stripping "http://" in this case.
+ bool omit_http =
+ (format_types & kFormatUrlOmitHTTP) && (url_string == kHTTP) &&
+ (url.host().compare(0, arraysize(kFTP) - 1, kFTP) != 0);
+
+ new_parsed->scheme = parsed.scheme;
+
+ if ((format_types & kFormatUrlOmitUsernamePassword) != 0) {
+ // Remove the username and password fields. We don't want to display those
+ // to the user since they can be used for attacks,
+ // e.g. "http://google.com:search@evil.ru/"
+ new_parsed->username.reset();
+ new_parsed->password.reset();
+ if ((*offset_for_adjustment != std::wstring::npos) &&
+ (parsed.username.is_nonempty() || parsed.password.is_nonempty())) {
+ if (parsed.username.is_nonempty() && parsed.password.is_nonempty()) {
+ // The seeming off-by-one and off-by-two in these first two lines are to
+ // account for the ':' after the username and '@' after the password.
+ if (*offset_for_adjustment >
+ static_cast<size_t>(parsed.password.end())) {
+ *offset_for_adjustment -=
+ (parsed.username.len + parsed.password.len + 2);
+ } else if (*offset_for_adjustment >
+ static_cast<size_t>(parsed.username.begin)) {
+ *offset_for_adjustment = std::wstring::npos;
+ }
+ } else {
+ const url_parse::Component* nonempty_component =
+ parsed.username.is_nonempty() ? &parsed.username : &parsed.password;
+ // The seeming off-by-one in these first two lines is to account for the
+ // '@' after the username/password.
+ if (*offset_for_adjustment >
+ static_cast<size_t>(nonempty_component->end())) {
+ *offset_for_adjustment -= (nonempty_component->len + 1);
+ } else if (*offset_for_adjustment >
+ static_cast<size_t>(nonempty_component->begin)) {
+ *offset_for_adjustment = std::wstring::npos;
+ }
+ }
+ }
+ } else {
+ AppendFormattedComponent(spec, parsed.username, unescape_rules, &url_string,
+ &new_parsed->username, offset_for_adjustment);
+ if (parsed.password.is_valid())
+ url_string.push_back(':');
+ AppendFormattedComponent(spec, parsed.password, unescape_rules, &url_string,
+ &new_parsed->password, offset_for_adjustment);
+ if (parsed.username.is_valid() || parsed.password.is_valid())
+ url_string.push_back('@');
+ }
+ if (prefix_end)
+ *prefix_end = static_cast<size_t>(url_string.length());
+
+ AppendFormattedHost(url, languages, &url_string, new_parsed,
+ offset_for_adjustment);
+
+ // Port.
+ if (parsed.port.is_nonempty()) {
+ url_string.push_back(':');
+ new_parsed->port.begin = url_string.length();
+ std::copy(spec.begin() + parsed.port.begin,
+ spec.begin() + parsed.port.end(), std::back_inserter(url_string));
+ new_parsed->port.len = url_string.length() - new_parsed->port.begin;
+ } else {
+ new_parsed->port.reset();
+ }
+
+ // Path and query both get the same general unescape & convert treatment.
+ if (!(format_types & kFormatUrlOmitTrailingSlashOnBareHostname) ||
+ !CanStripTrailingSlash(url)) {
+ AppendFormattedComponent(spec, parsed.path, unescape_rules, &url_string,
+ &new_parsed->path, offset_for_adjustment);
+ }
+ if (parsed.query.is_valid())
+ url_string.push_back('?');
+ AppendFormattedComponent(spec, parsed.query, unescape_rules, &url_string,
+ &new_parsed->query, offset_for_adjustment);
+
+ // Reference is stored in valid, unescaped UTF-8, so we can just convert.
+ if (parsed.ref.is_valid()) {
+ url_string.push_back('#');
+ new_parsed->ref.begin = url_string.length();
+ size_t offset_past_current_output =
+ ((*offset_for_adjustment == std::wstring::npos) ||
+ (*offset_for_adjustment < url_string.length())) ?
+ std::wstring::npos : (*offset_for_adjustment - url_string.length());
+ size_t* offset_into_ref =
+ (offset_past_current_output >= static_cast<size_t>(parsed.ref.len)) ?
+ NULL : &offset_past_current_output;
+ if (parsed.ref.len > 0) {
+ url_string.append(UTF8ToWideAndAdjustOffset(spec.substr(parsed.ref.begin,
+ parsed.ref.len),
+ offset_into_ref));
+ }
+ new_parsed->ref.len = url_string.length() - new_parsed->ref.begin;
+ if (offset_into_ref) {
+ *offset_for_adjustment = (*offset_into_ref == std::wstring::npos) ?
+ std::wstring::npos : (new_parsed->ref.begin + *offset_into_ref);
+ } else if (offset_past_current_output != std::wstring::npos) {
+ // We clamped the offset near the beginning of this function to ensure it
+ // was within the input URL. If we reach here, the input was something
+ // invalid and non-parseable such that the offset was past any component
+ // we could figure out. In this case it won't be represented in the
+ // output string, so reset it.
+ *offset_for_adjustment = std::wstring::npos;
+ }
+ }
+
+ // If we need to strip out http do it after the fact. This way we don't need
+ // to worry about how offset_for_adjustment is interpreted.
+ const size_t kHTTPSize = arraysize(kHTTP) - 1;
+ if (omit_http && !url_string.compare(0, kHTTPSize, kHTTP)) {
+ url_string = url_string.substr(kHTTPSize);
+ if (*offset_for_adjustment != std::wstring::npos) {
+ if (*offset_for_adjustment < kHTTPSize)
+ *offset_for_adjustment = std::wstring::npos;
+ else
+ *offset_for_adjustment -= kHTTPSize;
+ }
+ if (prefix_end)
+ *prefix_end -= kHTTPSize;
+
+ // Adjust new_parsed.
+ DCHECK(new_parsed->scheme.is_valid());
+ int delta = -(new_parsed->scheme.len + 3); // +3 for ://.
+ new_parsed->scheme.reset();
+ AdjustComponents(delta, new_parsed);
+ }
+
+ return url_string;
+}
+
+} // namespace
+
+const FormatUrlType kFormatUrlOmitNothing = 0;
+const FormatUrlType kFormatUrlOmitUsernamePassword = 1 << 0;
+const FormatUrlType kFormatUrlOmitHTTP = 1 << 1;
+const FormatUrlType kFormatUrlOmitTrailingSlashOnBareHostname = 1 << 2;
+const FormatUrlType kFormatUrlOmitAll = kFormatUrlOmitUsernamePassword |
+ kFormatUrlOmitHTTP | kFormatUrlOmitTrailingSlashOnBareHostname;
+
+// TODO(viettrungluu): We don't want non-POD globals; change this.
+std::set<int> explicitly_allowed_ports;
GURL FilePathToFileURL(const FilePath& path) {
// Produce a URL like "file:///C:/foo" for a regular file, or
@@ -1391,237 +1624,7 @@ void AppendFormattedHost(const GURL& url,
}
}
-/* static */
-void AppendFormattedComponent(const std::string& spec,
- const url_parse::Component& in_component,
- UnescapeRule::Type unescape_rules,
- std::wstring* output,
- url_parse::Component* out_component,
- size_t* offset_for_adjustment) {
- DCHECK(output);
- DCHECK(offset_for_adjustment);
- if (in_component.is_nonempty()) {
- out_component->begin = static_cast<int>(output->length());
- size_t offset_past_current_output =
- ((*offset_for_adjustment == std::wstring::npos) ||
- (*offset_for_adjustment < output->length())) ?
- std::wstring::npos : (*offset_for_adjustment - output->length());
- size_t* offset_into_component =
- (offset_past_current_output >= static_cast<size_t>(in_component.len)) ?
- NULL : &offset_past_current_output;
- if (unescape_rules == UnescapeRule::NONE) {
- output->append(UTF8ToWideAndAdjustOffset(
- spec.substr(in_component.begin, in_component.len),
- offset_into_component));
- } else {
- output->append(UTF16ToWideHack(UnescapeAndDecodeUTF8URLComponent(
- spec.substr(in_component.begin, in_component.len), unescape_rules,
- offset_into_component)));
- }
- out_component->len =
- static_cast<int>(output->length()) - out_component->begin;
- if (offset_into_component) {
- *offset_for_adjustment = (*offset_into_component == std::wstring::npos) ?
- std::wstring::npos : (out_component->begin + *offset_into_component);
- } else if (offset_past_current_output != std::wstring::npos) {
- *offset_for_adjustment += out_component->len - in_component.len;
- }
- } else {
- out_component->reset();
- }
-}
-
-std::wstring FormatUrl(const GURL& url,
- const std::wstring& languages,
- FormatUrlTypes format_types,
- UnescapeRule::Type unescape_rules,
- url_parse::Parsed* new_parsed,
- size_t* prefix_end,
- size_t* offset_for_adjustment) {
- url_parse::Parsed parsed_temp;
- if (!new_parsed)
- new_parsed = &parsed_temp;
- else
- *new_parsed = url_parse::Parsed();
- size_t offset_temp = std::wstring::npos;
- if (!offset_for_adjustment)
- offset_for_adjustment = &offset_temp;
-
- std::wstring url_string;
-
- // Check for empty URLs or 0 available text width.
- if (url.is_empty()) {
- if (prefix_end)
- *prefix_end = 0;
- *offset_for_adjustment = std::wstring::npos;
- return url_string;
- }
-
- // Special handling for view-source:. Don't use chrome::kViewSourceScheme
- // because this library shouldn't depend on chrome.
- const char* const kViewSource = "view-source";
- // Reject "view-source:view-source:..." to avoid deep recursion.
- const char* const kViewSourceTwice = "view-source:view-source:";
- if (url.SchemeIs(kViewSource) &&
- !StartsWithASCII(url.possibly_invalid_spec(), kViewSourceTwice, false)) {
- return FormatViewSourceUrl(url, languages, format_types,
- unescape_rules, new_parsed, prefix_end, offset_for_adjustment);
- }
-
- // We handle both valid and invalid URLs (this will give us the spec
- // regardless of validity).
- const std::string& spec = url.possibly_invalid_spec();
- const url_parse::Parsed& parsed = url.parsed_for_possibly_invalid_spec();
- if (*offset_for_adjustment >= spec.length())
- *offset_for_adjustment = std::wstring::npos;
-
- // Copy everything before the username (the scheme and the separators.)
- // These are ASCII.
- std::copy(spec.begin(),
- spec.begin() + parsed.CountCharactersBefore(url_parse::Parsed::USERNAME,
- true),
- std::back_inserter(url_string));
-
- const wchar_t kHTTP[] = L"http://";
- const char kFTP[] = "ftp.";
- // URLFixerUpper::FixupURL() treats "ftp.foo.com" as ftp://ftp.foo.com. This
- // means that if we trim "http://" off a URL whose host starts with "ftp." and
- // the user inputs this into any field subject to fixup (which is basically
- // all input fields), the meaning would be changed. (In fact, often the
- // formatted URL is directly pre-filled into an input field.) For this reason
- // we avoid stripping "http://" in this case.
- bool omit_http =
- (format_types & kFormatUrlOmitHTTP) && (url_string == kHTTP) &&
- (url.host().compare(0, arraysize(kFTP) - 1, kFTP) != 0);
-
- new_parsed->scheme = parsed.scheme;
-
- if ((format_types & kFormatUrlOmitUsernamePassword) != 0) {
- // Remove the username and password fields. We don't want to display those
- // to the user since they can be used for attacks,
- // e.g. "http://google.com:search@evil.ru/"
- new_parsed->username.reset();
- new_parsed->password.reset();
- if ((*offset_for_adjustment != std::wstring::npos) &&
- (parsed.username.is_nonempty() || parsed.password.is_nonempty())) {
- if (parsed.username.is_nonempty() && parsed.password.is_nonempty()) {
- // The seeming off-by-one and off-by-two in these first two lines are to
- // account for the ':' after the username and '@' after the password.
- if (*offset_for_adjustment >
- static_cast<size_t>(parsed.password.end())) {
- *offset_for_adjustment -=
- (parsed.username.len + parsed.password.len + 2);
- } else if (*offset_for_adjustment >
- static_cast<size_t>(parsed.username.begin)) {
- *offset_for_adjustment = std::wstring::npos;
- }
- } else {
- const url_parse::Component* nonempty_component =
- parsed.username.is_nonempty() ? &parsed.username : &parsed.password;
- // The seeming off-by-one in these first two lines is to account for the
- // '@' after the username/password.
- if (*offset_for_adjustment >
- static_cast<size_t>(nonempty_component->end())) {
- *offset_for_adjustment -= (nonempty_component->len + 1);
- } else if (*offset_for_adjustment >
- static_cast<size_t>(nonempty_component->begin)) {
- *offset_for_adjustment = std::wstring::npos;
- }
- }
- }
- } else {
- AppendFormattedComponent(spec, parsed.username, unescape_rules, &url_string,
- &new_parsed->username, offset_for_adjustment);
- if (parsed.password.is_valid())
- url_string.push_back(':');
- AppendFormattedComponent(spec, parsed.password, unescape_rules, &url_string,
- &new_parsed->password, offset_for_adjustment);
- if (parsed.username.is_valid() || parsed.password.is_valid())
- url_string.push_back('@');
- }
- if (prefix_end)
- *prefix_end = static_cast<size_t>(url_string.length());
-
- AppendFormattedHost(url, languages, &url_string, new_parsed,
- offset_for_adjustment);
-
- // Port.
- if (parsed.port.is_nonempty()) {
- url_string.push_back(':');
- new_parsed->port.begin = url_string.length();
- std::copy(spec.begin() + parsed.port.begin,
- spec.begin() + parsed.port.end(), std::back_inserter(url_string));
- new_parsed->port.len = url_string.length() - new_parsed->port.begin;
- } else {
- new_parsed->port.reset();
- }
-
- // Path and query both get the same general unescape & convert treatment.
- if (!(format_types & kFormatUrlOmitTrailingSlashOnBareHostname) ||
- !CanStripTrailingSlash(url)) {
- AppendFormattedComponent(spec, parsed.path, unescape_rules, &url_string,
- &new_parsed->path, offset_for_adjustment);
- }
- if (parsed.query.is_valid())
- url_string.push_back('?');
- AppendFormattedComponent(spec, parsed.query, unescape_rules, &url_string,
- &new_parsed->query, offset_for_adjustment);
-
- // Reference is stored in valid, unescaped UTF-8, so we can just convert.
- if (parsed.ref.is_valid()) {
- url_string.push_back('#');
- new_parsed->ref.begin = url_string.length();
- size_t offset_past_current_output =
- ((*offset_for_adjustment == std::wstring::npos) ||
- (*offset_for_adjustment < url_string.length())) ?
- std::wstring::npos : (*offset_for_adjustment - url_string.length());
- size_t* offset_into_ref =
- (offset_past_current_output >= static_cast<size_t>(parsed.ref.len)) ?
- NULL : &offset_past_current_output;
- if (parsed.ref.len > 0) {
- url_string.append(UTF8ToWideAndAdjustOffset(spec.substr(parsed.ref.begin,
- parsed.ref.len),
- offset_into_ref));
- }
- new_parsed->ref.len = url_string.length() - new_parsed->ref.begin;
- if (offset_into_ref) {
- *offset_for_adjustment = (*offset_into_ref == std::wstring::npos) ?
- std::wstring::npos : (new_parsed->ref.begin + *offset_into_ref);
- } else if (offset_past_current_output != std::wstring::npos) {
- // We clamped the offset near the beginning of this function to ensure it
- // was within the input URL. If we reach here, the input was something
- // invalid and non-parseable such that the offset was past any component
- // we could figure out. In this case it won't be represented in the
- // output string, so reset it.
- *offset_for_adjustment = std::wstring::npos;
- }
- }
-
- // If we need to strip out http do it after the fact. This way we don't need
- // to worry about how offset_for_adjustment is interpreted.
- const size_t kHTTPSize = arraysize(kHTTP) - 1;
- if (omit_http && !url_string.compare(0, kHTTPSize, kHTTP)) {
- url_string = url_string.substr(kHTTPSize);
- if (*offset_for_adjustment != std::wstring::npos) {
- if (*offset_for_adjustment < kHTTPSize)
- *offset_for_adjustment = std::wstring::npos;
- else
- *offset_for_adjustment -= kHTTPSize;
- }
- if (prefix_end)
- *prefix_end -= kHTTPSize;
-
- // Adjust new_parsed.
- DCHECK(new_parsed->scheme.is_valid());
- int delta = -(new_parsed->scheme.len + 3); // +3 for ://.
- new_parsed->scheme.reset();
- AdjustComponents(delta, new_parsed);
- }
-
- return url_string;
-}
-
-// TODO(viettrungluu): convert the code in wstring version to this form.
+// TODO(viettrungluu): convert the wstring |FormatUrlInternal()|.
string16 FormatUrl(const GURL& url,
const std::string& languages,
FormatUrlTypes format_types,
@@ -1630,8 +1633,9 @@ string16 FormatUrl(const GURL& url,
size_t* prefix_end,
size_t* offset_for_adjustment) {
return WideToUTF16Hack(
- FormatUrl(url, ASCIIToWide(languages), format_types, unescape_rules,
- new_parsed, prefix_end, offset_for_adjustment));
+ FormatUrlInternal(url, ASCIIToWide(languages), format_types,
+ unescape_rules, new_parsed, prefix_end,
+ offset_for_adjustment));
}
bool CanStripTrailingSlash(const GURL& url) {
diff --git a/net/base/net_util.h b/net/base/net_util.h
index a3bea0d..af3bd0a 100644
--- a/net/base/net_util.h
+++ b/net/base/net_util.h
@@ -294,15 +294,7 @@ void AppendFormattedHost(const GURL& url,
// 8. If the offset cannot be successfully adjusted (e.g. because it points
// into the middle of a component that was entirely removed, past the end of the
// string, or into the middle of an encoding sequence), it will be set to
-// std::wstring::npos.
-// TODO(viettrungluu): remove wstring version.
-std::wstring FormatUrl(const GURL& url,
- const std::wstring& languages,
- FormatUrlTypes format_types,
- UnescapeRule::Type unescape_rules,
- url_parse::Parsed* new_parsed,
- size_t* prefix_end,
- size_t* offset_for_adjustment);
+// string16::npos.
string16 FormatUrl(const GURL& url,
const std::string& languages,
FormatUrlTypes format_types,
@@ -315,11 +307,6 @@ string16 FormatUrl(const GURL& url,
// format_types = kFormatUrlOmitAll and unescape = SPACES. This is the typical
// set of flags for "URLs to display to the user". You should be cautious about
// using this for URLs which will be parsed or sent to other applications.
-// TODO(viettrungluu): remove wstring version.
-inline std::wstring FormatUrl(const GURL& url, const std::wstring& languages) {
- return FormatUrl(url, languages, kFormatUrlOmitAll, UnescapeRule::SPACES,
- NULL, NULL, NULL);
-}
inline string16 FormatUrl(const GURL& url, const std::string& languages) {
return FormatUrl(url, languages, kFormatUrlOmitAll, UnescapeRule::SPACES,
NULL, NULL, NULL);
diff --git a/net/base/net_util_unittest.cc b/net/base/net_util_unittest.cc
index a3b3afb..4975a68 100644
--- a/net/base/net_util_unittest.cc
+++ b/net/base/net_util_unittest.cc
@@ -395,16 +395,6 @@ struct UrlTestData {
size_t prefix_len;
};
-struct UrlTestDataDeprecated {
- const char* description;
- const char* input;
- const std::wstring languages;
- net::FormatUrlTypes format_types;
- UnescapeRule::Type escape_rules;
- const std::wstring output;
- size_t prefix_len;
-};
-
// Returns an addrinfo for the given 32-bit address (IPv4.)
// The result lives in static storage, so don't delete it.
// |bytes| should be an array of length 4.
@@ -866,17 +856,17 @@ TEST(NetUtilTest, IDNToUnicodeAdjustOffset) {
{2, 2},
{4, 4},
{5, 5},
- {6, std::wstring::npos},
- {16, std::wstring::npos},
+ {6, string16::npos},
+ {16, string16::npos},
{17, 7},
{18, 8},
- {19, std::wstring::npos},
- {25, std::wstring::npos},
+ {19, string16::npos},
+ {25, string16::npos},
{34, 12},
{35, 13},
{38, 16},
- {39, std::wstring::npos},
- {std::wstring::npos, std::wstring::npos},
+ {39, string16::npos},
+ {string16::npos, string16::npos},
};
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(adjust_cases); ++i) {
size_t offset = adjust_cases[i].input_offset;
@@ -1527,296 +1517,143 @@ TEST(NetUtilTest, FormatUrl) {
}
}
-TEST(NetUtilTest, FormatUrlDeprecated) {
- net::FormatUrlTypes default_format_type = net::kFormatUrlOmitUsernamePassword;
- const UrlTestDataDeprecated tests[] = {
- {"Empty URL", "", L"", default_format_type, UnescapeRule::NORMAL, L"", 0},
-
- {"Simple URL",
- "http://www.google.com/", L"", default_format_type, UnescapeRule::NORMAL,
- L"http://www.google.com/", 7},
-
- {"With a port number and a reference",
- "http://www.google.com:8080/#\xE3\x82\xB0", L"", default_format_type,
- UnescapeRule::NORMAL,
- L"http://www.google.com:8080/#\x30B0", 7},
-
- // -------- IDN tests --------
- {"Japanese IDN with ja",
- "http://xn--l8jvb1ey91xtjb.jp", L"ja", default_format_type,
- UnescapeRule::NORMAL, L"http://\x671d\x65e5\x3042\x3055\x3072.jp/", 7},
-
- {"Japanese IDN with en",
- "http://xn--l8jvb1ey91xtjb.jp", L"en", default_format_type,
- UnescapeRule::NORMAL, L"http://xn--l8jvb1ey91xtjb.jp/", 7},
-
- {"Japanese IDN without any languages",
- "http://xn--l8jvb1ey91xtjb.jp", L"", default_format_type,
- UnescapeRule::NORMAL,
- // Single script is safe for empty languages.
- L"http://\x671d\x65e5\x3042\x3055\x3072.jp/", 7},
-
- {"mailto: with Japanese IDN",
- "mailto:foo@xn--l8jvb1ey91xtjb.jp", L"ja", default_format_type,
- UnescapeRule::NORMAL,
- // GURL doesn't assume an email address's domain part as a host name.
- L"mailto:foo@xn--l8jvb1ey91xtjb.jp", 7},
-
- {"file: with Japanese IDN",
- "file://xn--l8jvb1ey91xtjb.jp/config.sys", L"ja", default_format_type,
- UnescapeRule::NORMAL,
- L"file://\x671d\x65e5\x3042\x3055\x3072.jp/config.sys", 7},
-
- {"ftp: with Japanese IDN",
- "ftp://xn--l8jvb1ey91xtjb.jp/config.sys", L"ja", default_format_type,
- UnescapeRule::NORMAL,
- L"ftp://\x671d\x65e5\x3042\x3055\x3072.jp/config.sys", 6},
-
- // -------- omit_username_password flag tests --------
- {"With username and password, omit_username_password=false",
- "http://user:passwd@example.com/foo", L"",
- net::kFormatUrlOmitNothing, UnescapeRule::NORMAL,
- L"http://user:passwd@example.com/foo", 19},
-
- {"With username and password, omit_username_password=true",
- "http://user:passwd@example.com/foo", L"", default_format_type,
- UnescapeRule::NORMAL, L"http://example.com/foo", 7},
-
- {"With username and no password",
- "http://user@example.com/foo", L"", default_format_type,
- UnescapeRule::NORMAL, L"http://example.com/foo", 7},
-
- {"Just '@' without username and password",
- "http://@example.com/foo", L"", default_format_type, UnescapeRule::NORMAL,
- L"http://example.com/foo", 7},
-
- // GURL doesn't think local-part of an email address is username for URL.
- {"mailto:, omit_username_password=true",
- "mailto:foo@example.com", L"", default_format_type, UnescapeRule::NORMAL,
- L"mailto:foo@example.com", 7},
-
- // -------- unescape flag tests --------
- {"Do not unescape",
- "http://%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB.jp/"
- "%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB"
- "?q=%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB", L"en", default_format_type,
- UnescapeRule::NONE,
- // GURL parses %-encoded hostnames into Punycode.
- L"http://xn--qcka1pmc.jp/%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB"
- L"?q=%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB", 7},
-
- {"Unescape normally",
- "http://%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB.jp/"
- "%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB"
- "?q=%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB", L"en", default_format_type,
- UnescapeRule::NORMAL,
- L"http://xn--qcka1pmc.jp/\x30B0\x30FC\x30B0\x30EB"
- L"?q=\x30B0\x30FC\x30B0\x30EB", 7},
-
- {"Unescape normally including unescape spaces",
- "http://www.google.com/search?q=Hello%20World", L"en", default_format_type,
- UnescapeRule::SPACES, L"http://www.google.com/search?q=Hello World", 7},
-
- /*
- {"unescape=true with some special characters",
- "http://user%3A:%40passwd@example.com/foo%3Fbar?q=b%26z", L"",
- net::kFormatUrlOmitNothing, UnescapeRule::NORMAL,
- L"http://user%3A:%40passwd@example.com/foo%3Fbar?q=b%26z", 25},
- */
- // Disabled: the resultant URL becomes "...user%253A:%2540passwd...".
-
- // -------- omit http: --------
- {"omit http with user name",
- "http://user@example.com/foo", L"", net::kFormatUrlOmitAll,
- UnescapeRule::NORMAL, L"example.com/foo", 0},
-
- {"omit http",
- "http://www.google.com/", L"en", net::kFormatUrlOmitHTTP,
- UnescapeRule::NORMAL, L"www.google.com/",
- 0},
-
- {"omit http with https",
- "https://www.google.com/", L"en", net::kFormatUrlOmitHTTP,
- UnescapeRule::NORMAL, L"https://www.google.com/",
- 8},
-
- {"omit http starts with ftp.",
- "http://ftp.google.com/", L"en", net::kFormatUrlOmitHTTP,
- UnescapeRule::NORMAL, L"http://ftp.google.com/",
- 7},
-
- // -------- omit trailing slash on bare hostname --------
- {"omit slash when it's the entire path",
- "http://www.google.com/", L"en",
- net::kFormatUrlOmitTrailingSlashOnBareHostname, UnescapeRule::NORMAL,
- L"http://www.google.com", 7},
- {"omit slash when there's a ref",
- "http://www.google.com/#ref", L"en",
- net::kFormatUrlOmitTrailingSlashOnBareHostname, UnescapeRule::NORMAL,
- L"http://www.google.com/#ref", 7},
- {"omit slash when there's a query",
- "http://www.google.com/?", L"en",
- net::kFormatUrlOmitTrailingSlashOnBareHostname, UnescapeRule::NORMAL,
- L"http://www.google.com/?", 7},
- {"omit slash when it's not the entire path",
- "http://www.google.com/foo", L"en",
- net::kFormatUrlOmitTrailingSlashOnBareHostname, UnescapeRule::NORMAL,
- L"http://www.google.com/foo", 7},
- {"omit slash for nonstandard URLs",
- "data:/", L"en", net::kFormatUrlOmitTrailingSlashOnBareHostname,
- UnescapeRule::NORMAL, L"data:/", 5},
- {"omit slash for file URLs",
- "file:///", L"en", net::kFormatUrlOmitTrailingSlashOnBareHostname,
- UnescapeRule::NORMAL, L"file:///", 7},
-
- // -------- view-source: --------
- {"view-source",
- "view-source:http://xn--qcka1pmc.jp/", L"ja", default_format_type,
- UnescapeRule::NORMAL, L"view-source:http://\x30B0\x30FC\x30B0\x30EB.jp/",
- 19},
-
- {"view-source of view-source",
- "view-source:view-source:http://xn--qcka1pmc.jp/", L"ja",
- default_format_type, UnescapeRule::NORMAL,
- L"view-source:view-source:http://xn--qcka1pmc.jp/", 12},
-
- // view-source should omit http and trailing slash where non-view-source
- // would.
- {"view-source omit http",
- "view-source:http://a.b/c", L"en", net::kFormatUrlOmitAll,
- UnescapeRule::NORMAL, L"view-source:a.b/c",
- 12},
- {"view-source omit http starts with ftp.",
- "view-source:http://ftp.b/c", L"en", net::kFormatUrlOmitAll,
- UnescapeRule::NORMAL, L"view-source:http://ftp.b/c",
- 19},
- {"view-source omit slash when it's the entire path",
- "view-source:http://a.b/", L"en", net::kFormatUrlOmitAll,
- UnescapeRule::NORMAL, L"view-source:a.b",
- 12},
- };
-
- for (size_t i = 0; i < arraysize(tests); ++i) {
- size_t prefix_len;
- std::wstring formatted = net::FormatUrl(
- GURL(tests[i].input), tests[i].languages, tests[i].format_types,
- tests[i].escape_rules, NULL, &prefix_len, NULL);
- EXPECT_EQ(tests[i].output, formatted) << tests[i].description;
- EXPECT_EQ(tests[i].prefix_len, prefix_len) << tests[i].description;
- }
-}
-
TEST(NetUtilTest, FormatUrlParsed) {
// No unescape case.
url_parse::Parsed parsed;
- std::wstring formatted = net::FormatUrl(
+ string16 formatted = net::FormatUrl(
GURL("http://\xE3\x82\xB0:\xE3\x83\xBC@xn--qcka1pmc.jp:8080/"
"%E3%82%B0/?q=%E3%82%B0#\xE3\x82\xB0"),
- L"ja", net::kFormatUrlOmitNothing, UnescapeRule::NONE, &parsed, NULL,
+ "ja", net::kFormatUrlOmitNothing, UnescapeRule::NONE, &parsed, NULL,
NULL);
- EXPECT_EQ(L"http://%E3%82%B0:%E3%83%BC@\x30B0\x30FC\x30B0\x30EB.jp:8080"
- L"/%E3%82%B0/?q=%E3%82%B0#\x30B0", formatted);
- EXPECT_EQ(L"%E3%82%B0",
+ EXPECT_EQ(WideToUTF16(
+ L"http://%E3%82%B0:%E3%83%BC@\x30B0\x30FC\x30B0\x30EB.jp:8080"
+ L"/%E3%82%B0/?q=%E3%82%B0#\x30B0"), formatted);
+ EXPECT_EQ(WideToUTF16(L"%E3%82%B0"),
formatted.substr(parsed.username.begin, parsed.username.len));
- EXPECT_EQ(L"%E3%83%BC",
+ EXPECT_EQ(WideToUTF16(L"%E3%83%BC"),
formatted.substr(parsed.password.begin, parsed.password.len));
- EXPECT_EQ(L"\x30B0\x30FC\x30B0\x30EB.jp",
+ EXPECT_EQ(WideToUTF16(L"\x30B0\x30FC\x30B0\x30EB.jp"),
formatted.substr(parsed.host.begin, parsed.host.len));
- EXPECT_EQ(L"8080", formatted.substr(parsed.port.begin, parsed.port.len));
- EXPECT_EQ(L"/%E3%82%B0/",
+ EXPECT_EQ(WideToUTF16(L"8080"),
+ formatted.substr(parsed.port.begin, parsed.port.len));
+ EXPECT_EQ(WideToUTF16(L"/%E3%82%B0/"),
formatted.substr(parsed.path.begin, parsed.path.len));
- EXPECT_EQ(L"q=%E3%82%B0",
+ EXPECT_EQ(WideToUTF16(L"q=%E3%82%B0"),
formatted.substr(parsed.query.begin, parsed.query.len));
- EXPECT_EQ(L"\x30B0", formatted.substr(parsed.ref.begin, parsed.ref.len));
+ EXPECT_EQ(WideToUTF16(L"\x30B0"),
+ formatted.substr(parsed.ref.begin, parsed.ref.len));
// Unescape case.
formatted = net::FormatUrl(
GURL("http://\xE3\x82\xB0:\xE3\x83\xBC@xn--qcka1pmc.jp:8080/"
"%E3%82%B0/?q=%E3%82%B0#\xE3\x82\xB0"),
- L"ja", net::kFormatUrlOmitNothing, UnescapeRule::NORMAL, &parsed, NULL,
+ "ja", net::kFormatUrlOmitNothing, UnescapeRule::NORMAL, &parsed, NULL,
NULL);
- EXPECT_EQ(L"http://\x30B0:\x30FC@\x30B0\x30FC\x30B0\x30EB.jp:8080"
- L"/\x30B0/?q=\x30B0#\x30B0", formatted);
- EXPECT_EQ(L"\x30B0",
+ EXPECT_EQ(WideToUTF16(L"http://\x30B0:\x30FC@\x30B0\x30FC\x30B0\x30EB.jp:8080"
+ L"/\x30B0/?q=\x30B0#\x30B0"), formatted);
+ EXPECT_EQ(WideToUTF16(L"\x30B0"),
formatted.substr(parsed.username.begin, parsed.username.len));
- EXPECT_EQ(L"\x30FC",
+ EXPECT_EQ(WideToUTF16(L"\x30FC"),
formatted.substr(parsed.password.begin, parsed.password.len));
- EXPECT_EQ(L"\x30B0\x30FC\x30B0\x30EB.jp",
+ EXPECT_EQ(WideToUTF16(L"\x30B0\x30FC\x30B0\x30EB.jp"),
formatted.substr(parsed.host.begin, parsed.host.len));
- EXPECT_EQ(L"8080", formatted.substr(parsed.port.begin, parsed.port.len));
- EXPECT_EQ(L"/\x30B0/", formatted.substr(parsed.path.begin, parsed.path.len));
- EXPECT_EQ(L"q=\x30B0",
+ EXPECT_EQ(WideToUTF16(L"8080"),
+ formatted.substr(parsed.port.begin, parsed.port.len));
+ EXPECT_EQ(WideToUTF16(L"/\x30B0/"),
+ formatted.substr(parsed.path.begin, parsed.path.len));
+ EXPECT_EQ(WideToUTF16(L"q=\x30B0"),
formatted.substr(parsed.query.begin, parsed.query.len));
- EXPECT_EQ(L"\x30B0", formatted.substr(parsed.ref.begin, parsed.ref.len));
+ EXPECT_EQ(WideToUTF16(L"\x30B0"),
+ formatted.substr(parsed.ref.begin, parsed.ref.len));
// Omit_username_password + unescape case.
formatted = net::FormatUrl(
GURL("http://\xE3\x82\xB0:\xE3\x83\xBC@xn--qcka1pmc.jp:8080/"
"%E3%82%B0/?q=%E3%82%B0#\xE3\x82\xB0"),
- L"ja", net::kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL,
- &parsed, NULL, NULL);
- EXPECT_EQ(L"http://\x30B0\x30FC\x30B0\x30EB.jp:8080"
- L"/\x30B0/?q=\x30B0#\x30B0", formatted);
+ "ja", net::kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL, &parsed,
+ NULL, NULL);
+ EXPECT_EQ(WideToUTF16(L"http://\x30B0\x30FC\x30B0\x30EB.jp:8080"
+ L"/\x30B0/?q=\x30B0#\x30B0"), formatted);
EXPECT_FALSE(parsed.username.is_valid());
EXPECT_FALSE(parsed.password.is_valid());
- EXPECT_EQ(L"\x30B0\x30FC\x30B0\x30EB.jp",
+ EXPECT_EQ(WideToUTF16(L"\x30B0\x30FC\x30B0\x30EB.jp"),
formatted.substr(parsed.host.begin, parsed.host.len));
- EXPECT_EQ(L"8080", formatted.substr(parsed.port.begin, parsed.port.len));
- EXPECT_EQ(L"/\x30B0/", formatted.substr(parsed.path.begin, parsed.path.len));
- EXPECT_EQ(L"q=\x30B0",
+ EXPECT_EQ(WideToUTF16(L"8080"),
+ formatted.substr(parsed.port.begin, parsed.port.len));
+ EXPECT_EQ(WideToUTF16(L"/\x30B0/"),
+ formatted.substr(parsed.path.begin, parsed.path.len));
+ EXPECT_EQ(WideToUTF16(L"q=\x30B0"),
formatted.substr(parsed.query.begin, parsed.query.len));
- EXPECT_EQ(L"\x30B0", formatted.substr(parsed.ref.begin, parsed.ref.len));
+ EXPECT_EQ(WideToUTF16(L"\x30B0"),
+ formatted.substr(parsed.ref.begin, parsed.ref.len));
// View-source case.
formatted = net::FormatUrl(
GURL("view-source:http://user:passwd@host:81/path?query#ref"),
- L"", net::kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL, &parsed,
+ "", net::kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL, &parsed,
NULL, NULL);
- EXPECT_EQ(L"view-source:http://host:81/path?query#ref", formatted);
- EXPECT_EQ(L"view-source:http",
+ EXPECT_EQ(WideToUTF16(L"view-source:http://host:81/path?query#ref"),
+ formatted);
+ EXPECT_EQ(WideToUTF16(L"view-source:http"),
formatted.substr(parsed.scheme.begin, parsed.scheme.len));
EXPECT_FALSE(parsed.username.is_valid());
EXPECT_FALSE(parsed.password.is_valid());
- EXPECT_EQ(L"host", formatted.substr(parsed.host.begin, parsed.host.len));
- EXPECT_EQ(L"81", formatted.substr(parsed.port.begin, parsed.port.len));
- EXPECT_EQ(L"/path", formatted.substr(parsed.path.begin, parsed.path.len));
- EXPECT_EQ(L"query", formatted.substr(parsed.query.begin, parsed.query.len));
- EXPECT_EQ(L"ref", formatted.substr(parsed.ref.begin, parsed.ref.len));
+ EXPECT_EQ(WideToUTF16(L"host"),
+ formatted.substr(parsed.host.begin, parsed.host.len));
+ EXPECT_EQ(WideToUTF16(L"81"),
+ formatted.substr(parsed.port.begin, parsed.port.len));
+ EXPECT_EQ(WideToUTF16(L"/path"),
+ formatted.substr(parsed.path.begin, parsed.path.len));
+ EXPECT_EQ(WideToUTF16(L"query"),
+ formatted.substr(parsed.query.begin, parsed.query.len));
+ EXPECT_EQ(WideToUTF16(L"ref"),
+ formatted.substr(parsed.ref.begin, parsed.ref.len));
// omit http case.
formatted = net::FormatUrl(
GURL("http://host:8000/a?b=c#d"),
- L"", net::kFormatUrlOmitHTTP, UnescapeRule::NORMAL, &parsed, NULL, NULL);
- EXPECT_EQ(L"host:8000/a?b=c#d", formatted);
+ "", net::kFormatUrlOmitHTTP, UnescapeRule::NORMAL, &parsed, NULL, NULL);
+ EXPECT_EQ(WideToUTF16(L"host:8000/a?b=c#d"), formatted);
EXPECT_FALSE(parsed.scheme.is_valid());
EXPECT_FALSE(parsed.username.is_valid());
EXPECT_FALSE(parsed.password.is_valid());
- EXPECT_EQ(L"host", formatted.substr(parsed.host.begin, parsed.host.len));
- EXPECT_EQ(L"8000", formatted.substr(parsed.port.begin, parsed.port.len));
- EXPECT_EQ(L"/a", formatted.substr(parsed.path.begin, parsed.path.len));
- EXPECT_EQ(L"b=c", formatted.substr(parsed.query.begin, parsed.query.len));
- EXPECT_EQ(L"d", formatted.substr(parsed.ref.begin, parsed.ref.len));
+ EXPECT_EQ(WideToUTF16(L"host"),
+ formatted.substr(parsed.host.begin, parsed.host.len));
+ EXPECT_EQ(WideToUTF16(L"8000"),
+ formatted.substr(parsed.port.begin, parsed.port.len));
+ EXPECT_EQ(WideToUTF16(L"/a"),
+ formatted.substr(parsed.path.begin, parsed.path.len));
+ EXPECT_EQ(WideToUTF16(L"b=c"),
+ formatted.substr(parsed.query.begin, parsed.query.len));
+ EXPECT_EQ(WideToUTF16(L"d"),
+ formatted.substr(parsed.ref.begin, parsed.ref.len));
// omit http starts with ftp case.
formatted = net::FormatUrl(
GURL("http://ftp.host:8000/a?b=c#d"),
- L"", net::kFormatUrlOmitHTTP, UnescapeRule::NORMAL, &parsed, NULL, NULL);
- EXPECT_EQ(L"http://ftp.host:8000/a?b=c#d", formatted);
+ "", net::kFormatUrlOmitHTTP, UnescapeRule::NORMAL, &parsed, NULL, NULL);
+ EXPECT_EQ(WideToUTF16(L"http://ftp.host:8000/a?b=c#d"), formatted);
EXPECT_TRUE(parsed.scheme.is_valid());
EXPECT_FALSE(parsed.username.is_valid());
EXPECT_FALSE(parsed.password.is_valid());
- EXPECT_EQ(L"http", formatted.substr(parsed.scheme.begin, parsed.scheme.len));
- EXPECT_EQ(L"ftp.host", formatted.substr(parsed.host.begin, parsed.host.len));
- EXPECT_EQ(L"8000", formatted.substr(parsed.port.begin, parsed.port.len));
- EXPECT_EQ(L"/a", formatted.substr(parsed.path.begin, parsed.path.len));
- EXPECT_EQ(L"b=c", formatted.substr(parsed.query.begin, parsed.query.len));
- EXPECT_EQ(L"d", formatted.substr(parsed.ref.begin, parsed.ref.len));
+ EXPECT_EQ(WideToUTF16(L"http"),
+ formatted.substr(parsed.scheme.begin, parsed.scheme.len));
+ EXPECT_EQ(WideToUTF16(L"ftp.host"),
+ formatted.substr(parsed.host.begin, parsed.host.len));
+ EXPECT_EQ(WideToUTF16(L"8000"),
+ formatted.substr(parsed.port.begin, parsed.port.len));
+ EXPECT_EQ(WideToUTF16(L"/a"),
+ formatted.substr(parsed.path.begin, parsed.path.len));
+ EXPECT_EQ(WideToUTF16(L"b=c"),
+ formatted.substr(parsed.query.begin, parsed.query.len));
+ EXPECT_EQ(WideToUTF16(L"d"),
+ formatted.substr(parsed.ref.begin, parsed.ref.len));
// omit http starts with 'f' case.
formatted = net::FormatUrl(
GURL("http://f/"),
- L"", net::kFormatUrlOmitHTTP, UnescapeRule::NORMAL, &parsed, NULL, NULL);
- EXPECT_EQ(L"f/", formatted);
+ "", net::kFormatUrlOmitHTTP, UnescapeRule::NORMAL, &parsed, NULL, NULL);
+ EXPECT_EQ(WideToUTF16(L"f/"), formatted);
EXPECT_FALSE(parsed.scheme.is_valid());
EXPECT_FALSE(parsed.username.is_valid());
EXPECT_FALSE(parsed.password.is_valid());
@@ -1824,8 +1661,10 @@ TEST(NetUtilTest, FormatUrlParsed) {
EXPECT_TRUE(parsed.path.is_valid());
EXPECT_FALSE(parsed.query.is_valid());
EXPECT_FALSE(parsed.ref.is_valid());
- EXPECT_EQ(L"f", formatted.substr(parsed.host.begin, parsed.host.len));
- EXPECT_EQ(L"/", formatted.substr(parsed.path.begin, parsed.path.len));
+ EXPECT_EQ(WideToUTF16(L"f"),
+ formatted.substr(parsed.host.begin, parsed.host.len));
+ EXPECT_EQ(WideToUTF16(L"/"),
+ formatted.substr(parsed.path.begin, parsed.path.len));
}
TEST(NetUtilTest, FormatUrlAdjustOffset) {
@@ -1839,13 +1678,13 @@ TEST(NetUtilTest, FormatUrlAdjustOffset) {
{22, 22},
{23, 23},
{25, 25},
- {26, std::wstring::npos},
- {500000, std::wstring::npos},
- {std::wstring::npos, std::wstring::npos},
+ {26, string16::npos},
+ {500000, string16::npos},
+ {string16::npos, string16::npos},
};
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(basic_cases); ++i) {
size_t offset = basic_cases[i].input_offset;
- net::FormatUrl(GURL("http://www.google.com/foo/"), L"en",
+ net::FormatUrl(GURL("http://www.google.com/foo/"), "en",
net::kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL,
NULL, NULL, &offset);
EXPECT_EQ(basic_cases[i].output_offset, offset);
@@ -1858,18 +1697,18 @@ TEST(NetUtilTest, FormatUrlAdjustOffset) {
} omit_auth_cases[] = {
{"http://foo:bar@www.google.com/", 6, 6},
{"http://foo:bar@www.google.com/", 7, 7},
- {"http://foo:bar@www.google.com/", 8, std::wstring::npos},
- {"http://foo:bar@www.google.com/", 10, std::wstring::npos},
- {"http://foo:bar@www.google.com/", 11, std::wstring::npos},
- {"http://foo:bar@www.google.com/", 14, std::wstring::npos},
+ {"http://foo:bar@www.google.com/", 8, string16::npos},
+ {"http://foo:bar@www.google.com/", 10, string16::npos},
+ {"http://foo:bar@www.google.com/", 11, string16::npos},
+ {"http://foo:bar@www.google.com/", 14, string16::npos},
{"http://foo:bar@www.google.com/", 15, 7},
{"http://foo:bar@www.google.com/", 25, 17},
- {"http://foo@www.google.com/", 9, std::wstring::npos},
+ {"http://foo@www.google.com/", 9, string16::npos},
{"http://foo@www.google.com/", 11, 7},
};
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(omit_auth_cases); ++i) {
size_t offset = omit_auth_cases[i].input_offset;
- net::FormatUrl(GURL(omit_auth_cases[i].input_url), L"en",
+ net::FormatUrl(GURL(omit_auth_cases[i].input_url), "en",
net::kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL,
NULL, NULL, &offset);
EXPECT_EQ(omit_auth_cases[i].output_offset, offset);
@@ -1882,30 +1721,30 @@ TEST(NetUtilTest, FormatUrlAdjustOffset) {
{12, 12},
{13, 13},
{19, 19},
- {20, std::wstring::npos},
+ {20, string16::npos},
{23, 19},
{26, 22},
- {std::wstring::npos, std::wstring::npos},
+ {string16::npos, string16::npos},
};
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(view_source_cases); ++i) {
size_t offset = view_source_cases[i].input_offset;
- net::FormatUrl(GURL("view-source:http://foo@www.google.com/"), L"en",
+ net::FormatUrl(GURL("view-source:http://foo@www.google.com/"), "en",
net::kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL,
NULL, NULL, &offset);
EXPECT_EQ(view_source_cases[i].output_offset, offset);
}
const AdjustOffsetCase idn_hostname_cases[] = {
- {8, std::wstring::npos},
- {16, std::wstring::npos},
- {24, std::wstring::npos},
+ {8, string16::npos},
+ {16, string16::npos},
+ {24, string16::npos},
{25, 12},
{30, 17},
};
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(idn_hostname_cases); ++i) {
size_t offset = idn_hostname_cases[i].input_offset;
// "http://\x671d\x65e5\x3042\x3055\x3072.jp/foo/"
- net::FormatUrl(GURL("http://xn--l8jvb1ey91xtjb.jp/foo/"), L"ja",
+ net::FormatUrl(GURL("http://xn--l8jvb1ey91xtjb.jp/foo/"), "ja",
net::kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL,
NULL, NULL, &offset);
EXPECT_EQ(idn_hostname_cases[i].output_offset, offset);
@@ -1913,22 +1752,22 @@ TEST(NetUtilTest, FormatUrlAdjustOffset) {
const AdjustOffsetCase unescape_cases[] = {
{25, 25},
- {26, std::wstring::npos},
- {27, std::wstring::npos},
+ {26, string16::npos},
+ {27, string16::npos},
{28, 26},
- {35, std::wstring::npos},
+ {35, string16::npos},
{41, 31},
{59, 33},
- {60, std::wstring::npos},
- {67, std::wstring::npos},
- {68, std::wstring::npos},
+ {60, string16::npos},
+ {67, string16::npos},
+ {68, string16::npos},
};
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(unescape_cases); ++i) {
size_t offset = unescape_cases[i].input_offset;
// "http://www.google.com/foo bar/\x30B0\x30FC\x30B0\x30EB"
net::FormatUrl(GURL(
"http://www.google.com/foo%20bar/%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB"),
- L"en", net::kFormatUrlOmitUsernamePassword, UnescapeRule::SPACES, NULL,
+ "en", net::kFormatUrlOmitUsernamePassword, UnescapeRule::SPACES, NULL,
NULL, &offset);
EXPECT_EQ(unescape_cases[i].output_offset, offset);
}
@@ -1936,30 +1775,30 @@ TEST(NetUtilTest, FormatUrlAdjustOffset) {
const AdjustOffsetCase ref_cases[] = {
{30, 30},
{31, 31},
- {32, std::wstring::npos},
+ {32, string16::npos},
{34, 32},
{37, 33},
- {38, std::wstring::npos},
+ {38, string16::npos},
};
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(ref_cases); ++i) {
size_t offset = ref_cases[i].input_offset;
// "http://www.google.com/foo.html#\x30B0\x30B0z"
net::FormatUrl(GURL(
- "http://www.google.com/foo.html#\xE3\x82\xB0\xE3\x82\xB0z"), L"en",
+ "http://www.google.com/foo.html#\xE3\x82\xB0\xE3\x82\xB0z"), "en",
net::kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL, NULL, NULL,
&offset);
EXPECT_EQ(ref_cases[i].output_offset, offset);
}
const AdjustOffsetCase omit_http_cases[] = {
- {0, std::wstring::npos},
- {3, std::wstring::npos},
+ {0, string16::npos},
+ {3, string16::npos},
{7, 0},
{8, 1},
};
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(omit_http_cases); ++i) {
size_t offset = omit_http_cases[i].input_offset;
- net::FormatUrl(GURL("http://www.google.com"), L"en",
+ net::FormatUrl(GURL("http://www.google.com"), "en",
net::kFormatUrlOmitHTTP, UnescapeRule::NORMAL, NULL, NULL, &offset);
EXPECT_EQ(omit_http_cases[i].output_offset, offset);
}
@@ -1971,7 +1810,7 @@ TEST(NetUtilTest, FormatUrlAdjustOffset) {
};
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(omit_http_start_with_ftp); ++i) {
size_t offset = omit_http_start_with_ftp[i].input_offset;
- net::FormatUrl(GURL("http://ftp.google.com"), L"en",
+ net::FormatUrl(GURL("http://ftp.google.com"), "en",
net::kFormatUrlOmitHTTP, UnescapeRule::NORMAL, NULL, NULL, &offset);
EXPECT_EQ(omit_http_start_with_ftp[i].output_offset, offset);
}
@@ -1979,12 +1818,12 @@ TEST(NetUtilTest, FormatUrlAdjustOffset) {
const AdjustOffsetCase omit_all_cases[] = {
{12, 0},
{13, 1},
- {0, std::wstring::npos},
- {3, std::wstring::npos},
+ {0, string16::npos},
+ {3, string16::npos},
};
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(omit_all_cases); ++i) {
size_t offset = omit_all_cases[i].input_offset;
- net::FormatUrl(GURL("http://user@foo.com/"), L"en", net::kFormatUrlOmitAll,
+ net::FormatUrl(GURL("http://user@foo.com/"), "en", net::kFormatUrlOmitAll,
UnescapeRule::NORMAL, NULL, NULL, &offset);
EXPECT_EQ(omit_all_cases[i].output_offset, offset);
}