1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-26 11:37:20 +00:00

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.
This commit is contained in:
Robin Munn 2020-11-01 17:47:50 +07:00 committed by GitHub
parent c6cd4d33e6
commit ecb3c86e7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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);
}
};
/*