history.js
history.js copied to clipboard
Traditional urls getting rewritten if period (.) is in the hash
We are using history 1.7.1. We have cases where a period is part of the a hash parameter value. In onPopState in History.js it calls replaceState because it says it found a state. This causes a rewrite of the url from:
http://localhost:5000/search/record/results#count=20&query=%2Bgivenname%3Apatrick~%20%2Bsurname%3Ajones.~
to
http://localhost:5000/search/record/count=20&query=+givenname:patrick~%20+surname:jones.~
All because it is thinks it is a traditional url. Here is the function:
History.isTraditionalAnchor = function(url_or_hash){
// Check
var isTraditional = !(/[\/\?\.]/.test(url_or_hash));
// Return
return isTraditional;
};
Why isTraditionalAnchor looking for a period? I don't understand how a tradition anchor is determined by a / . or ?
At any rate, it appears to be a bug unless I am not understanding this. It is not fixed in 1.8.0 either.
I have similar problems in #315.
I created a pull request to fix this. https://github.com/browserstate/history.js/pull/322
Any reason why dot is still used as separator?
According to http://tools.ietf.org/html/rfc3986 dot is valid character for fragment.
This causes rewrite of hash with dot into path, ie:
/admin/messages/#1jY4xnOMD_sort
Becomes
/admin/messages/1jY4xnOMD_sort
Had hard time figuring out why this happens.
There is a workaround for this issue. After including history.js, delay init, alter isTraditionalAnchor
and init manually:
History.options.delayInit = true;
History.isTraditionalAnchor = function(url_or_hash) {
var isTraditional;
isTraditional = !(/[\/\?]/.test(url_or_hash));
return isTraditional;
};
History.init();
@pmaselkowski thanks - and your comment just in time for when I started looking at this issue!
I had to alter the regexp this way : [?] otherwyse, the / is alos forbidden in the hash part
@pmaselkowski I did add your script and the value of the isTraditional is false but the url is not updated.
url was
loungewear/icat/unisex-loungewear# size = XS
After changing size to size = X/S it becomes
loungewear/icat/size=XL/2X
@kiflay see brunob2f comment, maybe You need to tweak with regexp.
Thanks @pmaselkowski