cfdocs icon indicating copy to clipboard operation
cfdocs copied to clipboard

JSON utils doesn't escape quotes or add new line characters

Open zspitzer opened this issue 8 years ago • 6 comments

I went to go and fix the broken example for listMap by copying the example into https://cfdocs.org/utilities/json/

"code": "Rainbow = \"Whero, Karaka, Kowhai, Kakariki, Kikorangi, Tawatawa, Mawhero\"; \r\n externalList = \"\"; \r\n reverseRainbow = listMap( rainbow, function(v,i,l) \r\n { \r\n var newValue = \"#i#:#v.reverse()#\";  \r\n externalList = externalList.append(newValue); \r\n return newValue; \r\n }); \r\n riteDump([{rainbow=rainbow},{reverseRainbow=reverseRainbow},{externalList=externalList}]);  \r\n"
}], 

but the output from the json generator didn't escape the " or add the newlines \r\n

code: " Rainbow = "Whero, Karaka, Kowhai, Kakariki, Kikorangi, Tawatawa, Mawhero"; externalList = ""; reverseRainbow = listMap( rainbow, function(v,i,l) { var newValue = "#i#:#v.reverse()#"; externalList = ListAppend(externalList,newValue); return newValue; }); writeDump([{rainbow=rainbow},{reverseRainbow=reverseRainbow},{externalList=externalList}]); ",

zspitzer avatar Oct 03 '17 02:10 zspitzer

So you had new line characters in your original code and they got stripped out?

Normally you add "real" breaks which get converted to line break characters (\r\n).

shaedrich avatar Oct 03 '17 11:10 shaedrich

  1. open https://cfdocs.org/listmap
  2. click run
  3. copy the content between the cfscript tags
  4. open https://cfdocs.org/utilities/json/
  5. paste in the copied code from 3 into the code textarea
  6. press to json

zspitzer avatar Oct 03 '17 11:10 zspitzer

Then I get line breaks as expected oO

No matter if I use the String or the code box...

shaedrich avatar Oct 03 '17 11:10 shaedrich

are the quotes escaped too? @shaedrich what platform, I'm on win10 with chrome

zspitzer avatar Oct 03 '17 23:10 zspitzer

They are.

The platform and browser shouldn't make any different because the tool works server-side.

I'm on ubuntu with chromium.

shaedrich avatar Oct 04 '17 06:10 shaedrich

That is what I get:

"code":"Rainbow = \"Whero, Karaka, Kowhai, Kakariki, Kikorangi, Tawatawa, Mawhero\"; \r\n externalList = \"\"; \r\n reverseRainbow = listMap( rainbow, function(v,i,l) \r\n { \r\n var newValue = \"#i#:#v.reverse()#\";  \r\n externalList = externalList.append(newValue); \r\n return newValue; \r\n }); \r\nwriteDump([{rainbow=rainbow},{reverseRainbow=reverseRainbow},{externalList=externalList}]);  ",

shaedrich avatar Oct 25 '17 10:10 shaedrich