trimPathRegex is quadratic on a long run of slashes

オープン 初心者向け
#757 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
77/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
javascript, node.js, typescript

調査の方向性

まずルーターのソースコード内で 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分
マージ済み PR(30日)
21

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

solidjs/solid-router のほかの issue

solidjs/solid-router の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。