ObjFW  Check-in [d7bbf983f0]

Overview
Comment:Allow \u0000 in JSON
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: d7bbf983f0700e19b8188457635796dbe7e66e3babba9e389fe87856c8f6ff30
User & Date: js on 2024-10-27 23:48:14
Other Links: manifest | tags
Context
2024-10-27
23:57
Add support for \x from JSON5 Leaf check-in: 229486deb1 user: js tags: trunk
23:48
Allow \u0000 in JSON check-in: d7bbf983f0 user: js tags: trunk
23:38
OFSystemInfo: Fix \0 in +[CPUModel] on macOS check-in: e061c2b66e user: js tags: trunk
Changes

Modified src/OFString+JSONParsing.m from [08913e2453] to [14e3ab6458].

133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
133
134
135
136
137
138
139



140
141
142
143
144
145
146







-
-
-







			ret |= c + 10 - 'a';
		else if (c >= 'A' && c <= 'F')
			ret |= c + 10 - 'A';
		else
			return 0xFFFF;
	}

	if (ret == 0)
		return 0xFFFF;

	return ret;
}

static inline OFString *
parseString(const char **pointer, const char *stop, size_t *line)
{
	char *buffer;

Modified tests/OFJSONTests.m from [4578e0b89d] to [f4ec78e136].

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
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,\"foo\",false]}";
    @"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],
		@"foo",
		@"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,\"foo\",false]}");
	    @"{\"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\"foo\",\n\t\tfalse\n\t]\n}");
	    @"\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,\"foo\",false]}");
	    @"{\"f\\0oo\":\"b\\\na\\r\",x:[0.5,15,null,\"fo\\0o\",false]}");
}

- (void)testObjectByParsingJSONFailsWithInvalidJSON
{
	OTAssertThrowsSpecific([@"{" objectByParsingJSON],
	    OFInvalidJSONException);