From ecb3c86e7bff8205043f397848355d5cefe7f470 Mon Sep 17 00:00:00 2001 From: Robin Munn Date: Sun, 1 Nov 2020 17:47:50 +0700 Subject: [PATCH] Fix bug when location hash contains a # (#4947) The bug fixed in this commit had an interesting side effect when the location hash started with #, e.g. it looked like wiki.html##foo. In that case, TiddlyWiki's navigation processing is not triggered and the browser's navigation processing is used instead, which allows anchors to be used within tiddlers for sub-tiddler navigation. To preserve this unintended but useful side-effect, we check for a location hash that starts with # and ignore it if it does. --- boot/boot.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/boot/boot.js b/boot/boot.js index 80032b4f5..9b742120c 100644 --- a/boot/boot.js +++ b/boot/boot.js @@ -267,8 +267,16 @@ $tw.utils.htmlDecode = function(s) { 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() { - var parts = window.location.href.split('#'); - return "#" + (parts.length > 1 ? parts[1] : ""); + var href = window.location.href; + var idx = href.indexOf('#'); + if(idx === -1) { + return "#"; + } else if(idx < href.length-1 && href[idx+1] === '#') { + // Special case: ignore location hash if it itself starts with a # + return "#"; + } else { + return href.substring(idx); + } }; /*