Differences From Artifact [4578e0b89d]:
- File
tests/OFJSONTests.m
— part of check-in
[6fbc3b18c7]
at
2024-10-27 22:27:20
on branch trunk
— Allow strings to contain \0
In order to not accidentally have C strings with \0, an
OFInvalidEncodingException is thrown when trying to get a C string for a
string that contains \0.In order to get a C string with \0 anyway, a new method
-[insecureCStringWithEncoding:] is added. (user: js, size: 4109) [annotate] [blame] [check-ins using]
To Artifact [f4ec78e136]:
- File tests/OFJSONTests.m — part of check-in [d7bbf983f0] at 2024-10-27 23:48:14 on branch trunk — Allow \u0000 in JSON (user: js, size: 4144) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
25 26 27 28 29 30 31 | @interface OFJSONTests: OTTestCase { OFDictionary *_dictionary; } @end static OFString *string = @"{\"f\\0oo\"\t:'b\\na\\r', \"x\":/*foo*/ [.5\r,0xF," | | | | > | | | 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | @interface OFJSONTests: OTTestCase { OFDictionary *_dictionary; } @end static OFString *string = @"{\"f\\0oo\"\t:'b\\na\\r', \"x\":/*foo*/ [.5\r,0xF," @"null//bar\n,\"fo\\u0000o\",false]}"; @implementation OFJSONTests - (void)setUp { [super setUp]; _dictionary = [[OTOrderedDictionary alloc] initWithKeysAndObjects: @"f\0oo", @"b\na\r", @"x", [OFArray arrayWithObjects: [OFNumber numberWithFloat: .5f], [OFNumber numberWithInt: 0xF], [OFNull null], @"fo\0o", [OFNumber numberWithBool: false], nil], nil]; } - (void)dealloc { [_dictionary release]; [super dealloc]; } - (void)testObjectByParsingJSON { OTAssertEqualObjects(string.objectByParsingJSON, _dictionary); } - (void)testJSONRepresentation { OTAssert(_dictionary.JSONRepresentation, @"{\"f\\u0000oo\":\"b\\na\\r\",\"x\":[0.5,15,null,\"fo\\u0000o\"," @"false]}"); } - (void)testSortedJSONRepresentation { OTAssertEqualObjects( [([OFDictionary dictionaryWithKeysAndObjects: @"b", @"a", @"a", @"b", nil]) JSONRepresentationWithOptions: OFJSONRepresentationOptionSorted], @"{\"a\":\"b\",\"b\":\"a\"}"); } - (void)testPrettyJSONRepresentation { OTAssertEqualObjects([_dictionary JSONRepresentationWithOptions: OFJSONRepresentationOptionPretty], @"{\n\t\"f\\u0000oo\": \"b\\na\\r\",\n\t\"x\": [\n\t\t0.5,\n\t\t15," @"\n\t\tnull,\n\t\t\"fo\\u0000o\",\n\t\tfalse\n\t]\n}"); } - (void)testJSON5Representation { OTAssertEqualObjects([_dictionary JSONRepresentationWithOptions: OFJSONRepresentationOptionJSON5], @"{\"f\\0oo\":\"b\\\na\\r\",x:[0.5,15,null,\"fo\\0o\",false]}"); } - (void)testObjectByParsingJSONFailsWithInvalidJSON { OTAssertThrowsSpecific([@"{" objectByParsingJSON], OFInvalidJSONException); |
︙ | ︙ |