Defect #772
toJSON() seems to encode entities twice (in some cases)
Start date:
12/13/2013
Due date:
% Done:
0%
Estimated time:
Browser (if web client):
Description
The following code:
var _oContext = { obj: { wrong: "&" } };
application.output(plugins.VelocityReport.toJSON(_oContext));
_oContext = { obj: "&" };
application.output(plugins.VelocityReport.toJSON(_oContext));
Produces the following output:
{"obj":{"wrong":"&"}}
{"obj":"&"}
The first one is very wrong and will not serialize back properly (obviously)
History
Updated by Patrick Talbot almost 12 years ago
- Status changed from New to Closed
Fixed in v3.2.18. I've also added an (optional) boolean to the fromJSON method, that will automatically unescape the & > < HTML entities.
var _oContext = { obj: { wrong: "&" } };
application.output(plugins.VelocityReport.toJSON(_oContext));
var result = plugins.VelocityReport.fromJSON(plugins.VelocityReport.toJSON(_oContext));
application.output(result.obj.wrong);
result = plugins.VelocityReport.fromJSON(plugins.VelocityReport.toJSON(_oContext),true);
application.output(result.obj.wrong);
_oContext = { obj: "&" };
application.output(plugins.VelocityReport.toJSON(_oContext));
result = plugins.VelocityReport.fromJSON(plugins.VelocityReport.toJSON(_oContext));
application.output(result.obj);
result = plugins.VelocityReport.fromJSON(plugins.VelocityReport.toJSON(_oContext),true);
application.output(result.obj);
Gives me this:
{"obj":{"wrong":"&"}}
&
&
{"obj":"&"}
&
&