history.js icon indicating copy to clipboard operation
history.js copied to clipboard

Traditional urls getting rewritten if period (.) is in the hash

Open patrickliechty opened this issue 11 years ago • 9 comments

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.

patrickliechty avatar Jul 08 '13 21:07 patrickliechty

I have similar problems in #315.

igor-alexandrov avatar Jul 09 '13 19:07 igor-alexandrov

I created a pull request to fix this. https://github.com/browserstate/history.js/pull/322

patrickliechty avatar Aug 12 '13 22:08 patrickliechty

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.

pmaselkowski avatar Oct 08 '15 16:10 pmaselkowski

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 avatar Oct 14 '15 20:10 pmaselkowski

@pmaselkowski thanks - and your comment just in time for when I started looking at this issue!

gareththackeray avatar Oct 19 '15 10:10 gareththackeray

I had to alter the regexp this way : [?] otherwyse, the / is alos forbidden in the hash part

brunob2f avatar Apr 08 '16 09:04 brunob2f

@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 avatar Mar 07 '17 15:03 kiflay

@kiflay see brunob2f comment, maybe You need to tweak with regexp.

pmaselkowski avatar Mar 07 '17 17:03 pmaselkowski

Thanks @pmaselkowski

kiflay avatar Mar 09 '17 12:03 kiflay