Bug 1597639 - [css-grid] Don't accept two trailing <line-names> in the grid/grid-template shorthands. r=emilio

Differential Revision: https://phabricator.services.mozilla.com/D53909

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Mats Palmgren 2019-11-23 19:56:34 +00:00
Родитель 2abac68bde
Коммит 774a732b4a
5 изменённых файлов: 190 добавлений и 14 удалений

Просмотреть файл

@ -301,27 +301,37 @@
% endfor
let first_line_names = input.try(parse_line_names).unwrap_or_default();
if let Ok(mut string) = input.try(|i| i.expect_string().map(|s| s.as_ref().to_owned().into())) {
if let Ok(string) = input.try(|i| i.expect_string().map(|s| s.as_ref().to_owned().into())) {
let mut strings = vec![];
let mut values = vec![];
let mut line_names = vec![];
let mut names = first_line_names;
line_names.push(first_line_names);
strings.push(string);
loop {
line_names.push(names);
strings.push(string);
let size = input.try(|i| TrackSize::parse(context, i)).unwrap_or_default();
values.push(TrackListValue::TrackSize(size));
names = input.try(parse_line_names).unwrap_or_default();
if let Ok(v) = input.try(parse_line_names) {
let mut names_vec = names.into_vec();
names_vec.extend(v.into_iter());
names = names_vec.into();
}
let mut names = input.try(parse_line_names).unwrap_or_default();
let more_names = input.try(parse_line_names);
string = match input.try(|i| i.expect_string().map(|s| s.as_ref().to_owned().into())) {
Ok(s) => s,
_ => { // only the named area determines whether we should bail out
line_names.push(names.into());
match input.try(|i| i.expect_string().map(|s| s.as_ref().to_owned().into())) {
Ok(string) => {
strings.push(string);
if let Ok(v) = more_names {
// We got `[names] [more_names] "string"` - merge the two name lists.
let mut names_vec = names.into_vec();
names_vec.extend(v.into_iter());
names = names_vec.into();
}
line_names.push(names);
},
Err(e) => {
if more_names.is_ok() {
// We've parsed `"string" [names] [more_names]` but then failed to parse another `"string"`.
// The grammar doesn't allow two trailing `<line-names>` so this is an invalid value.
return Err(e.into());
}
// only the named area determines whether we should bail out
line_names.push(names);
break
},
};

Просмотреть файл

@ -0,0 +1,50 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>CSS Grid Layout Test: parsing 'grid' with invalid values</title>
<link rel="author" title="Mats Palmgren" href="mailto:mats@mozilla.com">
<link rel="help" href="https://drafts.csswg.org/css-grid/#propdef-grid">
<meta name="assert" content="grid-template supports only the grammar `<'grid-template'> | <'grid-template-rows'> / [ auto-flow && dense? ] <'grid-auto-columns'>? | [ auto-flow && dense? ] <'grid-auto-rows'>? / <'grid-template-columns'>`.">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/css/support/parsing-testcommon.js"></script>
</head>
<body>
<script>
test_invalid_value("grid", 'none none');
test_invalid_value("grid", 'none []');
test_invalid_value("grid", '10px');
test_invalid_value("grid", '20%');
test_invalid_value("grid", '5fr');
test_invalid_value("grid", '[a]');
test_invalid_value("grid", '[a] 10px');
test_invalid_value("grid", '[a] 10px []');
test_invalid_value("grid", '[]');
test_invalid_value("grid", '10px "a"');
test_invalid_value("grid", '[] 10px "a"');
test_invalid_value("grid", '10px [] "a"');
test_invalid_value("grid", '[] [] "a"');
test_invalid_value("grid", '"a" none');
test_invalid_value("grid", '"a" 10px 10px');
test_invalid_value("grid", '"a" [a] 10px');
test_invalid_value("grid", '"a" [a] 10px [a]');
test_invalid_value("grid", '"a" [a] [a] 10px');
test_invalid_value("grid", '"a" 10px [a] [a]');
test_invalid_value("grid", '"a" [a] [a]');
test_invalid_value("grid", '[a] "a" [a] [a]');
test_invalid_value("grid", '"a" "a" [a] [a]');
test_invalid_value("grid", '"a" [a] [a] / none');
test_invalid_value("grid", '"a" "a" [a] [a] / none');
test_invalid_value("grid", 'none / "a"');
test_invalid_value("grid", '"a" / none');
test_invalid_value("grid", 'none / [] "a"');
test_invalid_value("grid", 'none / "a" []');
test_invalid_value("grid", 'none / "a" [] 10px');
// FIXME: add more values to test full syntax
</script>
</body>
</html>

Просмотреть файл

@ -0,0 +1,33 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>CSS Grid Layout Test: parsing 'grid' with valid values</title>
<link rel="author" title="Mats Palmgren" href="mailto:mats@mozilla.com">
<link rel="help" href="https://drafts.csswg.org/css-grid/#propdef-grid">
<meta name="assert" content="grid-template supports the grammar `<'grid-template'> | <'grid-template-rows'> / [ auto-flow && dense? ] <'grid-auto-columns'>? | [ auto-flow && dense? ] <'grid-auto-rows'>? / <'grid-template-columns'>`.">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/css/support/parsing-testcommon.js"></script>
</head>
<body>
<script>
// <'grid-template'> values
test_valid_value("grid", 'auto / auto');
test_valid_value("grid", 'none / [a] 0px');
test_valid_value("grid", 'none / [] 0px', 'none / 0px');
test_valid_value("grid", '[a] 10px / auto');
test_valid_value("grid", '[a] 10px / none');
test_valid_value("grid", '[] 10px [] / [] auto []', '10px / auto');
test_valid_value("grid", '[a] "a" 10px');
test_valid_value("grid", '[a] "a" 10px []', '[a] "a" 10px');
test_valid_value("grid", '"a" 10px');
test_valid_value("grid", '[] "a" 10px', '"a" 10px');
test_valid_value("grid", '[a] "a" 10px [a]');
// FIXME: add more values to test full syntax
</script>
</body>
</html>

Просмотреть файл

@ -0,0 +1,51 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>CSS Grid Layout Test: parsing grid-template with invalid values</title>
<link rel="author" title="Mats Palmgren" href="mailto:mats@mozilla.com">
<link rel="help" href="https://drafts.csswg.org/css-grid/#propdef-grid-template">
<meta name="assert" content="grid-template supports only the grammar `none | [ <'grid-template-rows'> / <'grid-template-columns'> ] | [ <line-names>? <string> <track-size>? <line-names>? ]+ [ / <explicit-track-list> ]?`.">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/css/support/parsing-testcommon.js"></script>
</head>
<body>
<script>
test_invalid_value("grid-template", 'auto');
test_invalid_value("grid-template", 'none none');
test_invalid_value("grid-template", 'none []');
test_invalid_value("grid-template", '10px');
test_invalid_value("grid-template", '20%');
test_invalid_value("grid-template", '5fr');
test_invalid_value("grid-template", '[a]');
test_invalid_value("grid-template", '[a] 10px');
test_invalid_value("grid-template", '[a] 10px []');
test_invalid_value("grid-template", '[]');
test_invalid_value("grid-template", '10px "a"');
test_invalid_value("grid-template", '[] 10px "a"');
test_invalid_value("grid-template", '10px [] "a"');
test_invalid_value("grid-template", '[] [] "a"');
test_invalid_value("grid-template", '"a" none');
test_invalid_value("grid-template", '"a" 10px 10px');
test_invalid_value("grid-template", '"a" [a] 10px');
test_invalid_value("grid-template", '"a" [a] 10px [a]');
test_invalid_value("grid-template", '"a" [a] [a] 10px');
test_invalid_value("grid-template", '"a" 10px [a] [a]');
test_invalid_value("grid-template", '"a" [a] [a]');
test_invalid_value("grid-template", '[a] "a" [a] [a]');
test_invalid_value("grid-template", '"a" "a" [a] [a]');
test_invalid_value("grid-template", '"a" [a] [a] / none');
test_invalid_value("grid-template", '"a" "a" [a] [a] / none');
test_invalid_value("grid-template", 'none / "a"');
test_invalid_value("grid-template", '"a" / none');
test_invalid_value("grid-template", 'none / [] "a"');
test_invalid_value("grid-template", 'none / "a" []');
test_invalid_value("grid-template", 'none / "a" [] 10px');
// FIXME: add more values to test full syntax
</script>
</body>
</html>

Просмотреть файл

@ -0,0 +1,32 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>CSS Grid Layout Test: parsing grid-template with valid values</title>
<link rel="author" title="Mats Palmgren" href="mailto:mats@mozilla.com">
<link rel="help" href="https://drafts.csswg.org/css-grid/#propdef-grid-template">
<meta name="assert" content="grid-template supports the grammar `none | [ <'grid-template-rows'> / <'grid-template-columns'> ] | [ <line-names>? <string> <track-size>? <line-names>? ]+ [ / <explicit-track-list> ]?`.">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/css/support/parsing-testcommon.js"></script>
</head>
<body>
<script>
test_valid_value("grid-template", 'auto / auto');
test_valid_value("grid-template", 'none / [a] 0px');
test_valid_value("grid-template", 'none / [] 0px', 'none / 0px');
test_valid_value("grid-template", '[a] 10px / auto');
test_valid_value("grid-template", '[a] 10px / none');
test_valid_value("grid-template", '[] 10px [] / [] auto []', '10px / auto');
test_valid_value("grid-template", '[a] "a" 10px');
test_valid_value("grid-template", '[a] "a" 10px []', '[a] "a" 10px');
test_valid_value("grid-template", '"a" 10px');
test_valid_value("grid-template", '[] "a" 10px', '"a" 10px');
test_valid_value("grid-template", '[a] "a" 10px [a]');
// FIXME: add more values to test full syntax
</script>
</body>
</html>