mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-10 23:47:55 -05:00
Sanitize trailing ? when stripping analytics parameters from URL
Safari doesn't remove the ? from a URL when setting `url.search = ''` which results in links not correctly applying `:visited`. For example, before this change: https://www.reddit.com/?utm_foo=bar -> https://www.reddit.com/? and links to https://www.reddit.com/ don't render as :visited After this change, https://www.reddit.com/?utm_foo=bar -> https://www.reddit.com/ and links to https://www.reddit.com/ are properly empurpled. Additionally, hash is preserved: https://www.reddit.com/?utm_foo=bar&baz=qux#hoopla -> https://www.reddit.com/?baz=qux#hoopla
This commit is contained in:
@@ -329,6 +329,10 @@ r.analytics = {
|
||||
var a = document.createElement('a');
|
||||
a.href = window.location.href;
|
||||
a.search = $.param(strippedParams);
|
||||
if (!a.search) {
|
||||
// Safari leaves a trailing ? when search is empty
|
||||
a.href = a.href.replace(/\?(#.+)?$/, a.hash);
|
||||
}
|
||||
|
||||
window.history.replaceState({}, document.title, a.href);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user