Skip to content

fix: trim leading and trailing slashes in linear time (#757) - #758

Open
saudademjj wants to merge 2 commits into
solidjs:mainfrom
saudademjj:fix/linear-trim-path-757
Open

saudademjj wants to merge 2 commits into
solidjs:mainfrom
saudademjj:fix/linear-trim-path-757

Conversation

@saudademjj

Copy link
Copy Markdown

Fixes #757

Summary

  • Replace trimPathRegex (/^\/+|(\/)\/+$/g) in src/utils.ts with a linear-time trimPath scan so long runs of slashes no longer trigger quadratic regex backtracking (e.g. "/streams" + "/".repeat(100_000) + "x" drops from ~16s to <1ms while keeping identical normalization output).
  • Replace the trailing /\/+$/ regex in plainHref and isUnderBase with a linear-time stripTrailingSlashes helper for the same reason.
  • Add unit tests in test/utils.spec.ts covering normalizePath edge cases and linear-time regression checks for normalizePath, plainHref, and isUnderBase.

Verification

  • npm test (54 client test files / 780 tests, 17 server test files / 110 tests, test:types) passed.
  • npm run build and prettier --check passed.

@changeset-bot

changeset-bot Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a6c8125

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@solidjs/router Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

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.

trimPathRegex is quadratic on a long run of slashes

1 participant