fix: escape property names in the schema refs the generated code validates against - #882
Open
nigrosimone wants to merge 2 commits into
Open
nigrosimone wants to merge 2 commits into
nigrosimone wants to merge 2 commits into
Conversation
nigrosimone
marked this pull request as ready for review
September 13, 2026 11:30
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.
A property whose subschema has
anyOf,oneOforifis validated at run time through ajv, by a schema ref the generated code carries as a string literal:validator.validate("#/properties/<name>/oneOf/0", ...). The name goes in unescaped, so a property named with a newline, a quote or a backslash makes the build throwInvalid or unexpected token, and the same ref is used unescaped in theTypeErrortemplate of a mismatch. The JSON pointer is not escaped either, so a name with a/or a~points at nothing and ajv answersno schema with key or ref. The ref also sits on a comment line above the function of a nested object or array, where a newline or a U+2028 in the name ends the comment and the rest of the name becomes code.The fix embeds the ref and the message with
JSON.stringify, escapes the pointer segments as RFC 6901 says, and escapes the line terminators on the comment lines.The added test builds each of the three keywords with such names, and a nested object under a name with a line terminator: 24 of its 39 cases fail on main, all pass here.