Skip to content

fix: match jQuery 4 output for bracketed keys, empty keys, and non-plain objects, and bump to v1.2.10 - #46

Merged
knowledgecode merged 5 commits into
masterfrom
develop
Oct 18, 2026
Merged

knowledgecode merged 5 commits into
masterfrom
develop

Conversation

@knowledgecode

Copy link
Copy Markdown
Owner

Summary

  • Fix three cases where the output differed from jQuery 4's $.param():
    • Array items under a key already ending in [] are added as-is ({ 'ids[]': [1, 2] } -> ids[]=1&ids[]=2, previously ids[][]=1&ids[][]=2)
    • Top-level empty-string keys are serialized ({ '': 'foo' } -> =foo, previously dropped)
    • Recursion follows jQuery's toType() class list, so Map, Set, typed arrays, arguments, and objects with a custom Symbol.toStringTag are walked key by key instead of stringified
  • Add 15 equivalence cases covering these inputs, and fix a duplicated test name (function #9 -> function #10)
  • README: point the traditional browser example at jquery-param.min.js (and close its <script> tag), and state that the output is tested against jQuery 4.x
  • CI: update actions/checkout and actions/setup-node to v7 (node24) and drop the build step that npm test already runs
  • Bump version to 1.2.10 and update dev dependencies (jsdom, rollup, vitest)

Behavior changes

Output changes only for inputs where it previously differed from jQuery:

Input 1.2.9 1.2.10 (= jQuery 4)
{ 'ids[]': [1, 2] } ids[][]=1&ids[][]=2 ids[]=1&ids[]=2
{ '': 'foo' } (empty) =foo
{ u: new Uint8Array([7, 8]) } u=7,8 u[0]=7&u[1]=8
{ m: new Map([['a', 1]]) } m=[object Map] (empty)

Commits

  • test: fix duplicate name of the RegExp function case
  • fix: match jQuery 4 for bracketed keys, empty keys, and non-plain objects
  • docs: fix UMD script example and update tested jQuery version
  • ci: update actions to v7 and drop redundant build step
  • chore: bump version to 1.2.10 and update dev dependencies

Test plan

  • npm test builds and passes all 114 test cases (99 existing + 15 new)
  • The new cases fail against the previous implementation (11 of 15; the other 4 lock in behavior that already matched)
  • All three build outputs contain the new logic
  • The UMD build exposes the global param in a clean context: param({ 'ids[]': [1, 2] }) -> ids%5B%5D=1&ids%5B%5D=2

…ects

- Add array items under a key already ending in "[]" as-is instead of
  bracketing them again (`ids[]=1`, not `ids[][]=1`)
- Serialize top-level empty-string keys (`=foo`) instead of dropping them
- Decide recursion with jQuery's toType() class list, so Map, Set, typed
  arrays, arguments, and custom Symbol.toStringTag objects are walked
  key by key like in jQuery

Add equivalence cases covering each of these inputs.
- Point the traditional browser example at jquery-param.min.js and
  close its script tag
- State that the output is tested against jQuery 4.x
actions/checkout and actions/setup-node v7 run on node24. `npm test`
already builds before running Vitest, so the separate build step ran
the build twice.
@knowledgecode
knowledgecode merged commit e8c1e8b into master Oct 18, 2026
2 checks passed
@knowledgecode
knowledgecode deleted the develop branch October 18, 2026 00:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant