mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
style: Fix media query parsing when invalid queries are present.
This commit is contained in:
parent
e600e0495c
commit
f69983930d
3 changed files with 28 additions and 10 deletions
|
@ -243,19 +243,13 @@ pub fn parse_media_query_list(input: &mut Parser) -> MediaList {
|
|||
}
|
||||
|
||||
let mut media_queries = vec![];
|
||||
let mut found_invalid = false;
|
||||
loop {
|
||||
match input.parse_until_before(Delimiter::Comma, MediaQuery::parse) {
|
||||
Ok(mq) => if !found_invalid {
|
||||
Ok(mq) => {
|
||||
media_queries.push(mq);
|
||||
},
|
||||
Err(..) => if !found_invalid {
|
||||
media_queries.clear();
|
||||
Err(..) => {
|
||||
media_queries.push(MediaQuery::never_matching());
|
||||
// Consume the rest of the input as if they were valid
|
||||
// expressions (they might be, they might not), but ignore the
|
||||
// result, this allows correctly parsing invalid media queries.
|
||||
found_invalid = true;
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -266,8 +260,6 @@ pub fn parse_media_query_list(input: &mut Parser) -> MediaList {
|
|||
}
|
||||
}
|
||||
|
||||
debug_assert!(!found_invalid || media_queries.len() == 1);
|
||||
|
||||
MediaList {
|
||||
media_queries: media_queries,
|
||||
}
|
||||
|
|
|
@ -11066,6 +11066,12 @@
|
|||
{}
|
||||
]
|
||||
],
|
||||
"css/media_bogus_query_sequence.html": [
|
||||
[
|
||||
"/_mozilla/css/media_bogus_query_sequence.html",
|
||||
{}
|
||||
]
|
||||
],
|
||||
"css/media_calc_crash.html": [
|
||||
[
|
||||
"/_mozilla/css/media_calc_crash.html",
|
||||
|
@ -22295,6 +22301,10 @@
|
|||
"477c77a8ca848cf57b440ea7d74cc0edc97aa2cb",
|
||||
"support"
|
||||
],
|
||||
"css/media_bogus_query_sequence.html": [
|
||||
"88fb8ef33c4870966a1691f1dd992362ebe5f24e",
|
||||
"testharness"
|
||||
],
|
||||
"css/media_calc_crash.html": [
|
||||
"14034fed9727ceb0c17b17b33fbc1552bc7c949e",
|
||||
"testharness"
|
||||
|
|
16
tests/wpt/mozilla/tests/css/media_bogus_query_sequence.html
Normal file
16
tests/wpt/mozilla/tests/css/media_bogus_query_sequence.html
Normal file
|
@ -0,0 +1,16 @@
|
|||
<!doctype html>
|
||||
<meta charset="utf-8">
|
||||
<title>CSS Test: Media query with a bogus query doesn't turn the whole media query list invalid.</title>
|
||||
<style>
|
||||
@media not all and (bogus), all {
|
||||
#test { display: inline }
|
||||
}
|
||||
</style>
|
||||
<p id="test"></p>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script>
|
||||
test(function() {
|
||||
assert_equals(getComputedStyle(document.getElementById('test')).display, "inline");
|
||||
}, "Media query with a bogus query doesn't turn the whole media query list invalid");
|
||||
</script>
|
Loading…
Add table
Add a link
Reference in a new issue