Repository navigation
Allow SAX parsing of tagged CBOR - #5740
Conversation
Signed-off-by: Tyagiquamar <mohdquamartyagi@gmail.com>
Resolved conflicts in include/nlohmann/json.hpp and single_include/nlohmann/json.hpp: kept the PR's new tag-handler sax_parse overloads inside develop's clang -Wdocumentation-deprecated-sync pragma block, updated their binary_reader::sax_parse calls to the no-format signature introduced by develop, and regenerated single_include via make amalgamate. Signed-off-by: Niels Lohmann <mail@nlohmann.me>
|
Thanks for the PR! I merged
(This comment was written by Claude Code.) |
Signed-off-by: Tyagiquamar <mohdquamartyagi@gmail.com>
|
Updated to consolidate the \sax_parse\ functions by adding the default \ ag_handler = cbor_tag_handler_t::error\ parameter directly to the existing signatures instead of having separate overloads. Documentation and \single_include\ have been regenerated, and all test suites pass locally in Docker. |
There was a problem hiding this comment.
Thanks for the update. Passing tag_handler as a defaulted parameter is exactly what we wanted. The code and tests look good to me. A few things before we can merge:
-
Please merge
developinto your branch. The current CI failures are not caused by this PR. They come from the state ofdevelopon 10-02:ci_test_gcc:-Wexperimental-fmv-targetis not recognized by GCCci_cpplint: missing<memory>include inordered_map.hppci_test_noexceptions: crash inunit-bon8.cpp
#5750 and #5754 address these on
develop. After merging, please regeneratesingle_includewithmake amalgamateif there are conflicts injson.hpp. -
Please add a version history entry to
docs/mkdocs/docs/api/basic_json/sax_parse.md, for example:- Added `tag_handler` in version 3.13.0.
(next to the existing
ignore_trailing_commasline). -
Please update the PR description. It still mentions "explicit tag-handler overloads" and says "existing overload signatures and defaults remain unchanged". Neither is true since 5a36060: the existing signatures now take an additional defaulted parameter.
Optional, not blocking: to pass tag_handler, callers have to spell out strict, ignore_comments, and ignore_trailing_commas first. That is consistent with from_cbor, so I'm fine with it as is.
(This comment was written by Claude Code.)
|
Merged \develop\ into the branch, added the version history entry for \ ag_handler\ in \docs/mkdocs/docs/api/basic_json/sax_parse.md, verified amalgamation and formatting, and updated the PR description. |
Signed-off-by: Niels Lohmann <mail@nlohmann.me> # Conflicts: # include/nlohmann/json.hpp # single_include/nlohmann/json.hpp
|
Thanks! |
* Fix CI on develop after #5585 - test-diagnostics-optimized: -O3 makes GCC's -Winline and -Wsuggest-attribute=pure/const warnings fire with the ci_test_gcc flag set; turn them off for this test. - test-diagnostics-optimized: suppress Clang's -Wexit-time-destructors for the static table in to_json. - Infer: raise pulse-max-disjuncts from 20 to 40. With the default, Pulse loses the stored type in basic_json::replace_value() and reports false null dereferences of get_ptr() results in unit-pointer_access.cpp. Signed-off-by: Niels Lohmann <mail@nlohmann.me> * Ignore Infer's false USE_AFTER_DELETE in ordered_map::erase Infer's std::string model keeps the buffer of a moved-from string, so the destroy-and-reconstruct loop in erase(first, last) looks like it destroys a buffer twice. Signed-off-by: Niels Lohmann <mail@nlohmann.me> * Mark throw_on_discarded()'s parameters as used without exceptions With JSON_NOEXCEPTION, JSON_THROW expands to std::abort(), so Clang's -Wunused-parameter breaks test-disabled_exceptions (since #5761). Signed-off-by: Niels Lohmann <mail@nlohmann.me> * Skip the span_input_adapter sax_parse checks with deleted deprecated functions The #5676 regression test (#5740) calls the deprecated sax_parse(span_input_adapter&&, ...), which JSON_DELETE_DEPRECATED_FUNCTIONS deletes, so ci_test_delete_deprecated_functions failed to build. Signed-off-by: Niels Lohmann <mail@nlohmann.me> * Fall back to the first entry in test-diagnostics-optimized's to_json clang-tidy (clang-analyzer-security.ArrayBound) flagged it->second for a value not in the table. Use the same fallback as NLOHMANN_JSON_SERIALIZE_ENUM; the test still fails with -Werror=array-bounds on the headers from before #5585. Signed-off-by: Niels Lohmann <mail@nlohmann.me> * Fix clang-tidy findings in tests from #5762 and #5774 - unit-regression2.cpp (#5762): const/auto for the destroy() test values; NOLINT the intended copy in check_destroy_edge_case(). - unit-serialization.cpp (#5774): build the expected strings with += instead of chained operator+ (performance-inefficient-string-concatenation). Signed-off-by: Niels Lohmann <mail@nlohmann.me> --------- Signed-off-by: Niels Lohmann <mail@nlohmann.me>
Fixes #5676.
sax_parserejects CBOR tags because its public signatures did not pass a tag handler to the binary reader. This also rejects binary values with a subtype written byto_cbor.Consolidate
sax_parseby adding a defaultedconst cbor_tag_handler_t tag_handler = cbor_tag_handler_t::errorparameter directly to the existingsax_parsesignatures (compatible inputs, iterator pairs, and the deprecated span adapter). The parameter passes the handler to the binary reader, allowing callers to chooseignoreorstore. Regression tests cover all three input forms, each handler mode, and the JSON path.Validation (Docker, GCC 12, C++11):
unit-regression3with multiple headers: 12 cases, 107 assertions passed.unit-regression3with the single header: 12 cases, 107 assertions passed.unit-cbor --test-case="Tagged values": 1 case, 209 assertions passed.Regenerated the single header with the repository amalgamation script and formatted with AStyle 3.4.13.
Changes are described with the cause and fix.
The existing issue is referenced.
OSS-Fuzz issue: not applicable.
Code coverage remains at 100%: not measured locally; the new branches have regression coverage.
Documentation is updated.
Ran
make amalgamate: ran its amalgamation script and pinned formatter directly.