WardCunningham / Smallest-Federated-Wiki

This wiki innovates by: 1. federated sharing, 2. drag refactoring and 3. data visualization.
http://wardcunningham.github.com/
GNU General Public License v2.0
1.21k stars 178 forks source link

Pages Named "Clear" Cause Weird Behavior #438

Closed michaelarthurcaulfield closed 9 years ago

michaelarthurcaulfield commented 10 years ago

To duplicate, create a page named "Clear". It will freeze in this position:

screenshot 2014-12-06 at 10 03 02 pm

Not hard to work around, but mentioning in case strings are being evaluated in ways they shouldn't be.

DIscovered by student in my class writing page on the app Clear.

paul90 commented 9 years ago

will also freeze with other localStorage keywords

WardCunningham commented 9 years ago

Good catch. But @paul90, how did you even think to suspect this? I've not seen this behavior mentioned in any localStorage documentation.

Many thanks to @michaelarthurcaulfield and his students.

paul90 commented 9 years ago

Not seen it mentioned anywhere either, but there are some hints. At least one question points to DOM Storage guide

Note: Although the values can be set and read using the standard JavaScript property access method, using the getItem and setItem methods is recommended.

I also noticed that trying to follow the link to 'clear' also empties localstorage, which is a bit of a give away. Although the error in the Firefox console points to JSON.parse.

WardCunningham commented 9 years ago

I'm reminded of little Bobby Tables. http://xkcd.com/327/

paul90 commented 9 years ago

Of course localStorage["clear"] is the same as localStorage.clear which clears localStorage, which is a wee bit of a problem.

Other than the recommendation quoted above, most of the JavaScript texts seem to freely mix the use of setItem/getItem, square brackets, and the dot notation with not a word of warning of the trap that is awaiting.