diff --git a/boot/boot.js b/boot/boot.js index ce713916d..c5aa25464 100644 --- a/boot/boot.js +++ b/boot/boot.js @@ -316,8 +316,25 @@ $tw.utils.htmlDecode = function(s) { return s.toString().replace(/</mg,"<").replace(/ /mg,"\xA0").replace(/>/mg,">").replace(/"/mg,"\"").replace(/&/mg,"&"); }; -/** @deprecated Use window.location.hash instead. */ -$tw.utils.getLocationHash = () => window.location.hash; +/* +Get the browser location.hash. We don't use location.hash because of the way that Firefox auto-urldecodes it (see http://stackoverflow.com/questions/1703552/encoding-of-window-location-hash) +*/ +$tw.utils.getLocationHash = function() { + const href = window.location.href, + idx = href.indexOf("#"); + + if(idx === -1) { + return "#"; + } + + const afterHash = href.substring(idx + 1); + if(afterHash.startsWith("#") || afterHash.startsWith("%23")) { + // Special case: ignore location hash if it itself starts with a # + return "#"; + } + return href.substring(idx); +}; + /** @deprecated Pad a string to a given length with "0"s. Length defaults to 2 */ $tw.utils.pad = function(value,length = 2) { diff --git a/editions/tw5.com/tiddlers/releasenotes/5.4.0/deprecate-util-func.tid b/editions/tw5.com/tiddlers/releasenotes/5.4.0/deprecate-util-func.tid index b2c05acab..83e4b83e4 100644 --- a/editions/tw5.com/tiddlers/releasenotes/5.4.0/deprecate-util-func.tid +++ b/editions/tw5.com/tiddlers/releasenotes/5.4.0/deprecate-util-func.tid @@ -4,7 +4,7 @@ release: 5.4.0 tags: $:/tags/ChangeNote change-type: deprecation change-category: developer -github-links: https://github.com/TiddlyWiki/TiddlyWiki5/pull/9251 -github-contributors: Leilei332 +github-links: https://github.com/TiddlyWiki/TiddlyWiki5/pull/9251 https://github.com/TiddlyWiki/TiddlyWiki5/pull/9622 +github-contributors: Leilei332 saqimtiaz Deprecate some utility functions. Some of them are moved to [[$:/core/modules/utils/deprecated.js]]. \ No newline at end of file