Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check for empty attribute-value for ⚡ #13182

Merged
merged 1 commit into from
Apr 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion components/de_amp/browser/de_amp_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ namespace {
// Check for "amp" or "⚡" in <html> tag
// https://amp.dev/documentation/guides-and-tutorials/learn/spec/amphtml/?format=websites#ampd
constexpr char kGetHtmlTagPattern[] = "(<\\s*?html\\s.*?>)";
// To see the expected behaviour of this regex, please see unit tests in
// de_amp_util_unittest.cc
constexpr char kDetectAmpPattern[] =
"(?:<.*?\\s.*?(amp|⚡|amp=\"\\s*\"|amp='\\s*')(?:\\s.*?>|>|/>))";
"(?:<.*?\\s.*?(amp|⚡|⚡=\"\\s*\"|⚡=\'\\s*\'|amp=\"\\s*\"|amp='\\s*')(?:\\s.*"
"?>|>|/>))";
// Look for canonical link tag and get href
// https://amp.dev/documentation/guides-and-tutorials/learn/spec/amphtml/?format=websites#canon
constexpr char kFindCanonicalLinkTagPattern[] =
Expand Down
33 changes: 33 additions & 0 deletions components/de_amp/browser/test/de_amp_util_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,39 @@ TEST(DeAmpUtilUnitTest, DetectAmpWithWordAmpNotAtEnd) {
CheckFindCanonicalLinkResult("https://abc.com", body, true);
}

TEST(DeAmpUtilUnitTest, DetectAmpWithAmpEmptyAttribute) {
const std::string body =
"<html amp=\"\" xyzzy>"
"<head>"
"<link rel=\"canonical\" href=\"https://abc.com\"/>"
"</head>"
"<body></body>"
"</html>";
CheckFindCanonicalLinkResult("https://abc.com", body, true);
}

TEST(DeAmpUtilUnitTest, DetectAmpWithEmojiEmptyAttribute) {
const std::string body =
"<html tomato ⚡=\"\" xyzzy >"
"<head>"
"<link rel=\"canonical\" href=\"https://abc.com\"/>"
"</head>"
"<body></body>"
"</html>";
CheckFindCanonicalLinkResult("https://abc.com", body, true);
}

TEST(DeAmpUtilUnitTest, DetectAmpWithEmojiEmptyAttributeSingleQuotes) {
const std::string body =
"<html tomato ⚡='' xyzzy >"
"<head>"
"<link rel=\"canonical\" href=\"https://abc.com\"/>"
"</head>"
"<body></body>"
"</html>";
CheckFindCanonicalLinkResult("https://abc.com", body, true);
}

TEST(DeAmpUtilUnitTest, DetectAmpMixedCase) {
const std::string body =
"<DOCTYPE! html>\n"
Expand Down