owensd/json-swift

Control characters are not unescaped

Closed this issue · 3 comments

Currently, json-swift only handles escaped quote characters, but according to ECMA-404 (json.org), there are other control sequences which need to be unescaped while parsing strings, i.e. ", , /, \b, \f, \n, \r, \t and \u.

The following test fails with the current HEAD:

func testParseStringWithEscapedControlCharacters() {
    let string = "\"\\\\\\/\\n\\r\\t\""
    let jsvalue = JSValue.parse(string)

    XCTAssertTrue(jsvalue.error == nil, jsvalue.error?.userInfo?.description ?? "No error info")
    XCTAssertEqual(jsvalue.value!.string!, "\\/\n\r\t")
}

Hmm... good catch. I'll look into it.

Should be fixed now. Please re-open if you see any other issues with this.

That was quick, thanks!