Project

General

Profile

Defect #772

toJSON() seems to encode entities twice (in some cases)

Added by Robert Ivens over 10 years ago. Updated over 10 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Category:
velocity
Target version:
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

#1

Updated by Patrick Talbot over 10 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":"&amp;"}}
&amp;
&
{"obj":"&amp;"}
&amp;
&

Also available in: Atom PDF