trimPathRegex is quadratic on a long run of slashes

未關閉 適合新手
#757 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
77/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍

研究方向

先在路由器原始碼中找到 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
  1. 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");
  1. It prints about 2650 ms.
  2. In an app using the router, navigate client-side (link or history.pushState) to /streams followed by 100,000 slashes and x: 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 範本
  • 閱讀貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

solidjs/solid-router 的其他 Issue

查看 solidjs/solid-router 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。