This commit is contained in:
m-holger 2024-04-19 16:37:49 -05:00 committed by GitHub
commit fbefa3499d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 23 additions and 40 deletions

View File

@ -143,12 +143,6 @@ class JSON
QPDF_DLL
bool isDictionary() const;
// If the key is already in the dictionary, return true. Otherwise, mark it as seen and return
// false. This is primarily intended to be used by the parser to detect duplicate keys when the
// reactor blocks them from being added to the final dictionary.
QPDF_DLL
bool checkDictionaryKeySeen(std::string const& key);
// Accessors. Accessor behavior:
//
// - If argument is wrong type, including null, return false
@ -327,7 +321,6 @@ class JSON
~JSON_dictionary() override = default;
void write(Pipeline*, size_t depth) const override;
std::map<std::string, JSON> members;
std::set<std::string> parsed_keys;
};
struct JSON_array;
struct JSON_string: public JSON_value

View File

@ -287,16 +287,6 @@ JSON::addDictionaryMember(std::string const& key, JSON const& val)
}
}
bool
JSON::checkDictionaryKeySeen(std::string const& key)
{
if (auto* obj = m ? dynamic_cast<JSON_dictionary*>(m->value.get()) : nullptr) {
return !obj->parsed_keys.insert(key).second;
}
throw std::logic_error("JSON::checkDictionaryKey called on non-dictionary");
return false; // unreachable
}
JSON
JSON::makeArray()
{
@ -1266,11 +1256,6 @@ JSONParser::handleToken()
break;
case ps_dict_after_colon:
if (tos.checkDictionaryKeySeen(dict_key)) {
QTC::TC("libtests", "JSON parse duplicate key");
throw std::runtime_error(
"JSON: offset " + std::to_string(dict_key_offset) + ": duplicated dictionary key");
}
if (!reactor || !reactor->dictionaryItem(dict_key, item)) {
tos.addDictionaryMember(dict_key, item);
}

View File

@ -161,11 +161,6 @@ test_main()
assert(jarr.addArrayElement(uninitialized).isNull());
assert(!uninitialized.isArray());
assert(!uninitialized.isDictionary());
try {
uninitialized.checkDictionaryKeySeen("key");
assert(false);
} catch (std::logic_error&) {
}
std::string st_out = "unchanged";
assert(!uninitialized.getString(st_out));
assert(!uninitialized.getNumber(st_out));

View File

@ -90,6 +90,5 @@ JSON optional key 0
JSON 16 high high 0
JSON 16 low not after high 0
JSON 16 dangling high 0
JSON parse duplicate key 0
JSON schema array for single item 0
JSON schema array length mismatch 0

View File

@ -32,7 +32,7 @@ if ($^O ne 'msys')
cleanup();
my $good = 11;
my $good = 12;
for (my $i = 1; $i <= $good; ++$i)
{
@ -120,7 +120,7 @@ my @bad = (
"stray low surrogate", # 37
"high high surrogate", # 38
"dangling high surrogate", # 39
"duplicate dictionary key", # 40
"bs char in string", # 40
"decimal point after minus",# 41
"e after minus", # 42
"missing digit after e", # 43
@ -128,7 +128,7 @@ my @bad = (
"tab char in string", # 45
"cr char in string", # 46
"lf char in string", # 47
"bs char in string", # 48
#"bs char in string", # 40
);
my $i = 0;

View File

@ -1,6 +1 @@
{
"one": 1,
"two": 2,
"one": 3,
"four": 4
}
"bs in string"

View File

@ -1 +1 @@
exception: bad-40.json: JSON: offset 28: duplicated dictionary key
exception: bad-40.json: JSON: control or null character at offset 10

View File

@ -1 +0,0 @@
"bs in string"

View File

@ -1 +0,0 @@
exception: bad-48.json: JSON: control or null character at offset 10

View File

@ -0,0 +1,7 @@
dictionary start
dictionary item: one -> [11, 12): 1
dictionary item: two -> [23, 24): 2
dictionary item: one -> [35, 36): 3
dictionary item: four -> [48, 49): 4
container end: [0, 51): {}
{}

View File

@ -0,0 +1,6 @@
{
"one": 1,
"two": 2,
"one": 3,
"four": 4
}

View File

@ -0,0 +1,5 @@
{
"four": 4,
"one": 3,
"two": 2
}