Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't mutate a schema with a transform keyword while compiling it. #173

Merged
merged 1 commit into from
Nov 21, 2021

Conversation

n-e
Copy link
Contributor

@n-e n-e commented May 4, 2021

=> If the schema is compiled twice, the second validator function won't work properly since the transform array will have been emptied.

@@ -54,13 +54,15 @@ function _getDef(): CodeKeywordDefinition {

function transformExpr(ts: string[]): Code {
if (!ts.length) return data
const t = ts.pop() as string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to pass tNames.slice() above rather than to copy on every iteration... Mostly because to is clearer what is going on.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 🙂

@epoberezkin
Copy link
Member

Thank you - good catch - see the comment.

@n-e n-e force-pushed the do-not-mutate branch from da3df95 to 07a2c98 Compare May 7, 2021 08:37
@n-e n-e requested a review from epoberezkin May 21, 2021 15:45
@anlerandy
Copy link

This should fix everything discussed on #152.
Thanks @n-e & @epoberezkin.

@epoberezkin epoberezkin merged commit bc73a2d into ajv-validator:master Nov 21, 2021
@epoberezkin
Copy link
Member

sorry - forgot about it... Better late than never

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

Successfully merging this pull request may close these issues.

3 participants