atomizer / muledump

all your mules are belong to you
84 stars 144 forks source link

Perform a validity test on `accounts.js` before trying to import it #97

Open Nightfirecat opened 8 years ago

Nightfirecat commented 8 years ago

Javascript is more often than not able to read local files from a user's filesystem. (ref: http://stackoverflow.com/questions/14446447/javascript-read-local-text-file) Using a method like this, we should validate the file and try to provide useful error messages if something looks wrong. (illegal characters, invalid formatting, etc.)

atomizer commented 8 years ago

If reading local files would work I wouldn't bother making it a .js in the first place - a simple text file would work just fine. Maybe something changed over the years, but Chrome would refuse to read anything from local filesystem - every file is considered it's own origin, see [1] [2].

Nightfirecat commented 8 years ago

I believe that's an artifact of the old proprietary methods used by jQuery, and security implementations by browsers. (because at that point, there was no collective effort to develop the JS API to access filesystems in a secure way)

I like the idea of moving away fro a JS file, but doing so and breaking the experience for users who currently use the JS files may not be ideal. Should file writing also be available, maybe a conversion script should be run/included with this change.

Nightfirecat commented 7 years ago

Update: looks like every major browser supports the FileReader API, which would do the job. http://caniuse.com/#search=FileReader%20API

I may do some work on this in the near future; would love to kill the fancy quotes problem.

Nightfirecat commented 7 years ago

Well damn, looks like that only works if you select a local accounts file with <input type="file">. Not really feasible when you'd rather have the accounts loaded on page load with no input.