bpsm / edn-java

a reader for extensible data notation
Eclipse Public License 1.0
100 stars 24 forks source link

single quote in a string is incorrectly escaped #31

Closed kotarak closed 11 years ago

kotarak commented 11 years ago

Printing a string containing single quotes will incorrectly escape these quotes with a backslash. In a groovy shell:

> System.out.withWriter("UTF-8") { us.bspm.edn.printer.Printers.newPrinter(it).printValue("a 'b' c") }
"a \'b\' c">

Version affected: 0.4.0

bpsm commented 11 years ago

Looks like a bug relative to the behavior of clojure.core/pr. Also the Clojure reader rejects it.

Seems an obvious improvement to have edn-java no longer print this way.

What about reading though? Should it continue to accept "\'", or conform to clojure's behavior (a breaking change)?

Why things ended up this way:

edn-format/edn says: Strings are enclosed in "double quotes". May span multiple lines. Standard C/Java escape characters \t \r \n are supported.

The JLS considers "\'" valid:

http://docs.oracle.com/javase/specs/jls/se7/html/jls-3.html#jls-3.10.6

This message was sent via electromagnetism.

On 03.06.2013, at 18:11, Meikel Brandmeyer notifications@github.com wrote:

Printing a string containing single quotes will incorrectly escape these quotes with a backslash. In a groovy shell:

System.out.withWriter("UTF-8") { us.bspm.edn.printer.Printers.newPrinter(it).printValue("a 'b' c") } "a \'b\' c"> Version affected: 0.4.0

— Reply to this email directly or view it on GitHub.

kotarak commented 11 years ago

Well, the set of escape characters is listed, but then \a and \b are missing. I don't remember \' being a C escape character though. But I don't know the standard. File a bug against edn for clarification?

Reading can probably continue to accept it. Normally it won't be produced (assuming a "correct" producer with "correct" meaning pr alike). So the chance to encounter this is mostly historic edn-java produced data. On the other hand that would mean a slight glitch in handling corrupt input.

bpsm commented 11 years ago

Misbehaving printer is fixed in ceb7be0b21bc0aa11487ad27f8a1f0463a7b2b9c and will be included in release 0.4.1.