Files
swift-mirror/lib/Basic/JSONSerialization.cpp
Connor Wakamo 725f501e9b Fixed the escaping of strings in swift::json::Output.
Instead of using llvm::raw_ostream::write_escaped (which does not produce valid
JSON strings), implemented custom escaping logic based on the JSON standard,
which only requires that the following characters be escaped:

  - Quotation mark (U+0022)
  - Reverse solidus (U+005C)
  - Control characters (U+0000 to U+001F)

Since these characters all fit within a single UTF8 byte, and will not be
present in a multi-byte UTF8 representation, simply check whether the current
byte needs to be escaped according to those requirements. If the current byte
needs to be escaped, then print out the escaped version of the byte; otherwise,
pass the current byte to the stream directly.

This fixes <rdar://problem/18266570>.

Swift SVN r21892
2014-09-11 22:20:05 +00:00

7.7 KiB