mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
Fixes panic on DOMString::strip_leading_and_trailing_ascii_whitespace
This commit is contained in:
parent
dd5e5e9294
commit
1f99bf4631
3 changed files with 44 additions and 9 deletions
|
@ -182,16 +182,16 @@ impl DOMString {
|
|||
return;
|
||||
}
|
||||
|
||||
let last_non_whitespace = match self.0.rfind(|ref c| !char::is_ascii_whitespace(c)) {
|
||||
Some(idx) => idx + 1,
|
||||
None => {
|
||||
self.0.clear();
|
||||
return;
|
||||
},
|
||||
};
|
||||
let first_non_whitespace = self.0.find(|ref c| !char::is_ascii_whitespace(c)).unwrap();
|
||||
let trailing_whitespace_len = self
|
||||
.0
|
||||
.trim_end_matches(|ref c| char::is_ascii_whitespace(c))
|
||||
.len();
|
||||
self.0.truncate(trailing_whitespace_len);
|
||||
if self.0.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
self.0.truncate(last_non_whitespace);
|
||||
let first_non_whitespace = self.0.find(|ref c| !char::is_ascii_whitespace(c)).unwrap();
|
||||
let _ = self.0.replace_range(0..first_non_whitespace, "");
|
||||
}
|
||||
|
||||
|
|
|
@ -14006,6 +14006,12 @@
|
|||
{}
|
||||
]
|
||||
],
|
||||
"mozilla/input_value.html": [
|
||||
[
|
||||
"/_mozilla/mozilla/input_value.html",
|
||||
{}
|
||||
]
|
||||
],
|
||||
"mozilla/interface_member_exposed.html": [
|
||||
[
|
||||
"/_mozilla/mozilla/interface_member_exposed.html",
|
||||
|
@ -27049,6 +27055,10 @@
|
|||
"031e67e0c3bfd25bb32a8c1727864cdcf8bd641b",
|
||||
"testharness"
|
||||
],
|
||||
"mozilla/input_value.html": [
|
||||
"a2a12d44d0331164651816710eeb2ddcb1738735",
|
||||
"testharness"
|
||||
],
|
||||
"mozilla/interface_member_exposed.html": [
|
||||
"dd637cf92a894e4569e8fb0baf11eea6968033af",
|
||||
"testharness"
|
||||
|
|
25
tests/wpt/mozilla/tests/mozilla/input_value.html
Normal file
25
tests/wpt/mozilla/tests/mozilla/input_value.html
Normal file
|
@ -0,0 +1,25 @@
|
|||
<!doctype html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title></title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<input id="0" type="url" value="">
|
||||
<input id="1" type="url" value=" 黑aaab">
|
||||
<input id="2" type="url" value="三体! ">
|
||||
<input id="3" type="url" value="#β">
|
||||
<input id="4" type="url" value=" #β ">
|
||||
<script>
|
||||
// Testing that unicode values are correctly handled in
|
||||
// DOMString::strip_leading_and_trailing_ascii_whitespace
|
||||
test(function() {
|
||||
var expected = ["", "黑aaab", "三体!", "#β", "#β"];
|
||||
for (var i = 0; i < expected.length; i++) {
|
||||
var input = window.document.getElementById(i.toString());
|
||||
assert_equals(input.value, expected[i]);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
Loading…
Add table
Add a link
Reference in a new issue