Skip to content

Commit ff6a382

Browse files
authored
fix(studio-server): normalize watch paths in linear time
1 parent f25defd commit ff6a382

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

‎packages/studio-server/src/helpers/previewWatchIgnore.test.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ describe("preview reload filtering", () => {
7575
expect(shouldReloadPreview(dir, "index.html")).toBe(true);
7676
});
7777

78+
it("handles long runs of separators in untrusted settings", () => {
79+
const separators = "/".repeat(100_000);
80+
expect(normalizePreviewWatchIgnore([`docs${separators}`])).toEqual(["docs"]);
81+
expect(normalizePreviewWatchIgnore([`docs${separators}report.json`])).toEqual([]);
82+
});
83+
7884
it("rejects exclusions that could hide the whole project or escape its root", () => {
7985
expect(
8086
normalizePreviewWatchIgnore([

‎packages/studio-server/src/helpers/previewWatchIgnore.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ export function normalizePreviewWatchIgnore(value: unknown): string[] {
77
if (!Array.isArray(value)) return [];
88
return value.flatMap((entry: unknown) => {
99
if (typeof entry !== "string") return [];
10-
const path = entry.replace(/\\/g, "/").replace(/^\.\//, "").replace(/\/+$/, "");
10+
const normalized = entry.replace(/\\/g, "/").replace(/^\.\//, "");
11+
let end = normalized.length;
12+
while (end > 0 && normalized[end - 1] === "/") end -= 1;
13+
const path = normalized.slice(0, end);
1114
if (
1215
!path ||
1316
path.startsWith("/") ||

0 commit comments

Comments
 (0)