(stateText: string)
| 76 | } |
| 77 | |
| 78 | export function deserialiseState(stateText: string): any { |
| 79 | let state; |
| 80 | let exception; |
| 81 | try { |
| 82 | state = urlSerialization.unrisonify(stateText); |
| 83 | if (state?.z) { |
| 84 | const data = lzstring.decompressFromBase64(state.z); |
| 85 | // If lzstring fails to decompress this it'll return an empty string rather than throwing an error |
| 86 | if (data === '') { |
| 87 | throw new Error('lzstring decompress error, url is corrupted'); |
| 88 | } |
| 89 | state = urlSerialization.unrisonify(data); |
| 90 | } |
| 91 | } catch (ex) { |
| 92 | exception = ex; |
| 93 | } |
| 94 | |
| 95 | // This handles prehistoric urls, assumes rison fails with an error |
| 96 | if (!state) { |
| 97 | try { |
| 98 | state = JSON.parse(decodeURIComponent(stateText)); |
| 99 | exception = null; |
| 100 | } catch (ex) { |
| 101 | if (!exception) exception = ex; |
| 102 | } |
| 103 | } |
| 104 | if (exception) throw exception; |
| 105 | return loadState(state); |
| 106 | } |
no test coverage detected