镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

[Tests] parse: characterize the ]= split on parts with no open bracket group - #620

Merged
ljharb merged 1 commit into
ljharb:mainfrom
euriconicacio:pin-resplit-shapes
Oct 14, 2026
Merged

ljharb merged 1 commit into
ljharb:mainfrom
euriconicacio:pin-resplit-shapes

Conversation

@euriconicacio

Copy link
Copy Markdown
Contributor

You mentioned that deterministic test cases for these shapes would be a welcome PR. This is that — test/parse.js only, no behaviour change.

It adds four assertions for parts where ]= appears but no bracket group ever opened. The suite pins what the ]= shortcut exists for — a[>=]=23, a[<=>]==23, a[==]=23 — and pins nothing for what it does when there is no group to serve.

These characterize today's output rather than endorse it, in the same spirit as the issue #558 blocks a few lines below, and they reuse the characterizeParse helper you added with them. That is deliberate: the split moved once already without anyone noticing. role=guest%5D=admin parses one way through 6.12.1 and another from 6.12.2 on, the changelog line for that commit does not mention it, and no test caught it. These make the next such change loud.

The comment above the block names what each case becomes under a bracket-depth scanner, so whoever lands one updates the assertions in the same commit:

'a=b[c]=d'                -> { a: 'b[c]=d' }
'q=%5B1%5D=2'             -> { q: '[1]=2' }
'role=guest%5Bx%5Dy%5D=z' -> { role: 'guest[x]y]=z' }

which is what new URLSearchParams and node:querystring return for all three today.

Verified in both directions, since a passing suite on its own would prove nothing here:

tree result
main as-is 1113 / 1113 pass
a bracket-depth scanner applied locally 486 / 490 in test/parse.js — the four new assertions fail, and nothing else does

Under that scanner the three ]=-shortcut cases come out byte-identical. That is the control that matters: the new assertions detect a change to where the split lands without being tripped by a fix that leaves the shortcut's actual purpose alone.

Happy to drop any of the four, or to fold them into an existing block instead of a new one, if you would rather.

… bracket group

The `]=` shortcut exists so that a bracket group's contents may contain `=`
(`a[>=]=23`, `a[<=>]==23`, `a[==]=23`),
but `indexOf(']=')` scans the whole part,
so when the first `=` comes before any bracket group,
it moves the key/value split into the value instead.

Pin today's output rather than endorse it,
so that a change to where the split lands cannot ship unnoticed.
The encoded spellings already changed unnoticed once, in 6.12.2 (`81835ff`);
the literal `a=b[c]=d` has parsed this way since 1.0.0.

Under a bracket-depth scanner these become what `URLSearchParams` and `node:querystring` return today:
    a=b[c]=d                -> { a: 'b[c]=d' }
    q=%5B1%5D=2             -> { q: '[1]=2' }
    role=guest%5Bx%5Dy%5D=z -> { role: 'guest[x]y]=z' }
    role=guest%5D=admin     -> { role: 'guest]=admin' }

Co-authored-by: Eurico Nicacio <euriconicaciojr@gmail.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
@ljharb
ljharb force-pushed the pin-resplit-shapes branch from f925bfb to 3ee412c Compare October 14, 2026 18:06
@ljharb

ljharb commented Oct 14, 2026

Copy link
Copy Markdown
Owner

Thanks! Made a few changes before landing:

  • Moved the new test out of the middle of parses a simple string, so that existing test is untouched, and put it next to the other lenient-parsing characterizations (the issue 6.15.2 parse behavioral change breaks nested bracket query string parsing #558 blocks)
  • Renamed it to "currently moves the key/value split to a later ]= when the first = comes before any bracket group", since a group does open in two of the four cases; what they share is that the first = comes first
  • Fixed the third label: in role=guest%5Bx%5Dy%5D=z the group opens before the first ]=, but after the first =. The label now also notes that the trailing y is dropped, since that case pins that behavior too
  • Dropped the long comment, and moved its history and the expected bracket-depth-scanner outputs into the commit message, adding the fourth case (role=guest%5D=admin -> { role: 'guest]=admin' }) that the list was missing. I also noted there that the literal a=b[c]=d form has parsed this way since 1.0.0; only the encoded spellings changed in 6.12.2

@codecov

codecov Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (37a60ae) to head (3ee412c).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #620   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            9         9           
  Lines         2944      2950    +6     
  Branches       305       305           
=========================================
+ Hits          2944      2950    +6     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ljharb
ljharb merged commit 3ee412c into ljharb:main Oct 14, 2026
440 checks passed
github-actions Bot pushed a commit to modify-dev/harbor that referenced this pull request Oct 19, 2026
This PR contains the following updates:

| Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) |
|---|---|---|---|
| [qs](https://github.com/ljharb/qs) | [`6.16.0` → `6.16.1`](https://renovatebot.com/diffs/npm/qs/6.16.0/6.16.1) | ![age](https://developer.mend.io/api/mc/badges/age/npm/qs/6.16.1?slim=true) | ![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/qs/6.16.0/6.16.1?slim=true) |

---

> ⚠️ **Warning**
>
> Some dependencies could not be looked up. Check the [Dependency Dashboard](issues/99) for more information.

---

### Release Notes

<details>
<summary>ljharb/qs (qs)</summary>

### [`v6.16.1`](https://github.com/ljharb/qs/blob/HEAD/CHANGELOG.md#6161)

[Compare Source](ljharb/qs@v6.16.0...v6.16.1)

- \[Fix] `parse`: do not mutate an object input
- \[Fix] `stringify`: stop re-encoding structural separator dots when `encodeDotInKeys` is set ([#&#8203;564](ljharb/qs#564))
- \[Fix] `stringify`: `arrayFormat: 'comma'`: pass the full encoder arguments with `encodeValuesOnly`
- \[Fix] `utils`: encode `+` as `%2B` in iso-8859-1 mode so values round-trip ([#&#8203;565](ljharb/qs#565))
- \[Fix] parse: only convert top-level dots to brackets when allowDots is on ([#&#8203;621](ljharb/qs#621))
- \[Fix] `stringify`: ignore inherited array format names ([#&#8203;622](ljharb/qs#622))
- \[Fix] `stringify`: `arrayFormat: 'comma'`: do not throw on elements with no callable `toString`
- \[Fix] `utils`: `merge`: seed an overflow container's index from its own keys, not just the source
- \[Fix] `utils`: `merge`: keep a `strictMerge` conflict container's index and `arrayLimit` correct
- \[Fix] `parse`: only treat `[]` as array syntax when it ends the key
- \[Perf] `decode`: skip decoders when there is no percent sign ([#&#8203;583](ljharb/qs#583))
- \[Robustness] `utils`: `merge`: apply `arrayLimit` to the two-element array built for colliding values
- \[Robustness] `parse`: bound the nesting added by repeated `strictMerge` conflicts (credit [@&#8203;Yeaseen](https://github.com/Yeaseen))
- \[Docs] document that `qs` and flat parsers disagree about parameter names
- \[Docs] clarify that `throwOnLimitExceeded` limits each array, not the total number of values
- \[Docs] clarify 6.14.1/6.15.2 parse bracket behavior change ([#&#8203;567](ljharb/qs#567), [#&#8203;568](ljharb/qs#568))
- \[meta] fix changelog indents
- \[actions] set least-privilege `cache-mode`
- \[Tests] `utils`: `decode`: add missing cases
- \[Tests] `parse`: characterize the `]=` split when an `=` precedes any bracket group ([#&#8203;620](ljharb/qs#620))
- \[Tests] `parse`: `allowDots`: cover stray close brackets before a dot
- \[Dev Deps] update `@ljharb/eslint-config`, `eslint`, `tape`

</details>

---

### Configuration

📅 **Schedule**: (UTC)

- Branch creation
  - "before 9am on tuesday"
- Automerge
  - At any time (no schedule defined)

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate CLI](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0NC4xMzMuMCIsInVwZGF0ZWRJblZlciI6IjQ0LjE2Ny4wIiwidGFyZ2V0QnJhbmNoIjoiZGV2ZWxvcCIsImxhYmVscyI6WyJkZXBlbmRlbmNpZXMiLCJyZW5vdmF0ZSJdfQ==-->

Reviewed-on: https://code.futo.org/harbor/harbor/pulls/1824
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.

2 participants