mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
script: Added missing spec step in Location::SetHash
(#33380)
* Implement missing spec step in Location::SetHash Signed-off-by: crbrz <cristianb@gmail.com> * Fixed wrong URL fragment when hash set to empty string Signed-off-by: crbrz <cristianb@gmail.com> * Add WPT tests Signed-off-by: crbrz <cristianb@gmail.com> --------- Signed-off-by: crbrz <cristianb@gmail.com>
This commit is contained in:
parent
cc3c69b953
commit
2993577ac0
4 changed files with 64 additions and 6 deletions
|
@ -315,13 +315,19 @@ impl LocationMethods for Location {
|
|||
// Step 5: Set copyURL's fragment to the empty string.
|
||||
// Step 6: Basic URL parse input, with copyURL as url and fragment state as
|
||||
// state override.
|
||||
copy_url.as_mut_url().set_fragment(match value.0.as_str() {
|
||||
"" => Some("#"),
|
||||
_ if value.0.starts_with('#') => Some(&value.0[1..]),
|
||||
_ => Some(&value.0),
|
||||
});
|
||||
let new_fragment = if value.0.starts_with('#') {
|
||||
Some(&value.0[1..])
|
||||
} else {
|
||||
Some(value.0.as_str())
|
||||
};
|
||||
// Step 7: If copyURL's fragment is this's url's fragment, then return.
|
||||
if copy_url.fragment() == new_fragment {
|
||||
Ok(None)
|
||||
} else {
|
||||
copy_url.as_mut_url().set_fragment(new_fragment);
|
||||
|
||||
Ok(Some(copy_url))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
|
14
tests/wpt/meta/MANIFEST.json
vendored
14
tests/wpt/meta/MANIFEST.json
vendored
|
@ -641539,6 +641539,20 @@
|
|||
{}
|
||||
]
|
||||
],
|
||||
"location_hash_set_empty_string.html": [
|
||||
"bfde4e638290c0ef1b4068b399e7428d090544b2",
|
||||
[
|
||||
null,
|
||||
{}
|
||||
]
|
||||
],
|
||||
"location_hashchange_infinite_loop.html": [
|
||||
"694c619ecabdb8b8e2f69fc6144e59f5a8279818",
|
||||
[
|
||||
null,
|
||||
{}
|
||||
]
|
||||
],
|
||||
"location_host.html": [
|
||||
"d93bf47e506f131e29f2009e1f4446bc5844aee5",
|
||||
[
|
||||
|
|
17
tests/wpt/tests/html/browsers/history/the-location-interface/location_hash_set_empty_string.html
vendored
Normal file
17
tests/wpt/tests/html/browsers/history/the-location-interface/location_hash_set_empty_string.html
vendored
Normal file
|
@ -0,0 +1,17 @@
|
|||
<!doctype html>
|
||||
<meta charset="utf-8">
|
||||
<title>Set window.location.hash to an empty string</title>
|
||||
<link rel="author" href="mailto:cristianb@gmail.com">
|
||||
<link rel="help" href="https://html.spec.whatwg.org/multipage/#dom-location-hash">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script>
|
||||
const orig_location = window.location.href;
|
||||
|
||||
window.location.hash = '';
|
||||
|
||||
test(() => {
|
||||
assert_true(window.location.hash === '');
|
||||
assert_true(window.location.href === orig_location + '#');
|
||||
}, 'window.location.hash is an empty string');
|
||||
</script>
|
|
@ -0,0 +1,21 @@
|
|||
<!doctype html>
|
||||
<meta charset="utf-8">
|
||||
<title>Set window.location.hash to same value while handling event hashchange</title>
|
||||
<link rel="author" href="mailto:cristianb@gmail.com">
|
||||
<link rel="help" href="https://html.spec.whatwg.org/multipage/#dom-location-hash">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script>
|
||||
let count = 0;
|
||||
|
||||
window.onhashchange = () => {
|
||||
count += 1;
|
||||
window.location.hash = 'running';
|
||||
}
|
||||
|
||||
promise_test(async t => {
|
||||
window.location.hash = 'running';
|
||||
|
||||
await t.step_wait(() => count === 1);
|
||||
}, 'Setting window.location.hash to same value while handling hashchange event shouldn\'t cause an infinite loop.');
|
||||
</script>
|
Loading…
Add table
Add a link
Reference in a new issue