From d9df57dc5a9f91c2fa60ec96d5f14d961665a56d Mon Sep 17 00:00:00 2001 From: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com> Date: Sat, 14 Nov 2026 19:53:35 -0300 Subject: [PATCH] test(db): escape every metacharacter in the gate test's string builders CodeQL flagged two js/incomplete-sanitization alerts in check-migration-numbering-base-diff.test.ts. One test built a RegExp from a migration file name by escaping only the dot. Another built JS string literals from a fixture by escaping only the quotes, never the backslash. Today's inputs have neither metacharacters nor backslashes, so the tests behaved the same, but a future name or fixture could have broken them silently. The RegExp builder now escapes every metacharacter, and both literal builders escape backslashes before quotes. The suite still passes 58/58. --- tests/unit/check-migration-numbering-base-diff.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/unit/check-migration-numbering-base-diff.test.ts b/tests/unit/check-migration-numbering-base-diff.test.ts index 83dc76ddb2b..93b49480430 100644 --- a/tests/unit/check-migration-numbering-base-diff.test.ts +++ b/tests/unit/check-migration-numbering-base-diff.test.ts @@ -482,7 +482,7 @@ function assertStrictRemovalMessage(stderr: string, name: string) { assert.match( stderr, new RegExp( - `${name.replace(/\./g, "\\.")}: migration já mesclada não pode ser apagada nem renomeada` + `${name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}: migration já mesclada não pode ser apagada nem renomeada` ) ); assert.match(stderr, /homologação, Docker :next, VPS, sync do Enterprise/); @@ -726,8 +726,8 @@ test("parser: declarations inside string literals are ignored; zero or two real const real = "export const RENAMED_MIGRATION_COMPATIBILITY = [];"; for (const decoy of [ `const NOTE = \`${fake}\`;`, - `const NOTE = '${fake.replace(/"/g, "\\'")}';`, - `const NOTE = "${fake.replace(/"/g, '\\"')}";`, + `const NOTE = '${fake.replace(/\\/g, "\\\\").replace(/"/g, "\\'")}';`, + `const NOTE = "${fake.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}";`, ]) { assert.deepEqual(lib.parseRenamedMigrationCompatibility(`${decoy}\n${real}\n`), [], decoy); }