Skip to content

fix: prevent crash when query params have conflicting dot-notation keys#2958

Merged
mikicho merged 2 commits intonock:mainfrom
ordinary9843:fix/expand-primitive-conflict
Apr 5, 2026
Merged

fix: prevent crash when query params have conflicting dot-notation keys#2958
mikicho merged 2 commits intonock:mainfrom
ordinary9843:fix/expand-primitive-conflict

Conversation

@ordinary9843
Copy link
Copy Markdown
Contributor

Fixes #2893.

When a query string contains params like parent=value&parent.1=first, the expand() function in common.js would crash with Cannot assign to read only property '1' of string 'value'. This happened because expand() first set parent to the string 'value', then tried to traverse into it as an object when processing the parent.1 key.

The fix adds a check before descending into an intermediate path segment: if the existing value is a non-null primitive (not an object or array), return undefined — the same sentinel value already used when a blocklisted key is encountered. dataEqual then compares both sides as undefined, which causes them to match correctly when both the intercepted URL and the nock scope have the same unbalanced query params.

Copy link
Copy Markdown
Member

@mikicho mikicho left a comment

Choose a reason for hiding this comment

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

LGTM

@mikicho mikicho enabled auto-merge (squash) April 5, 2026 20:13
@mikicho mikicho merged commit 7ea9933 into nock:main Apr 5, 2026
13 of 14 checks passed
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 5, 2026

🎉 This PR is included in version 14.0.12 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"Unbalanced" query parameters causes internal error.

2 participants