Commit b7ceb6d7 authored by yhirano@chromium.org's avatar yhirano@chromium.org

Fix b180514: Some exception entries cannot be deleted from a setting panel.

This bug is caused by single trailing dot trimming from the input.
Fixed it by forbidding a pattern if canonicalization is not idempotent, i.e. the pattern canonicalized twice differs from the pattern canonicalized once.

BUG=180514


Review URL: https://chromiumcodereview.appspot.com/13251012

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@192984 0039d316-1c4b-4281-b951-d872f2087c98
parent fd3f1899
......@@ -156,6 +156,20 @@ ContentSettingsPattern ContentSettingsPattern::Builder::Build() {
} else {
is_valid_ = Validate(parts_);
}
if (!is_valid_)
return ContentSettingsPattern();
// A pattern is invalid if canonicalization is not idempotent.
// This check is here because it should be checked no matter
// use_legacy_validate_ is.
PatternParts parts(parts_);
if (!Canonicalize(&parts))
return ContentSettingsPattern();
if (ContentSettingsPattern(parts_, true) !=
ContentSettingsPattern(parts, true)) {
return ContentSettingsPattern();
}
return ContentSettingsPattern(parts_, is_valid_);
}
......
......@@ -206,6 +206,9 @@ TEST(ContentSettingsPatternTest, TrimEndingDotFromHost) {
Pattern("www.example.com.").ToString().c_str());
EXPECT_TRUE(Pattern("www.example.com.") == Pattern("www.example.com"));
EXPECT_TRUE(Pattern(".").IsValid());
EXPECT_STREQ(".", Pattern(".").ToString().c_str());
}
TEST(ContentSettingsPatternTest, FromString_WithNoWildcards) {
......@@ -443,6 +446,10 @@ TEST(ContentSettingsPatternTest, InvalidPatterns) {
EXPECT_STREQ("", Pattern("file://").ToString().c_str());
EXPECT_FALSE(Pattern("file:///foo/bar.html:8080").IsValid());
EXPECT_STREQ("", Pattern("file:///foo/bar.html:8080").ToString().c_str());
// Host having multiple ending dots.
EXPECT_FALSE(Pattern("www.example.com..").IsValid());
EXPECT_STREQ("", Pattern("www.example.com..").ToString().c_str());
}
TEST(ContentSettingsPatternTest, UnequalOperator) {
......
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