Bug overview description.
application-min.js includes the following code which modifies Array.prototype.toJSON:
Object.extend(Array.prototype, { toJSON: function() { var results = []; this.each(function(object) { var value = Object.toJSON(object); if (!Object.isUndefined(value)) results.push(value); }); return '[' + results.join(', ') + ']'; } });
...and causes arrays to be stringified twice when JSON.stringify is used. This is a nightmare for script development because code that would work nearly anywhere else fails here. JSON.stringify and JSON.parse are usually symmetric, so parse undoes stringify, but on e621 you have to call parse on arrays twice. This turns pretty nasty when you have arrays nested in other objects.
This isn't a huge priority or anything, since there are some other (uncomfortable) workarounds. Xch3l wrote his own stringify function to replace the native one. You could also set Array.prototype.toJSON = undefined, but I'm not sure if that would break any other site functions.
Anyway, even if the bug/irregularity can't be fixed I wanted to document it here. Hopefully it helps someone.
What part(s) of the site page(s) are affected?
Javascript on all pages
What is the expected behavior?
var testArr = [ 'test1', 'test2' ]; console.log(JSON.stringify(testArr)); Expected output: '["test1","test2"]'
What actual behavior is given instead?
e621 output: '"[\\"test1\\", \\"test2\\"]"'
Time of incident (if applicable).
For the past several years, at least.
Can you reproduce the bug every time?
Yes
What steps did you take to replicate this bug?
Above
Errors or other messages returned (if any).
Above
Updated by KiraNoot