From 9da21a80048674c84c2c4aed795e54ff9523e304 Mon Sep 17 00:00:00 2001 From: Richard R Date: Thu, 4 Jun 2026 18:21:40 -0600 Subject: [PATCH] test(folders): use escaped regex for file name matching in drag-and-drop tests Update folder tests to use an exported escapeRegExp helper when constructing regex patterns for file name matching. This prevents false positives or errors when file names contain special regex characters, improving test reliability. --- tests/folders.spec.ts | 3 ++- tests/helpers.ts | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/folders.spec.ts b/tests/folders.spec.ts index b88c6f9..47035a2 100644 --- a/tests/folders.spec.ts +++ b/tests/folders.spec.ts @@ -7,6 +7,7 @@ import { dragAndDrop, expectDocumentListed, expectNoDocumentLink, + escapeRegExp, } from './helpers'; test.describe('Document folders and hint persistence', () => { @@ -16,7 +17,7 @@ test.describe('Document folders and hint persistence', () => { // Utility to get the draggable tile for a given filename (by link). const rowFor = (page: Page, fileName: string) => { - const link = page.getByRole('link', { name: new RegExp(fileName, 'i') }).first(); + const link = page.getByRole('link', { name: new RegExp(escapeRegExp(fileName), 'i') }).first(); // The drag source is the tile container ancestor, marked with data-doc-tile. return link.locator('xpath=ancestor::*[@data-doc-tile][1]'); }; diff --git a/tests/helpers.ts b/tests/helpers.ts index 617227a..9d280f7 100644 --- a/tests/helpers.ts +++ b/tests/helpers.ts @@ -4,7 +4,7 @@ import { createHash } from 'crypto'; const DIR = './tests/files/'; // Small util to safely use filenames inside regex patterns -function escapeRegExp(input: string) { +export function escapeRegExp(input: string) { return input.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); }