GemTalk / Rowan

a new project/package manager for Smalltalk that supports FileTree and Tonel repositories, and is independent of Monticello and Metacello
MIT License
14 stars 7 forks source link

`STONWriter` produces invalid JSON when a string includes single quote characters. #904

Open gcotelli opened 1 year ago

gcotelli commented 1 year ago

To reproduce evaluate: STON toJsonString: '''' and you will get "\'" instead of "'".

Something like the following should fix the problem:

STONWriter>>jsonMode: boolean

    jsonMode := boolean.
    jsonMode
        ifTrue: [
            STONCharacters
                at: $' codePoint + 1 put: #pass;
                at: $" codePoint + 1 put: '\"' ]
        ifFalse: [
            STONCharacters
                at: $" codePoint + 1 put: #pass;
                at: $' codePoint + 1 put: '\''' ]

Would be a good idea to add some test cases covering the handling of both single and double quotes for Smalltalk and JSON mode.

dalehenrich commented 11 months ago

I tried implementing your workaround but some of the existing STONWriterTests JSON tests started failing. I was hoping to include the fix in Rowan masterV2.3.2 for the 3.6.7 release, "at the last minute", but don't have the time (at this moment) to look into a better solution ... should be able to return to this before the end of the year ...