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

Unified Diff: url/url_canon_host.cc

Issue 2433583002: Reduce buggy usage of the registry controlled domain service. (Closed)
Patch Set: Fix Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: url/url_canon_host.cc
diff --git a/url/url_canon_host.cc b/url/url_canon_host.cc
index d4cdfd52bc566d3d4df295f80f5af3e630236e22..3de8f980a74fb3a661bf232e280ac99d3c6dda7d 100644
--- a/url/url_canon_host.cc
+++ b/url/url_canon_host.cc
@@ -309,6 +309,25 @@ bool DoComplexHost(const base::char16* host, int host_len,
}
template<typename CHAR, typename UCHAR>
+bool DoHostSubstring(const CHAR* spec,
+ const Component& host,
+ CanonOutput* output) {
+ bool has_non_ascii, has_escaped;
+ ScanHostname<CHAR, UCHAR>(spec, host, &has_non_ascii, &has_escaped);
+
+ bool success;
+ if (!has_non_ascii && !has_escaped) {
+ success = DoSimpleHost(&spec[host.begin], host.len,
+ output, &has_non_ascii);
+ DCHECK(!has_non_ascii);
+ } else {
+ success = DoComplexHost(&spec[host.begin], host.len,
+ has_non_ascii, has_escaped, output);
+ }
+ return success;
Peter Kasting 2016/10/22 05:04:20 Nit: Slightly simpler: if (has_non_ascii || has
brettw 2016/10/24 21:45:24 Done.
+}
+
+template<typename CHAR, typename UCHAR>
void DoHost(const CHAR* spec,
const Component& host,
CanonOutput* output,
@@ -320,23 +339,10 @@ void DoHost(const CHAR* spec,
return;
}
- bool has_non_ascii, has_escaped;
- ScanHostname<CHAR, UCHAR>(spec, host, &has_non_ascii, &has_escaped);
-
// Keep track of output's initial length, so we can rewind later.
const int output_begin = output->length();
- bool success;
- if (!has_non_ascii && !has_escaped) {
- success = DoSimpleHost(&spec[host.begin], host.len,
- output, &has_non_ascii);
- DCHECK(!has_non_ascii);
- } else {
- success = DoComplexHost(&spec[host.begin], host.len,
- has_non_ascii, has_escaped, output);
- }
-
- if (!success) {
+ if (!DoHostSubstring<CHAR, UCHAR>(spec, host, output)) {
Peter Kasting 2016/10/22 05:04:20 Nit: Reverse conditional and arms, so "else" does
brettw 2016/10/24 21:45:24 Done.
// Canonicalization failed. Set BROKEN to notify the caller.
host_info->family = CanonHostInfo::BROKEN;
} else {
@@ -396,4 +402,16 @@ void CanonicalizeHostVerbose(const base::char16* spec,
DoHost<base::char16, base::char16>(spec, host, output, host_info);
}
+bool CanonicalizeHostSubstring(const char* spec,
+ const Component& host,
+ CanonOutput* output) {
+ return DoHostSubstring<char, unsigned char>(spec, host, output);
+}
+
+bool CanonicalizeHostSubstring(const base::char16* spec,
+ const Component& host,
+ CanonOutput* output) {
+ return DoHostSubstring<base::char16, base::char16>(spec, host, output);
+}
+
} // namespace url

Powered by Google App Engine
This is Rietveld 408576698