Repository navigation
Add rfl::CodePoints validator for UTF-8 string length - #7
Closed
clockblocker wants to merge 1 commit into
Closed
clockblocker wants to merge 1 commit into
clockblocker wants to merge 1 commit into
Conversation
rfl::Size validates .size(), which is the byte count for std::string, but its JSON schema emits minLength/maxLength, which JSON Schema defines in Unicode code points. For non-ASCII strings the validator and the schema disagree. rfl::CodePoints<V> counts UTF-8 code points (bytes that are not continuation bytes) and applies V to that count. Its schema output is identical to rfl::Size, so it composes with AllOf/AnyOf the same way. rfl::Size is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Owner
Author
|
Merged upstream in munich-data-engineering#774. |
clockblocker
added a commit
that referenced
this pull request
Nov 28, 2026
- P0-1: Eliminate flattened_field_offsets<T>() and unconstructed dummy[sizeof(T)] entirely; extract live-object field pointers directly in write(), read_with_default(), and to_schema() (skipping extraction when _defaults == nullptr), add std::launder on destroy_field_erased, and reject aggregates with reference members in both C++20 (NonRefAggProbe) and C++26 (std::meta::is_reference). - P0-2: Replace all unevaluated-context generic lambdas in TableStructParser and DirectFieldNames with named visitor structs, and replace all 5 consteval make_table lambdas with direct static consteval pack-expansion helpers. - P1-1: Add use_table_struct_parser_ = true to boost_serialization/Parser.hpp (10/10 built-in NamedTuple specializations opted in). - P1-2: Gate Parser_named_tuple.hpp's use_table_struct_parser_ on R::UnsizedObjectReader so external ViewType-inspecting custom readers stay on NamedTupleParser without breaking; also catch exceptions inside NamedTupleParser::read_object_or_array_with_default's noexcept boundary. - P1-3: Replace global #ifndef RFL_TABLE_PARSER_MIN_FIELDS macro definition with internal constexpr kTableStructParserMinFields (with temporary TODO(#7) sweep hook). - P1-4 & Rule #14: Add direct <concepts>, <new>, and fail_fast_v.hpp includes in TableStructParser.hpp, remove unused is_field.hpp in DirectFieldNames.hpp, and align parsing helpers to namespace rfl::parsing (zero rfl::internal::parsing or detail namespaces, avoiding shadowing rfl::internal across include/rfl/parsing/). - P1-5: Launder &t on return from Parser_default::read_struct_with_default after const-subobject replacement. - P1-6: Expand test_descriptor_table_stress.cpp with N == 64 bitmask boundary (Wide64Fields), Flatten<EmptyStruct>, const Flatten<InnerPlain>, "___" / "a__b" case transforms, AllowRawPtrs wrapper pointers, reference-member rejection, ExternalViewTypeReader, rfl::env, and NamedTuple/Field fallbacks.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
rfl::Size<V>for string validates the number of bytes.The JSON schema however interprited that as Unicode code points
So for non-ASCII strings the two disagree.
AI-authored:
Take
"héllo": it is 6 bytes and 5 code points, sorfl::Size<rfl::Maximum<5>>rejects it while the schema it generates accepts it.What's added
rfl::CodePoints<V>(include/rfl/CodePoints.hpp, exported fromrfl.hpp). It counts UTF-8 code points, meaning every byte that is not a continuation byte (10xxxxxx), and runsVon that count.to_schemapasses through torfl::Size<V>, so the schema output is the same (minLength/maxLength) and it works withAllOf/AnyOfwithout touchingto_schema.cpp.docs/content/size_validation.md.Why a separate type instead of a flag on
Sizerfl::Sizebehaves exactly as before.Sizealso handles.Caveats
Tests
tests/json/test_code_points.cpp(picked up by the existingGLOB_RECURSEintests/json/CMakeLists.txt) covers:héllo,日本語, an emoji) that passCodePointsbut fail the matching byte-basedSizelimitMinimumminLength/maxLength, theAllOfform, and that it matchesSize)All 286 tests in
reflect-cpp-json-testspass locally (macOS, Apple clang, Release, bundled deps).🤖 Generated with Claude Code