diff options
author | Cristian Brinza <cristianb@gmail.com> | 2024-09-09 19:58:26 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-09 16:58:26 +0000 |
commit | 2993577ac0ea2638a1dde3cfb9e4cb7b45b542ae (patch) | |
tree | a2ad8c04d83eef7cab625b457dc770367ade02bb /components/script/dom | |
parent | cc3c69b95364268610858f4a149d84c4cfee1a5f (diff) | |
download | servo-2993577ac0ea2638a1dde3cfb9e4cb7b45b542ae.tar.gz servo-2993577ac0ea2638a1dde3cfb9e4cb7b45b542ae.zip |
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>
Diffstat (limited to 'components/script/dom')
-rw-r--r-- | components/script/dom/location.rs | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/components/script/dom/location.rs b/components/script/dom/location.rs index 2d123fcc95b..e8d7ee16f1e 100644 --- a/components/script/dom/location.rs +++ b/components/script/dom/location.rs @@ -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)) + Ok(Some(copy_url)) + } }) } |