NSJSONSerialization doesn't always disregard trailing whitespace

Originator:mprudhom
Number:rdar://21472364 Date Originated:19-Jun-2015
Status:Open Resolved:
Product: Product Version:
Classification: Reproducible:
 
JSON is supposed to disregard trailing whitespace, but fractional numbers with trailing spaces sometimes do not equate to fractional numbers without trailing space. Paste the reproduction steps into a playground to reproduce.

Steps to Reproduce:
import Foundation

func makeJSON(str: String) -> NSObject? {
    if let data = str.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: true) {
        return NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.AllowFragments, error: nil) as? NSObject
    }
    return nil
}

makeJSON("1") == makeJSON("1") // true
makeJSON("1") == makeJSON("1 ") // true
makeJSON("123") == makeJSON("123 ") // true
makeJSON("123.4") == makeJSON("123.4 ") // true

makeJSON("123.45") == makeJSON("123.45") // true
makeJSON("123.45") == makeJSON(" 123.45") // true
makeJSON("123.45") == makeJSON("123.45 ") // true

makeJSON("123.456") == makeJSON("123.456") // true
makeJSON("123.456") == makeJSON(" 123.456") // true
makeJSON("123.456") == makeJSON("123.456 ") // false!?!?

makeJSON("123.4567") == makeJSON("123.4567") // true
makeJSON("123.4567") == makeJSON(" 123.4567") // true
makeJSON("123.4567") == makeJSON("123.4567 ") // true

makeJSON("123.45678") == makeJSON("123.45678") // true
makeJSON("123.45678") == makeJSON(" 123.45678") // true
makeJSON("123.45678") == makeJSON("123.45678 ") // false!?!?

makeJSON("123.456789") == makeJSON("123.456789") // true
makeJSON("123.456789") == makeJSON(" 123.456789") // true
makeJSON("123.456789") == makeJSON("123.456789 ") // false!?!?

makeJSON("123.4567890") == makeJSON("123.4567890") // true
makeJSON("123.4567890") == makeJSON(" 123.4567890") // true
makeJSON("123.4567890") == makeJSON("123.4567890 ") // false!?!?


Expected Results:


Actual Results:


Version:
Version 6.3.2 (6D2105)

Notes:


Configuration:

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!