Commit 455784de authored by brettw's avatar brettw Committed by Commit bot

Check for blacklist wildcards before creating GURL

The policy blacklist parser used to first check for "file" schemes first as a
special case before checking for wildcard hosts like "http://*", and the file
special-case had it's own wildcard special casing.

I am working on making "*" an invalid host character, and with this future
patch, creating a GURL of "file://*" will fail. This change moves the wildcard
handling above the file scheme checking so it will work regardless of whether
"*" is a valid host character or not.

The particular structure of this code looks like a result of adding the
wildcard handling ( https://codereview.chromium.org/1692503002/ ) after the
file handling was already in place.

BUG=652808

Review-Url: https://chromiumcodereview.appspot.com/2426733002
Cr-Commit-Position: refs/heads/master@{#426532}
parent 7acb2dd4
......@@ -262,6 +262,19 @@ bool URLBlacklist::FilterToComponents(const std::string& filter,
const std::string lc_filter = base::ToLowerASCII(filter);
const std::string url_scheme = url_formatter::SegmentURL(filter, &parsed);
// Check if it's a scheme wildcard pattern. We support both versions
// (scheme:* and scheme://*) the later being consistent with old filter
// definitions.
if (lc_filter == url_scheme + ":*" || lc_filter == url_scheme + "://*") {
scheme->assign(url_scheme);
host->clear();
*match_subdomains = true;
*port = 0;
path->clear();
query->clear();
return true;
}
if (url_scheme == url::kFileScheme) {
base::FilePath file_path;
if (!net::FileURLToFilePath(GURL(filter), &file_path))
......@@ -271,11 +284,7 @@ bool URLBlacklist::FilterToComponents(const std::string& filter,
host->clear();
*match_subdomains = true;
*port = 0;
// Special path when the |filter| is 'file://*' or 'file:*'.
if (lc_filter == "file:*" || lc_filter == "file://*")
path->clear();
else
*path = file_path.AsUTF8Unsafe();
*path = file_path.AsUTF8Unsafe();
#if defined(FILE_PATH_USES_WIN_SEPARATORS)
// Separators have to be canonicalized on Windows.
std::replace(path->begin(), path->end(), '\\', '/');
......@@ -284,19 +293,6 @@ bool URLBlacklist::FilterToComponents(const std::string& filter,
return true;
}
// Check if it's a scheme wildcard pattern. We support both versions
// (scheme:* and scheme://*) the later being consistent with old filter
// definitions.
if (lc_filter == url_scheme + ":*" || lc_filter == url_scheme + "://*") {
scheme->assign(url_scheme);
host->clear();
*match_subdomains = true;
*port = 0;
path->clear();
query->clear();
return true;
}
// According to documentation host can't be empty.
if (!parsed.host.is_nonempty())
return false;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment