Compare commits
12
Commits
f0a338f164
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c44b0262bc | ||
|
|
814b24efba | ||
|
|
86b58e83cb | ||
|
|
cdff634057 | ||
|
|
16f5d3cd9d | ||
|
|
6beb538b61 | ||
|
|
6520039dc2 | ||
|
|
93203b14f5 | ||
|
|
09c0fb72ca | ||
|
|
70bb33eeaf | ||
|
|
42d37d1fd7 | ||
|
|
5e462f1477 |
@@ -60,8 +60,9 @@ into the result, so it is non-movable.
|
|||||||
## Not supported (rejected at generation time, no fallback)
|
## Not supported (rejected at generation time, no fallback)
|
||||||
|
|
||||||
`oneOf` / `anyOf` / `allOf` / `not` / `if`-`then`-`else`,
|
`oneOf` / `anyOf` / `allOf` / `not` / `if`-`then`-`else`,
|
||||||
`patternProperties`, `additionalProperties` with a schema (typed map),
|
`patternProperties`, `additionalProperties` absent or set to `true`,
|
||||||
`additionalProperties: true`, `prefixItems` (tuples), `const`,
|
`additionalProperties` with a schema (typed map), `prefixItems` (tuples),
|
||||||
|
`const`,
|
||||||
`dependentSchemas`/`dependentRequired`, union `type` lists other than
|
`dependentSchemas`/`dependentRequired`, union `type` lists other than
|
||||||
`["T", "null"]`, non-string enums, and remote (`$ref` to other documents).
|
`["T", "null"]`, non-string enums, and remote (`$ref` to other documents).
|
||||||
|
|
||||||
|
|||||||
@@ -56,6 +56,7 @@
|
|||||||
"type": "array",
|
"type": "array",
|
||||||
"items": {
|
"items": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
|
"additionalProperties": false,
|
||||||
"required": [
|
"required": [
|
||||||
"name"
|
"name"
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ class SchemagenEnumTest(unittest.TestCase):
|
|||||||
def test_colliding_enum_values_deduplicate(self):
|
def test_colliding_enum_values_deduplicate(self):
|
||||||
schema = {
|
schema = {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
|
"additionalProperties": False,
|
||||||
"properties": {"role": {"enum": ["foo-bar", "foo_bar"]}},
|
"properties": {"role": {"enum": ["foo-bar", "foo_bar"]}},
|
||||||
}
|
}
|
||||||
rc, stdout, stderr = self.run_schemagen(schema)
|
rc, stdout, stderr = self.run_schemagen(schema)
|
||||||
@@ -45,6 +46,7 @@ class SchemagenEnumTest(unittest.TestCase):
|
|||||||
def test_distinct_enum_values_generate(self):
|
def test_distinct_enum_values_generate(self):
|
||||||
schema = {
|
schema = {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
|
"additionalProperties": False,
|
||||||
"properties": {"role": {"enum": ["admin", "user", "guest"]}},
|
"properties": {"role": {"enum": ["admin", "user", "guest"]}},
|
||||||
}
|
}
|
||||||
rc, stdout, stderr = self.run_schemagen(schema)
|
rc, stdout, stderr = self.run_schemagen(schema)
|
||||||
@@ -80,7 +82,7 @@ class SchemagenKeywordTest(unittest.TestCase):
|
|||||||
"module",
|
"module",
|
||||||
"import",
|
"import",
|
||||||
]
|
]
|
||||||
schema = {"type": "object", "properties": {}}
|
schema = {"type": "object", "additionalProperties": False, "properties": {}}
|
||||||
for kw in keywords:
|
for kw in keywords:
|
||||||
schema["properties"][kw] = {"type": "string"}
|
schema["properties"][kw] = {"type": "string"}
|
||||||
rc, stdout, stderr = self.run_schemagen(schema)
|
rc, stdout, stderr = self.run_schemagen(schema)
|
||||||
@@ -164,11 +166,18 @@ class SchemagenCollisionTest(unittest.TestCase):
|
|||||||
def test_kind_enum_does_not_duplicate_arr0(self):
|
def test_kind_enum_does_not_duplicate_arr0(self):
|
||||||
schema = {
|
schema = {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
|
"additionalProperties": False,
|
||||||
"properties": {
|
"properties": {
|
||||||
"arr": {"type": "array", "items": {"type": "string"}},
|
"arr": {"type": "array", "items": {"type": "string"}},
|
||||||
"obj": {"$ref": "#/$defs/Arr0"},
|
"obj": {"$ref": "#/$defs/Arr0"},
|
||||||
},
|
},
|
||||||
"$defs": {"Arr0": {"type": "object", "properties": {}}},
|
"$defs": {
|
||||||
|
"Arr0": {
|
||||||
|
"type": "object",
|
||||||
|
"additionalProperties": False,
|
||||||
|
"properties": {},
|
||||||
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
out = self.generate_and_compile(schema)
|
out = self.generate_and_compile(schema)
|
||||||
self.assertIn("struct Arr0", out)
|
self.assertIn("struct Arr0", out)
|
||||||
@@ -183,7 +192,13 @@ class SchemagenCollisionTest(unittest.TestCase):
|
|||||||
schema = {
|
schema = {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"items": {"$ref": "#/$defs/Skip"},
|
"items": {"$ref": "#/$defs/Skip"},
|
||||||
"$defs": {"Skip": {"type": "object", "properties": {}}},
|
"$defs": {
|
||||||
|
"Skip": {
|
||||||
|
"type": "object",
|
||||||
|
"additionalProperties": False,
|
||||||
|
"properties": {},
|
||||||
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
out = self.generate_and_compile(schema)
|
out = self.generate_and_compile(schema)
|
||||||
self.assertIn("struct Skip", out)
|
self.assertIn("struct Skip", out)
|
||||||
@@ -199,6 +214,7 @@ class SchemagenCollisionTest(unittest.TestCase):
|
|||||||
"""Regression test for issue #17: enum and array $defs must be reused."""
|
"""Regression test for issue #17: enum and array $defs must be reused."""
|
||||||
schema = {
|
schema = {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
|
"additionalProperties": False,
|
||||||
"properties": {
|
"properties": {
|
||||||
"role1": {"$ref": "#/$defs/Role"},
|
"role1": {"$ref": "#/$defs/Role"},
|
||||||
"role2": {"$ref": "#/$defs/Role"},
|
"role2": {"$ref": "#/$defs/Role"},
|
||||||
@@ -252,17 +268,14 @@ class SchemagenAdditionalPropertiesTest(unittest.TestCase):
|
|||||||
self.assertNotEqual(rc, 0)
|
self.assertNotEqual(rc, 0)
|
||||||
self.assertIn("additionalProperties: true is not supported", stderr)
|
self.assertIn("additionalProperties: true is not supported", stderr)
|
||||||
|
|
||||||
def test_additional_properties_absent_defaults_to_strict(self):
|
def test_additional_properties_absent_rejected(self):
|
||||||
schema = {
|
schema = {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {"name": {"type": "string"}},
|
"properties": {"name": {"type": "string"}},
|
||||||
}
|
}
|
||||||
rc, stdout, stderr = self.run_schemagen(schema)
|
rc, stdout, stderr = self.run_schemagen(schema)
|
||||||
self.assertEqual(rc, 0, msg=stderr)
|
self.assertNotEqual(rc, 0)
|
||||||
# The generated parser should reject unknown keys. Verify the key-matching
|
self.assertIn("additionalProperties is required for object schemas", stderr)
|
||||||
# helper returns -1 for an unknown key and cbKeyData rejects it.
|
|
||||||
self.assertIn("int matchKey(Kind k, std::string_view key) const {", stdout)
|
|
||||||
self.assertNotIn("bool isStrict(Kind k) const", stdout)
|
|
||||||
|
|
||||||
def test_additional_properties_false_accepted(self):
|
def test_additional_properties_false_accepted(self):
|
||||||
schema = {
|
schema = {
|
||||||
@@ -310,6 +323,7 @@ class SchemagenCyclicArrayTest(unittest.TestCase):
|
|||||||
def test_object_field_to_self_referential_array_rejected(self):
|
def test_object_field_to_self_referential_array_rejected(self):
|
||||||
schema = {
|
schema = {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
|
"additionalProperties": False,
|
||||||
"properties": {"items": {"$ref": "#/$defs/Items"}},
|
"properties": {"items": {"$ref": "#/$defs/Items"}},
|
||||||
"$defs": {
|
"$defs": {
|
||||||
"Items": {
|
"Items": {
|
||||||
@@ -326,6 +340,7 @@ class SchemagenCyclicArrayTest(unittest.TestCase):
|
|||||||
def test_chain_of_array_refs_rejected(self):
|
def test_chain_of_array_refs_rejected(self):
|
||||||
schema = {
|
schema = {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
|
"additionalProperties": False,
|
||||||
"properties": {"x": {"$ref": "#/$defs/A"}},
|
"properties": {"x": {"$ref": "#/$defs/A"}},
|
||||||
"$defs": {
|
"$defs": {
|
||||||
"A": {"type": "array", "items": {"$ref": "#/$defs/B"}},
|
"A": {"type": "array", "items": {"$ref": "#/$defs/B"}},
|
||||||
@@ -339,6 +354,7 @@ class SchemagenCyclicArrayTest(unittest.TestCase):
|
|||||||
def test_non_recursive_array_refs_still_allowed(self):
|
def test_non_recursive_array_refs_still_allowed(self):
|
||||||
schema = {
|
schema = {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
|
"additionalProperties": False,
|
||||||
"properties": {"roles": {"$ref": "#/$defs/Roles"}},
|
"properties": {"roles": {"$ref": "#/$defs/Roles"}},
|
||||||
"$defs": {
|
"$defs": {
|
||||||
"Role": {"enum": ["admin", "user"]},
|
"Role": {"enum": ["admin", "user"]},
|
||||||
@@ -439,10 +455,12 @@ class SchemagenCyclicNullableObjectTest(unittest.TestCase):
|
|||||||
self.skipTest("C++ compiler not available")
|
self.skipTest("C++ compiler not available")
|
||||||
schema = {
|
schema = {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
|
"additionalProperties": False,
|
||||||
"properties": {"self": {"$ref": "#/$defs/Self"}},
|
"properties": {"self": {"$ref": "#/$defs/Self"}},
|
||||||
"$defs": {
|
"$defs": {
|
||||||
"Self": {
|
"Self": {
|
||||||
"type": ["object", "null"],
|
"type": ["object", "null"],
|
||||||
|
"additionalProperties": False,
|
||||||
"properties": {"self": {"$ref": "#/$defs/Self"}},
|
"properties": {"self": {"$ref": "#/$defs/Self"}},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -592,6 +610,13 @@ class SchemagenIntegerBoundaryTest(unittest.TestCase):
|
|||||||
("123.0", "WeaselJson_OK", 123),
|
("123.0", "WeaselJson_OK", 123),
|
||||||
("9e18", "WeaselJson_OK", 9000000000000000000),
|
("9e18", "WeaselJson_OK", 9000000000000000000),
|
||||||
("10e18", "WeaselJson_REJECT", 0),
|
("10e18", "WeaselJson_REJECT", 0),
|
||||||
|
# Issue #56: zero written with a negative exponent must be accepted.
|
||||||
|
("0e-1", "WeaselJson_OK", 0),
|
||||||
|
("0e-2", "WeaselJson_OK", 0),
|
||||||
|
("0.0e-2", "WeaselJson_OK", 0),
|
||||||
|
("-0e-2", "WeaselJson_OK", 0),
|
||||||
|
("0e-20", "WeaselJson_OK", 0),
|
||||||
|
("0.000e-5", "WeaselJson_OK", 0),
|
||||||
]
|
]
|
||||||
cases_src = self._build_cases_array("root", cases)
|
cases_src = self._build_cases_array("root", cases)
|
||||||
harness = textwrap.dedent(
|
harness = textwrap.dedent(
|
||||||
@@ -634,6 +659,9 @@ class SchemagenIntegerBoundaryTest(unittest.TestCase):
|
|||||||
('{"age":2.0}', "WeaselJson_OK", 2),
|
('{"age":2.0}', "WeaselJson_OK", 2),
|
||||||
('{"age":0.0001e4}', "WeaselJson_OK", 1),
|
('{"age":0.0001e4}', "WeaselJson_OK", 1),
|
||||||
('{"age":0.001}', "WeaselJson_REJECT", 0),
|
('{"age":0.001}', "WeaselJson_REJECT", 0),
|
||||||
|
# Issue #56: zero written with a negative exponent must be accepted.
|
||||||
|
('{"age":0e-2}', "WeaselJson_OK", 0),
|
||||||
|
('{"age":-0e-20}', "WeaselJson_OK", 0),
|
||||||
(
|
(
|
||||||
'{"age":-9223372036854775808.0}',
|
'{"age":-9223372036854775808.0}',
|
||||||
"WeaselJson_OK",
|
"WeaselJson_OK",
|
||||||
@@ -670,6 +698,7 @@ class SchemagenIntegerBoundaryTest(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
schema = {
|
schema = {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
|
"additionalProperties": False,
|
||||||
"properties": {"age": {"type": "integer"}},
|
"properties": {"age": {"type": "integer"}},
|
||||||
"required": ["age"],
|
"required": ["age"],
|
||||||
}
|
}
|
||||||
@@ -785,14 +814,22 @@ class SchemagenStringEscapeTest(unittest.TestCase):
|
|||||||
|
|
||||||
def test_newline_in_property_key(self):
|
def test_newline_in_property_key(self):
|
||||||
"""A JSON key containing a newline must become a valid C++ literal."""
|
"""A JSON key containing a newline must become a valid C++ literal."""
|
||||||
schema = {"type": "object", "properties": {"a\nb": {"type": "string"}}}
|
schema = {
|
||||||
|
"type": "object",
|
||||||
|
"additionalProperties": False,
|
||||||
|
"properties": {"a\nb": {"type": "string"}},
|
||||||
|
}
|
||||||
out = self.generate_and_compile(schema)
|
out = self.generate_and_compile(schema)
|
||||||
self.assertIn('// "a\\nb"', out)
|
self.assertIn('// "a\\nb"', out)
|
||||||
self.assertIn('if (key == "a\\nb") return 0;', out)
|
self.assertIn('if (key == "a\\nb") return 0;', out)
|
||||||
|
|
||||||
def test_newline_in_enum_value(self):
|
def test_newline_in_enum_value(self):
|
||||||
"""An enum value containing a newline must become a valid C++ literal."""
|
"""An enum value containing a newline must become a valid C++ literal."""
|
||||||
schema = {"type": "object", "properties": {"x": {"enum": ["a\nb"]}}}
|
schema = {
|
||||||
|
"type": "object",
|
||||||
|
"additionalProperties": False,
|
||||||
|
"properties": {"x": {"enum": ["a\nb"]}},
|
||||||
|
}
|
||||||
out = self.generate_and_compile(schema)
|
out = self.generate_and_compile(schema)
|
||||||
self.assertIn('static constexpr const char *X_names[] = { "a\\nb" };', out)
|
self.assertIn('static constexpr const char *X_names[] = { "a\\nb" };', out)
|
||||||
|
|
||||||
@@ -800,6 +837,7 @@ class SchemagenStringEscapeTest(unittest.TestCase):
|
|||||||
"""Mixed control characters in an enum value must be escaped."""
|
"""Mixed control characters in an enum value must be escaped."""
|
||||||
schema = {
|
schema = {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
|
"additionalProperties": False,
|
||||||
"properties": {
|
"properties": {
|
||||||
"x": {"enum": ["x\ny\rz\tw\vq\x00\x01"]},
|
"x": {"enum": ["x\ny\rz\tw\vq\x00\x01"]},
|
||||||
},
|
},
|
||||||
@@ -812,7 +850,11 @@ class SchemagenStringEscapeTest(unittest.TestCase):
|
|||||||
|
|
||||||
def test_backslash_and_quote_still_escaped(self):
|
def test_backslash_and_quote_still_escaped(self):
|
||||||
"""Existing escaping for backslash and double quote must remain correct."""
|
"""Existing escaping for backslash and double quote must remain correct."""
|
||||||
schema = {"type": "object", "properties": {'a"b\\c': {"type": "string"}}}
|
schema = {
|
||||||
|
"type": "object",
|
||||||
|
"additionalProperties": False,
|
||||||
|
"properties": {'a"b\\c': {"type": "string"}},
|
||||||
|
}
|
||||||
out = self.generate_and_compile(schema)
|
out = self.generate_and_compile(schema)
|
||||||
self.assertIn('// "a\\"b\\\\c"', out)
|
self.assertIn('// "a\\"b\\\\c"', out)
|
||||||
self.assertIn('if (key == "a\\"b\\\\c") return 0;', out)
|
self.assertIn('if (key == "a\\"b\\\\c") return 0;', out)
|
||||||
|
|||||||
@@ -417,7 +417,13 @@ class Builder:
|
|||||||
tobj = TObj(name)
|
tobj = TObj(name)
|
||||||
if defname is not None:
|
if defname is not None:
|
||||||
self._building[defname] = (tobj, nullable)
|
self._building[defname] = (tobj, nullable)
|
||||||
ap = node.get("additionalProperties", False)
|
ap = node.get("additionalProperties", None)
|
||||||
|
if ap is None:
|
||||||
|
raise GenError(
|
||||||
|
"additionalProperties is required for object schemas; set it "
|
||||||
|
"explicitly to false to reject unknown keys (absent "
|
||||||
|
"additionalProperties is not supported)"
|
||||||
|
)
|
||||||
if ap is True:
|
if ap is True:
|
||||||
raise GenError("additionalProperties: true is not supported")
|
raise GenError("additionalProperties: true is not supported")
|
||||||
if isinstance(ap, dict):
|
if isinstance(ap, dict):
|
||||||
@@ -1058,10 +1064,10 @@ private:
|
|||||||
++trim;
|
++trim;
|
||||||
}}
|
}}
|
||||||
int64_t finalExp = exp - fracDigits + trim;
|
int64_t finalExp = exp - fracDigits + trim;
|
||||||
if (finalExp < 0) return false;
|
|
||||||
size_t leadingZeros = 0;
|
size_t leadingZeros = 0;
|
||||||
while (leadingZeros < digits.size() && digits[leadingZeros] == '0') ++leadingZeros;
|
while (leadingZeros < digits.size() && digits[leadingZeros] == '0') ++leadingZeros;
|
||||||
if (leadingZeros == digits.size()) {{ out = 0; return true; }}
|
if (leadingZeros == digits.size()) {{ out = 0; return true; }}
|
||||||
|
if (finalExp < 0) return false;
|
||||||
if (leadingZeros > 0) digits.erase(0, leadingZeros);
|
if (leadingZeros > 0) digits.erase(0, leadingZeros);
|
||||||
|
|
||||||
constexpr uint64_t kMaxNeg = 9223372036854775808ULL;
|
constexpr uint64_t kMaxNeg = 9223372036854775808ULL;
|
||||||
|
|||||||
@@ -38,6 +38,8 @@ enum WeaselJsonStatus {
|
|||||||
WeaselJson_REJECT,
|
WeaselJson_REJECT,
|
||||||
/** json is too deeply nested */
|
/** json is too deeply nested */
|
||||||
WeaselJson_OVERFLOW,
|
WeaselJson_OVERFLOW,
|
||||||
|
/** Tried to call parse on a null parser */
|
||||||
|
WeaselJson_NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct WeaselJsonParser WeaselJsonParser;
|
typedef struct WeaselJsonParser WeaselJsonParser;
|
||||||
@@ -65,7 +67,7 @@ void WeaselJsonParser_destroy(WeaselJsonParser *parser);
|
|||||||
/** Incrementally parse `len` more bytes starting at `buf`. `buf` may be
|
/** Incrementally parse `len` more bytes starting at `buf`. `buf` may be
|
||||||
* modified. Call with `len` 0 to indicate end of data. `buf` may be null if
|
* modified. Call with `len` 0 to indicate end of data. `buf` may be null if
|
||||||
* `len` is 0. `len` must not be negative; a negative length is treated as a
|
* `len` is 0. `len` must not be negative; a negative length is treated as a
|
||||||
* rejected input. */
|
* rejected input. Returns WeaselJson_NULL if parser is null */
|
||||||
WeaselJsonStatus WeaselJsonParser_parse(WeaselJsonParser *parser, char *buf,
|
WeaselJsonStatus WeaselJsonParser_parse(WeaselJsonParser *parser, char *buf,
|
||||||
int len);
|
int len);
|
||||||
|
|
||||||
|
|||||||
@@ -46,6 +46,9 @@ WeaselJsonParser_destroy(WeaselJsonParser *parser) {
|
|||||||
|
|
||||||
__attribute__((visibility("default"))) WeaselJsonStatus
|
__attribute__((visibility("default"))) WeaselJsonStatus
|
||||||
WeaselJsonParser_parse(WeaselJsonParser *parser, char *buf, int len) {
|
WeaselJsonParser_parse(WeaselJsonParser *parser, char *buf, int len) {
|
||||||
|
if (parser == nullptr) [[unlikely]] {
|
||||||
|
return WeaselJson_NULL;
|
||||||
|
}
|
||||||
return ((Parser3 *)parser)->parse(buf, len);
|
return ((Parser3 *)parser)->parse(buf, len);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-20
@@ -139,8 +139,7 @@ struct Parser3 {
|
|||||||
stackPtr = stack();
|
stackPtr = stack();
|
||||||
std::ignore = push({N_VALUE, N_WHITESPACE, T_EOF});
|
std::ignore = push({N_VALUE, N_WHITESPACE, T_EOF});
|
||||||
inKey = false;
|
inKey = false;
|
||||||
rejected = false;
|
terminalStatus = WeaselJson_OK;
|
||||||
overflowed = false;
|
|
||||||
utf8Codepoint = 0;
|
utf8Codepoint = 0;
|
||||||
utf16Surrogate = 0;
|
utf16Surrogate = 0;
|
||||||
minCodepoint = 0;
|
minCodepoint = 0;
|
||||||
@@ -163,8 +162,7 @@ struct Parser3 {
|
|||||||
NumDfa numDfa;
|
NumDfa numDfa;
|
||||||
Utf8Dfa strDfa;
|
Utf8Dfa strDfa;
|
||||||
bool inKey = false;
|
bool inKey = false;
|
||||||
bool rejected = false;
|
WeaselJsonStatus terminalStatus = WeaselJson_OK;
|
||||||
bool overflowed = false;
|
|
||||||
|
|
||||||
#ifndef HAS_MUSTTAIL
|
#ifndef HAS_MUSTTAIL
|
||||||
char *stashBufForTrampoline;
|
char *stashBufForTrampoline;
|
||||||
@@ -652,7 +650,7 @@ inline PRESERVE_NONE ContinuationStatus n_string2(Parser3 *self, char *buf,
|
|||||||
self->writeBuf[0] = (0b00000111 & codepoint) | 0b11110000;
|
self->writeBuf[0] = (0b00000111 & codepoint) | 0b11110000;
|
||||||
self->writeBuf += 4;
|
self->writeBuf += 4;
|
||||||
}
|
}
|
||||||
} else if (0xdc00 <= codepoint && codepoint <= 0xdfff) {
|
} else if (0xdc00 <= codepoint && codepoint <= 0xdfff) [[unlikely]] {
|
||||||
return WeaselJson_REJECT;
|
return WeaselJson_REJECT;
|
||||||
} else {
|
} else {
|
||||||
if (!(self->flags & WeaselJsonRaw)) {
|
if (!(self->flags & WeaselJsonRaw)) {
|
||||||
@@ -1072,16 +1070,12 @@ constexpr inline struct ContinuationTable {
|
|||||||
inline WeaselJsonStatus Parser3::parse(char *buf, int len) {
|
inline WeaselJsonStatus Parser3::parse(char *buf, int len) {
|
||||||
this->dataBegin = this->writeBuf = buf;
|
this->dataBegin = this->writeBuf = buf;
|
||||||
|
|
||||||
if (this->rejected) [[unlikely]] {
|
if (this->terminalStatus != WeaselJson_OK) [[unlikely]] {
|
||||||
return WeaselJson_REJECT;
|
return this->terminalStatus;
|
||||||
}
|
|
||||||
|
|
||||||
if (this->overflowed) [[unlikely]] {
|
|
||||||
return WeaselJson_OVERFLOW;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (len < 0) [[unlikely]] {
|
if (len < 0) [[unlikely]] {
|
||||||
this->rejected = true;
|
this->terminalStatus = WeaselJson_REJECT;
|
||||||
return WeaselJson_REJECT;
|
return WeaselJson_REJECT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1091,10 +1085,8 @@ inline WeaselJsonStatus Parser3::parse(char *buf, int len) {
|
|||||||
// range.
|
// range.
|
||||||
ContinuationStatus status =
|
ContinuationStatus status =
|
||||||
symbolTables.continuations[top()](this, buf, buf + len);
|
symbolTables.continuations[top()](this, buf, buf + len);
|
||||||
if (status == WeaselJson_REJECT) {
|
if (status > WeaselJson_AGAIN) {
|
||||||
this->rejected = true;
|
this->terminalStatus = WeaselJsonStatus(status);
|
||||||
} else if (status == WeaselJson_OVERFLOW) {
|
|
||||||
this->overflowed = true;
|
|
||||||
}
|
}
|
||||||
return WeaselJsonStatus(status);
|
return WeaselJsonStatus(status);
|
||||||
#else
|
#else
|
||||||
@@ -1103,10 +1095,8 @@ inline WeaselJsonStatus Parser3::parse(char *buf, int len) {
|
|||||||
while ((result = symbolTables.continuations[top()](
|
while ((result = symbolTables.continuations[top()](
|
||||||
this, stashBufForTrampoline, buf + len)) == kBounce)
|
this, stashBufForTrampoline, buf + len)) == kBounce)
|
||||||
;
|
;
|
||||||
if (result == WeaselJson_REJECT) {
|
if (result > WeaselJson_AGAIN) {
|
||||||
this->rejected = true;
|
this->terminalStatus = WeaselJsonStatus(result);
|
||||||
} else if (result == WeaselJson_OVERFLOW) {
|
|
||||||
this->overflowed = true;
|
|
||||||
}
|
}
|
||||||
return WeaselJsonStatus(result);
|
return WeaselJsonStatus(result);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -330,6 +330,10 @@ TEST_CASE("parse rejects negative length") {
|
|||||||
WeaselJsonParser_destroy(parser);
|
WeaselJsonParser_destroy(parser);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Calling parse with nullptr doesn't crash") {
|
||||||
|
REQUIRE(WeaselJsonParser_parse(nullptr, nullptr, 0) == WeaselJson_NULL);
|
||||||
|
}
|
||||||
|
|
||||||
TEST_CASE("streaming") { testStreaming(json); }
|
TEST_CASE("streaming") { testStreaming(json); }
|
||||||
|
|
||||||
TEST_CASE("reset clears inKey and transient state") {
|
TEST_CASE("reset clears inKey and transient state") {
|
||||||
|
|||||||
@@ -33,6 +33,9 @@ int main(int argc, char **argv) {
|
|||||||
case WeaselJson_REJECT:
|
case WeaselJson_REJECT:
|
||||||
case WeaselJson_OVERFLOW:
|
case WeaselJson_OVERFLOW:
|
||||||
return 1;
|
return 1;
|
||||||
|
case WeaselJson_NULL:
|
||||||
|
fprintf(stderr, "parse called with a null parser\n");
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
if (l == 0) {
|
if (l == 0) {
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ class WeaselJsonStatus(enum.Enum):
|
|||||||
AGAIN = 1
|
AGAIN = 1
|
||||||
REJECT = 2
|
REJECT = 2
|
||||||
OVERFLOW = 3
|
OVERFLOW = 3
|
||||||
|
NULL = 4
|
||||||
|
|
||||||
|
|
||||||
class WeaselJsonCallbacksBase:
|
class WeaselJsonCallbacksBase:
|
||||||
|
|||||||
Reference in New Issue
Block a user