Skip to content

Change JSONSerialization to escape solidus like macOS does #1321

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Foundation/JSONSerialization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,8 @@ private struct JSONWriter {
writer("\\\"") // U+0022 quotation mark
case "\\":
writer("\\\\") // U+005C reverse solidus
// U+002F solidus not escaped
case "/":
writer("\\/") // U+002F solidus
case "\u{8}":
writer("\\b") // U+0008 backspace
case "\u{c}":
Expand Down
3 changes: 3 additions & 0 deletions TestFoundation/TestJSONSerialization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1316,6 +1316,9 @@ extension TestJSONSerialization {

json = ["i\u{1f}"]
XCTAssertEqual(try trySerialize(json), "[\"i\\u001f\"]")

json = ["j/"]
XCTAssertEqual(try trySerialize(json), "[\"j\\/\"]")
}

/* These are a programming error and should not be done
Expand Down