Railo
  1. Railo
  2. RAILO-2807

serializeJson escapes forward slash

    Details

    • Similar Issues:
      Show 10 results 

      Description

      comment from Adam Cameron:
      The slash doesn't NEED to be escaped in JSON. The rule - as per the spec you link to, and borne out in the real world (including, I hasten to add: Railo) - is "any unicode character except double quote or backslash" is a char. A fwd slash is not a special char needing to be escaped. However if the backslash is present, then one of the acceptable following characters is a fwd slash. But this is not to say that the fwd slash NEEDS to be escaped. It just can be escaped.

      I would think any baseline / automated implementation (just as serializeJson() implemented) should NOT do unnecessary escaping? I can only presume that Railo is following CF's lead here. However I think that's a facile approach in this case: Railo should follow the rules of JSON, not CF's interpretation of them.

      As an aside... ColdFusion fails on this code, Railo does not:
      <cfset json = '

      {"link" = "/example/example1"}

      '>
      <cfdump var="#deserializeJson(json)#">

      Note that I am incorrectly (and entirely by accident: copy and paste from the original code) using "=" instead of ":" as the "assignment operator" in that string. That's not valid. Railo should error on that input. CF gets it right (so does OBD, FWIW). If I replace the "=" with a ":" to make it valid JSON, all three engines parse it fine. Note that the fwd slashes are not unnecessarily escaped.

        Gliffy Diagrams

          Activity

          Hide
          Adam Cameron added a comment -

          Also note that this returns true:

          <cfoutput>#isJson('{"x"=1}')#</cfoutput>

          It's NOT valid JSON (note the = rather than :)

          Show
          Adam Cameron added a comment - Also note that this returns true : <cfoutput>#isJson('{"x"=1}')#</cfoutput> It's NOT valid JSON (note the = rather than : )
          Show
          Michael Offner added a comment - add testcase https://github.com/getrailo/railo/commit/31a41cf275c9a85160f6fad972473b2c12d259c2
          Show
          Michael Offner added a comment - https://github.com/getrailo/railo/commit/9951654a4b3e2da951447a8482eb39c2d076af1a

            People

            • Assignee:
              Michael Offner
              Reporter:
              Michael Offner
            • Votes:
              3 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development