diff --git a/components/script/dom/html/htmlimageelement.rs b/components/script/dom/html/htmlimageelement.rs
index 2eedcacaaf1..f5cf6124d9b 100644
--- a/components/script/dom/html/htmlimageelement.rs
+++ b/components/script/dom/html/htmlimageelement.rs
@@ -1960,6 +1960,7 @@ fn image_dimension_setter(element: &Element, attr: LocalName, value: u32, can_gc
}
/// Collect sequence of code points
+///
pub(crate) fn collect_sequence_characters(
s: &str,
mut predicate: impl FnMut(&char) -> bool,
@@ -1983,17 +1984,13 @@ pub fn parse_a_srcset_attribute(input: &str) -> Vec {
// > 4. Splitting loop: Collect a sequence of code points that are ASCII whitespace or
// > U+002C COMMA characters from input given position. If any U+002C COMMA
// > characters were collected, that is a parse error.
- let mut collected_comma = false;
+ // NOTE: A parse error indicating a non-fatal mismatch between the input and the
+ // requirements will be silently ignored to match the behavior of other browsers.
+ //
let (collected_characters, string_after_whitespace) =
collect_sequence_characters(remaining_string, |character| {
- if *character == ',' {
- collected_comma = true;
- }
*character == ',' || character.is_ascii_whitespace()
});
- if collected_comma {
- return Vec::new();
- }
// Add the length of collected whitespace, to find the start of the URL we are going
// to parse.
@@ -2222,6 +2219,9 @@ pub fn parse_a_srcset_attribute(input: &str) -> Vec {
error = true;
}
+ // Step 15. If error is still no, then append a new image source to candidates whose URL is
+ // url, associated with a width width if not absent and a pixel density density if not
+ // absent. Otherwise, there is a parse error.
if !error {
let image_source = ImageSource {
url: url.into(),
@@ -2229,6 +2229,8 @@ pub fn parse_a_srcset_attribute(input: &str) -> Vec {
};
candidates.push(image_source);
}
+
+ // Step 16. Return to the step labeled splitting loop.
}
candidates
}
diff --git a/tests/wpt/meta/html/semantics/embedded-content/the-img-element/srcset/parse-a-srcset-attribute.html.ini b/tests/wpt/meta/html/semantics/embedded-content/the-img-element/srcset/parse-a-srcset-attribute.html.ini
index 0766cbca817..cb446a5f799 100644
--- a/tests/wpt/meta/html/semantics/embedded-content/the-img-element/srcset/parse-a-srcset-attribute.html.ini
+++ b/tests/wpt/meta/html/semantics/embedded-content/the-img-element/srcset/parse-a-srcset-attribute.html.ini
@@ -1,13 +1,4 @@
[parse-a-srcset-attribute.html]
- ["data:,a,, , "]
- expected: FAIL
-
- [",,,data:,a"]
- expected: FAIL
-
- [" , ,,data:,a"]
- expected: FAIL
-
["data:,a 1.0w"]
expected: FAIL