Closed GoogleCodeExporter closed 9 years ago
This is a valid bug, but relatively hard to fix since we would need to allow a
way
for the user to specify whether to escape Html characters or not.
Original comment by inder123
on 11 Mar 2009 at 9:06
What do you mean with HTML character?
The JSON specification <http://www.ietf.org/rfc/rfc4627.txt> clearly specifies
in the
last sentence of the first paragraph of section 2.5. Strings which characters
must be
escaped.
Original comment by dennis.b...@gmx.net
on 11 Mar 2009 at 9:34
The contents of the string may contain HTML characters and Gson provides a
GsonBuilder setting to escape them. We would have to provide a similar setting
to
the Constructor (or some other way) in the toString() method to make it work
correctly. For now, I have updated the Javadoc to remove this claim. But I will
leave this bug open because it is worth fixing in future.
Original comment by inder123
on 27 Mar 2009 at 7:31
I'm not sure what this issue has to do with HTML characters. To produce valid
JSON,
you just need to escape "s and the control characters listed in the JSON spec:
http://www.json.org/
If the string being escaped contains HTML, then that's fine, but escaping for
HTML
should be outside of the purview of this library since this library deals with
JSON
not HTML.
Unless there is something I am missing?
Original comment by z13g...@gmail.com
on 14 Apr 2009 at 8:31
I think I understand the issue. You are depending on the toString(Appender)
method
in JsonPrimitive to generate unescaped JSON so that the Serializer can do the
escaping.
I am running into the issue because I'm not using the Gson class at all because
I
don't need the Json <--> Object stuff. I am just parsing JSON via JsonParser to
generate the JsonElements then modifying it and outputting it.
IMHO, the toString method on the JsonElements should return properly escaped
JSON.
If it doesn't, then the method isn't of much use except by the internal methods
since
the JSON it is generating is invalid.
Is my interpretation correct? If it is, I'm still not clear how the HTML
escaping
fits into the problem.
Original comment by z13g...@gmail.com
on 14 Apr 2009 at 9:29
I agree that this is a valid problem. The toString() method should just do JSON
escaping and not HTML escaping (setting through GsonBuilder).
Original comment by inder123
on 14 Apr 2009 at 9:34
FYI... In the meantime, here is a quicky patch which adds the functionality via
a
second toEscapedString method.
Original comment by z13g...@gmail.com
on 14 Apr 2009 at 9:48
Attachments:
[deleted comment]
Original comment by joel.leitch@gmail.com
on 23 Sep 2009 at 6:49
Original issue reported on code.google.com by
dennis.b...@gmx.net
on 11 Mar 2009 at 5:46Attachments: