Commit 31c0c978 authored by Xiaocheng Hu's avatar Xiaocheng Hu Committed by Commit Bot

Do not parse @counter-style rules with invalid names

The spec requires a @counter-style rule to be invalid if its name is
among the disallowed values. This patch implements it.

Bug: 687225
Change-Id: Ib4c06453c30301cbc64e18950c8686fe63e08220
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2533855
Commit-Queue: Xiaocheng Hu <xiaochengh@chromium.org>
Reviewed-by: default avatarAnders Hartvoll Ruud <andruud@chromium.org>
Cr-Commit-Position: refs/heads/master@{#827572}
parent d22bb1cd
...@@ -943,9 +943,11 @@ StyleRuleCounterStyle* CSSParserImpl::ConsumeCounterStyleRule( ...@@ -943,9 +943,11 @@ StyleRuleCounterStyle* CSSParserImpl::ConsumeCounterStyleRule(
if (!prelude.AtEnd()) if (!prelude.AtEnd())
return nullptr; return nullptr;
// TODO(crbug.com/687225): If the name is invalid (none, decimal, disc and if (name_token.GetType() != kIdentToken ||
// CSS-wide keywords), should the entire rule be invalid, or does it simply !css_parsing_utils::IsCustomIdent<CSSValueID::kNone, CSSValueID::kDecimal,
// not define a counter style? CSSValueID::kDisc>(name_token.Id()))
return nullptr;
AtomicString name(name_token.Value().ToString()); AtomicString name(name_token.Value().ToString());
if (observer_) { if (observer_) {
......
<!DOCTYPE html>
<link rel="help" href="https://drafts.csswg.org/css-counter-styles-3/#the-counter-style-rule">
<link rel="author" href="mailto:xiaochengh@chromium.org">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support/counter-style-testcommon.js"></script>
<script>
test_valid_name('foo');
test_invalid_name('');
test_invalid_name('none');
test_invalid_name('initial');
test_invalid_name('inherit');
test_invalid_name('unset');
test_invalid_name('decimal');
test_invalid_name('disc');
</script>
...@@ -53,3 +53,31 @@ function test_invalid_counter_style_descriptor(descriptor, value) { ...@@ -53,3 +53,31 @@ function test_invalid_counter_style_descriptor(descriptor, value) {
test_counter_style_descriptor(descriptor, value, undefined); test_counter_style_descriptor(descriptor, value, undefined);
} }
function test_counter_style_name(name, isValid) {
let style = document.createElement('style');
style.textContent = `@counter-style ${name} { system: symbolic; symbols: 'X' 'Y'; }`;
document.head.appendChild(style);
test(() => {
let rule = style.sheet.cssRules[0];
if (!isValid) {
assert_equals(rule, undefined);
return;
}
assert_not_equals(rule, undefined);
assert_equals(rule.constructor.name, 'CSSCounterStyleRule');
assert_equals(rule.name, name);
}, `@counter-style name ${name} is ${isValid ? 'valid' : 'invalid'}`);
style.remove();
}
function test_valid_name(name) {
test_counter_style_name(name, true);
}
function test_invalid_name(name) {
test_counter_style_name(name, 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