Skip to content

Fix numeric string property names - #14

Open
howiezhao wants to merge 1 commit into
jdesgats:masterfrom
howiezhao:fix-numeric-string-property-names
Open

Fix numeric string property names#14
howiezhao wants to merge 1 commit into
jdesgats:masterfrom
howiezhao:fix-numeric-string-property-names

Conversation

@howiezhao

Copy link
Copy Markdown

When a JSON Schema uses a purely numeric string as a property name (e.g. "123456"), generate_validator crashes with an assertion error during schema compilation.

This is because ref_mt:child in store.lua navigates the schema tree by calling decodepart on every path segment. decodepart converts any string that looks like a number to n + 1 (to compensate for Lua's 1-based array indices when resolving JSON Pointer fragments). This is correct for array-typed keywords like items or allOf, but wrong for map-typed keywords (properties, patternProperties, definitions, dependencies) whose keys are always arbitrary strings. A property named "123456" would be looked up as schema.properties[123457], which is nil, causing assert to fail.

Introduce decode_key(part, parent) which behaves like decodepart for 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:child to track the previous path segment and pass it as the parent context to decode_key.

@Tieske

Tieske commented May 11, 2026

Copy link
Copy Markdown
Contributor

this has been fixed in lua-resty-ljsonschema fork since quite a while, available via LuaRocks

@howiezhao

Copy link
Copy Markdown
Author

this has been fixed in lua-resty-ljsonschema fork since quite a while, available via LuaRocks

Wow, thanks for reminding me, awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants