Skip to content

Commit 3d644a5

Browse files
committed
Hash getter and setter.
1 parent e233b3d commit 3d644a5

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/quirks.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -208,13 +208,14 @@ pub fn hash(url: &Url) -> &str {
208208

209209
/// Setter for https://url.spec.whatwg.org/#dom-url-hash
210210
pub fn set_hash(url: &mut Url, new_hash: &str) {
211-
if url.scheme() != "javascript" {
212-
url.set_fragment(match new_hash {
213-
"" => None,
214-
_ if new_hash.starts_with('#') => Some(&new_hash[1..]),
215-
_ => Some(new_hash),
216-
})
217-
}
211+
url.set_fragment(match new_hash {
212+
// If the given value is the empty string,
213+
// then set context object’s url’s fragment to null and return.
214+
"" => None,
215+
// Let input be the given value with a single leading U+0023 (#) removed, if any.
216+
_ if new_hash.starts_with('#') => Some(&new_hash[1..]),
217+
_ => Some(new_hash),
218+
})
218219
}
219220

220221
fn trim(s: &str) -> &str {

0 commit comments

Comments
 (0)