Skip to content

fix: avoid mutating object schema definitions during construction#412

Merged
nzakas merged 1 commit intomainfrom
fix/object-schema-no-definition-mutation
Mar 23, 2026
Merged

fix: avoid mutating object schema definitions during construction#412
nzakas merged 1 commit intomainfrom
fix/object-schema-no-definition-mutation

Conversation

@Pixel998
Copy link
Copy Markdown
Contributor

Prerequisites checklist

AI acknowledgment

  • I did not use AI to generate this PR.
  • (If the above is not checked) I have reviewed the AI-generated content before submitting.

What did you do?

Constructed an ObjectSchema from a definitions object and then checked the original object afterward.

const definitions = {
	foo: {
		merge: "replace",
		validate: "string",
	},
};

new ObjectSchema(definitions);

What did you expect to happen?

The original definitions object should remain unchanged.

definitions.foo.merge === "replace";
definitions.foo.validate === "string";

What actually happened?

The constructor normalized the definitions in place and replaced the original string values with functions.

What is the purpose of this pull request?

This PR prevents ObjectSchema from mutating caller-provided schema definitions during construction.

What changes did you make? (Give an overview)

  • Updated the constructor to normalize each definition into a local value instead of assigning normalized handlers back onto the input definitions object.
  • Added a regression test.

Related Issues

Is there anything you'd like reviewers to focus on?

@github-project-automation github-project-automation Bot moved this to Needs Triage in Triage Mar 23, 2026
@eslint-github-bot eslint-github-bot Bot added the bug Something isn't working label Mar 23, 2026
@Pixel998 Pixel998 moved this from Needs Triage to Implementing in Triage Mar 23, 2026
Copy link
Copy Markdown
Member

@mdjermanovic mdjermanovic left a comment

Choose a reason for hiding this comment

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

LGTM, thanks! Leaving this open for a couple more days in case anyone else would like to review.

@mdjermanovic mdjermanovic moved this from Implementing to Merge Candidates in Triage Mar 23, 2026
Copy link
Copy Markdown
Member

@nzakas nzakas left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks!

@nzakas nzakas merged commit f0fd9a2 into main Mar 23, 2026
50 of 52 checks passed
@nzakas nzakas deleted the fix/object-schema-no-definition-mutation branch March 23, 2026 19:37
@github-project-automation github-project-automation Bot moved this from Merge Candidates to Complete in Triage Mar 23, 2026
@eslintbot eslintbot mentioned this pull request Mar 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

Status: Complete

Development

Successfully merging this pull request may close these issues.

3 participants