Fix numeric string property names - #14
Open
howiezhao wants to merge 1 commit into
Open
Conversation
Contributor
|
this has been fixed in lua-resty-ljsonschema fork since quite a while, available via LuaRocks |
Author
Wow, thanks for reminding me, awesome! |
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.
When a JSON Schema uses a purely numeric string as a property name (e.g.
"123456"),generate_validatorcrashes with an assertion error during schema compilation.This is because
ref_mt:childinstore.luanavigates the schema tree by callingdecodeparton every path segment.decodepartconverts any string that looks like a number ton + 1(to compensate for Lua's 1-based array indices when resolving JSON Pointer fragments). This is correct for array-typed keywords likeitemsorallOf, but wrong for map-typed keywords (properties,patternProperties,definitions,dependencies) whose keys are always arbitrary strings. A property named"123456"would be looked up asschema.properties[123457], which isnil, causingassertto fail.Introduce
decode_key(part, parent)which behaves likedecodepartfor all keywords except the four map-typed ones (properties,patternProperties,definitions,dependencies). Under those keywords the numeric conversion is skipped and the key is returned as a plain URL-unescaped string.Update
ref_mt:childto track the previous path segment and pass it as the parent context todecode_key.