WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED CONFIGURATION CHANGED
199752
window.location.hash is not URL encoded when set from Javascript
https://bugs.webkit.org/show_bug.cgi?id=199752
Summary
window.location.hash is not URL encoded when set from Javascript
Robert Flack
Reported
2019-07-12 09:05:34 PDT
Created
attachment 374014
[details]
Demo of inconsistent hash readback. When Javascript sets the location hash, it reads back as the exact string which Javascript set. This seems to remain even if the page is reloaded. However, if the user copies the URL to another tab, the string is URL encoded resulting in a different location.hash read from Javascript. This results in a subtle bug if the developer does not explicitly encode / decode the location hash. See
https://output.jsbin.com/jikefe
for live demo or the following: <!DOCTYPE html> <body> <div id="log"></div> </body> <script> document.addEventListener('DOMContentLoaded', function() { if (window.location.hash == '') window.location.hash = 'test encoding'; else hashchange(); }); function hashchange() { document.getElementById('log').textContent = window.location.hash; } window.addEventListener('hashchange', hashchange); </script> When the demo site sets the location hash it is read back with a space in Safari 12 and Edge 18, in Chrome and Firefox the value read back is url encoded which it will be if the URL is copied to another tab.
Attachments
Demo of inconsistent hash readback.
(387 bytes, text/html)
2019-07-12 09:05 PDT
,
Robert Flack
no flags
Details
Safari 15.5 matches other browsers
(400.66 KB, image/png)
2022-05-30 09:54 PDT
,
Ahmad Saleem
no flags
Details
View All
Add attachment
proposed patch, testcase, etc.
Robert Flack
Comment 1
2019-07-12 10:47:15 PDT
FYI I've created a web-platform-tests PR here:
https://github.com/web-platform-tests/wpt/pull/17807
Radar WebKit Bug Importer
Comment 2
2019-07-12 17:00:04 PDT
<
rdar://problem/53034220
>
Ahmad Saleem
Comment 3
2022-05-30 09:54:46 PDT
Created
attachment 459866
[details]
Safari 15.5 matches other browsers Based on testing with Safari 15.5, now due to Spec change or browser changes on handling URL encoding, all browsers now behave same based on the test case. Hence, I think this should be marked as "Resolved Fixed". Thanks!
Alexey Proskuryakov
Comment 4
2022-05-31 09:58:26 PDT
Thank you for checking! We have this WPT test imported now, and it passes.
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug