Repository navigation
Add rfl::CodePoints validator for UTF-8 string length - #774
Merged
liuzicheng1987 merged 1 commit intoNov 12, 2026
Merged
liuzicheng1987 merged 1 commit into
liuzicheng1987 merged 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>
liuzicheng1987
merged commit Nov 12, 2026
8a1f52d
into
munich-data-engineering:main
176 checks passed
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, interprets that as Unicode code points
So for non-ASCII strings, there is a miscommunication.
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