devote / HTML5-History-API

HTML5 History API expansion for browsers not supporting pushState, replaceState
http://spb-piksel.ru
MIT License
1.02k stars 182 forks source link

JSON.parse(null) is invalid (Android 2.3) #23

Closed njam closed 11 years ago

njam commented 11 years ago

There is one issue stopping history.iegte8.js from working with the Android 2.3 stock browser: JSON.parse(null) throws an exception.

This occurs in 1 place in the code:

historyStorage = function(state) {
    return sessionStorage ? state ? sessionStorage.setItem('__hitoryapi__', JSON.stringify(state)) :
        JSON.parse(sessionStorage.getItem('__hitoryapi__')) || {} : {};
},

I see two ways of fixing this:

  1. Inline-resolve: JSON.parse(sessionStorage.getItem('__hitoryapi__') || null)
  2. Use the JSONParse from the IE6-version, but the emulation part is not really needed.

What do you think can one of these fixes be added to history.iegte8.js? I don't know how you handle it with pull requests, how do you create the minified versions etc. Please let me know if and how I should create a pull request.

devote commented 11 years ago

Hi, I have no way to check the script on Android, maybe this can be corrected in this way: JSON.parse ('' + sessionStorage.getItem ('__hitoryapi__')) Please try to use this method. If all goes well, let me know what I would have made ​​changes to the master branch. Thank you!

njam commented 11 years ago

@devote yes this works! Verified on Android 2.3 browser.

devote commented 11 years ago

I made ​​changes, thank you!

njam commented 11 years ago

Thank you!