Skip to content

Treat JSON string parsing as a special case #341

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
Apr 28, 2016
Merged
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
9 changes: 2 additions & 7 deletions Foundation/NSJSONSerialization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -484,12 +484,7 @@ private struct JSONReader {
}

func consumeStructure(_ ascii: UInt8, input: Index) throws -> Index? {
switch ascii {
case Structure.QuotationMark:
return try consumeWhitespace(input).flatMap(consumeASCII(ascii)) // for strings we don't consume(ignore) the whitespaces after the starting Quotation Mark because they are part of string e.g in "{\"title\" : \" hello world!!\" }" the value should be " hello world!!" instead of "hello world"
default:
return try consumeWhitespace(input).flatMap(consumeASCII(ascii)).flatMap(consumeWhitespace)
}
return try consumeWhitespace(input).flatMap(consumeASCII(ascii)).flatMap(consumeWhitespace)
}

func consumeASCII(_ ascii: UInt8) -> (Index) throws -> Index? {
Expand Down Expand Up @@ -530,7 +525,7 @@ private struct JSONReader {
//MARK: - String Parsing

func parseString(_ input: Index) throws -> (String, Index)? {
guard let beginIndex = try consumeStructure(Structure.QuotationMark, input: input) else {
guard let beginIndex = try consumeWhitespace(input).flatMap(consumeASCII(Structure.QuotationMark)) else {
return nil
}
var chunkIndex: Int = beginIndex
Expand Down