trimPathRegex is quadratic on a long run of slashes
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 2/5
- 預估耗時
- 1-3 小時
- 新手友好度
- 77/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 活躍
- 技術堆疊
- javascript, node.js, typescript
- 領域
- frontend, performance
研究方向
先在路由器原始碼中找到 trimPathRegex 和 normalizePath,再使用提供的含有大量斜線的輸入,在 Node 中重現回報的執行時間。修改裁切方式,讓執行時間呈線性成長,並確認裁切後的路徑行為符合預期,且含有 100,000 個斜線的案例能快速完成。
由索引模型根據 Issue 內容生成。
描述
Describe the bug
In @solidjs/router 2.0.1, trimPathRegex = /^\/+|(\/)\/+$/g (used by normalizePath) backtracks quadratically when a path has a long run of slashes followed by another character. The regex engine rescans the run from every start position, then fails at $. A client-side navigation to such a path blocks the main thread.
Your Example Website or App
No app needed; the regex alone reproduces it in Node (see steps).
Steps to Reproduce the Bug or Issue
- Run in Node:
const s = "/streams" + "/".repeat(100000) + "x";
const t = performance.now();
s.replace(/^\/+|(\/)\/+$/g, "$1");
console.log(Math.round(performance.now() - t), "ms");
- It prints about 2650 ms.
- In an app using the router, navigate client-side (link or
history.pushState) to/streamsfollowed by 100,000 slashes andx: the page freezes for about 0.9 s in Chromium and Firefox and 2.9 s in WebKit. With 1,000,000 slashes it does not return within 30 s.
Expected behavior
Trimming slashes takes linear time; a long path does not freeze the page. A loop over charCodeAt from the end (or a regex without the backtracking \/+$ alternative) does it in well under 1 ms for 100,000 slashes.
Screenshots or Videos
No response
Platform
- @solidjs/router 2.0.1, solid-js 2.0.4
- Node 26.13.1
- Browsers: Chromium, Firefox and WebKit from Playwright 1.65.1
- OS: Linux
Additional context
Servers usually reject such long URLs on a direct load (e.g. HTTP 431 near 20,000 characters), so the reach is client-side links and history.pushState.
- 主要語言
- TypeScript
- 星號
- 1.3k
- 分支
- 193
- 平均合併
- 8 小時 48 分鐘
- 30 天內合併 PR
- 21
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 沒有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
solidjs/solid-router 的其他 Issue
-
[2.0.1] Internal links do a full page load on a custom scheme (Electron app://)可能已有人在做 @saudademjj 於 1 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 20/100
solidjs/solid-router#755 · 1 則留言 ·
維護者通常 1 天內回覆
-
[2.0.1] diagnostics: a request for // crashes the dev server (Invalid URL in describeInitial)可能已有人在做 @bryanlundberg 於 4 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 35/100
solidjs/solid-router#752 ·
維護者通常 1 天內回覆
-
liveQuery SSR: the producer of a `live()` server function is never finalized after the response ends (the `return()` queues behind a read-ahead `next()`)可能已有人在做 @clean99 於 2 天前認領。 未關閉
難度 4/5 3-5 天 新手友好度 48/100
solidjs/solid-router#751 ·
維護者通常 1 天內回覆
-
[2.0.1] hashHistory: link claims and useLinkState ignore the hash, so aria-current/data-active are wrong on every link可能已有人在做 @clean99 於 10 天前認領。 未關閉
難度 3/5 1-2 天 新手友好度 72/100
solidjs/solid-router#746 ·
維護者通常 1 天內回覆
-
難度 4/5 3-5 天 新手友好度 48/100
solidjs/solid-router#736 · 1 則留言 ·
維護者通常 1 天內回覆
查看 solidjs/solid-router 的全部 Issue
相似的 Issue
-
[Bug]: A Markdown link with both a :line suffix and a #L fragment opens a path containing ":line"未關閉
難度 2/5 1-3 小時 新手友好度 82/100
維護者通常 1 天內回覆
-
status:needs-triage type:bug workstream:refimpl
難度 2/5 1-3 小時 新手友好度 76/100
GenAI-Security-Project/agent-control-standard#764 ·
維護者通常 1 天內回覆
-
good first issue
難度 2/5 1-3 小時 新手友好度 85/100
TanbirRamim/vibereel#39 ·
-
難度 2/5 1-3 小時 新手友好度 76/100
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
難度 1/5 1 小時以內 新手友好度 72/100
lingdojo/kana-dojo#34988 · 1 則留言 · 5 個 reaction ·
維護者通常 1 天內回覆