fix(utils): wrap discriminator merge check in parentheses to fix precedence#16351
Merged
vkarpov15 merged 1 commit intoJul 6, 2026
Conversation
…edence Backport of Automattic#16187 to 7.x. Because && binds tighter than ||, the isDiscriminatorSchemaMerge guard parsed as (A && B) || C, so merge() also skipped a single-nested vs document-array path on a normal merge where isDiscriminatorSchemaMerge is false. Wrapping the clauses restores A && (B || C). Re: Automatticgh-9534
AbdelrahmanHafez
approved these changes
Jul 1, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Backports a fix to utils.merge() in the 7.x line to ensure the discriminator-specific schema merge guard is correctly gated by options.isDiscriminatorSchemaMerge, preventing unintended key skipping in normal merges.
Changes:
- Fix JavaScript operator-precedence in
utils.merge()by wrapping the discriminator mismatch check in parentheses. - Add regression tests ensuring the mismatch-skip behavior only applies when
isDiscriminatorSchemaMerge: true.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| lib/utils.js | Wrapes the single-nested vs document-array mismatch condition so it’s fully guarded by isDiscriminatorSchemaMerge. |
| test/utils.test.js | Adds regression coverage for both discriminator and non-discriminator merge behavior for the mismatch case. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
vkarpov15
approved these changes
Jul 6, 2026
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.
Backports #16187 to the 7.x line.
utils.merge()guards against merging a single-nested path against a document-array path (and vice versa) when building a discriminator schema (gh-9534). Because&&binds tighter than||, the conditionparses as
(A && B) || C, so thecontinuealso fires whenisDiscriminatorSchemaMergeis false andfromis a document array whiletois single-nested. The path is then silently dropped from a normal (non-discriminator) merge. Wrapping the two clauses restoresA && (B || C).The 7.x
utils.merge()body is identical to master apart from this grouping, so the fix and its test port over unchanged.Verified on 7.x: the
isDiscriminatorSchemaMerge: falsetest fails before the change (undefined !== 2) and passes after;test/utils.test.jsstays green (26 passing).