playwright-smart-test 1.0.6 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli/index.js
CHANGED
|
@@ -15,7 +15,7 @@ const program = new Command();
|
|
|
15
15
|
program
|
|
16
16
|
.name('playwright-smart-test')
|
|
17
17
|
.description('AI-Powered Smart Regression Test Selection Agent for Playwright')
|
|
18
|
-
.version('1.0.
|
|
18
|
+
.version('1.0.7');
|
|
19
19
|
async function executeAnalysis(options) {
|
|
20
20
|
const cwd = options.cwd ? path.resolve(options.cwd) : process.cwd();
|
|
21
21
|
const config = loadConfig(cwd, options.config);
|
|
@@ -18,7 +18,8 @@ export declare class GitDiffAnalyzer {
|
|
|
18
18
|
deletions: number;
|
|
19
19
|
}>;
|
|
20
20
|
/**
|
|
21
|
-
* Split unified diff output into per-file patches
|
|
21
|
+
* Split unified diff output into per-file patches.
|
|
22
|
+
* Uses safe deterministic string operations to prevent polynomial regular expression DoS (CWE-1333).
|
|
22
23
|
*/
|
|
23
24
|
splitPatches(rawDiff: string): Map<string, string>;
|
|
24
25
|
}
|
|
@@ -84,7 +84,8 @@ export class GitDiffAnalyzer {
|
|
|
84
84
|
return map;
|
|
85
85
|
}
|
|
86
86
|
/**
|
|
87
|
-
* Split unified diff output into per-file patches
|
|
87
|
+
* Split unified diff output into per-file patches.
|
|
88
|
+
* Uses safe deterministic string operations to prevent polynomial regular expression DoS (CWE-1333).
|
|
88
89
|
*/
|
|
89
90
|
splitPatches(rawDiff) {
|
|
90
91
|
const filePatches = new Map();
|
|
@@ -92,12 +93,30 @@ export class GitDiffAnalyzer {
|
|
|
92
93
|
return filePatches;
|
|
93
94
|
const diffSections = rawDiff.split(/(?=^diff --git )/m);
|
|
94
95
|
for (const section of diffSections) {
|
|
95
|
-
|
|
96
|
+
const trimmed = section.trim();
|
|
97
|
+
if (!trimmed)
|
|
98
|
+
continue;
|
|
99
|
+
// Extract the header line without regex backtracking
|
|
100
|
+
const newlineIndex = trimmed.indexOf('\n');
|
|
101
|
+
const headerLine = (newlineIndex === -1 ? trimmed : trimmed.slice(0, newlineIndex)).trim();
|
|
102
|
+
if (!headerLine.startsWith('diff --git '))
|
|
96
103
|
continue;
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
104
|
+
const line = headerLine.slice(11); // Remove 'diff --git '
|
|
105
|
+
const sepIndex = line.lastIndexOf(' b/');
|
|
106
|
+
if (sepIndex !== -1) {
|
|
107
|
+
let filePath = line.slice(sepIndex + 3).trim();
|
|
108
|
+
// Fallback for deleted files where b/ is /dev/null
|
|
109
|
+
if (filePath === '/dev/null' || filePath === 'dev/null') {
|
|
110
|
+
const aPath = line.slice(0, sepIndex).trim();
|
|
111
|
+
filePath = aPath.startsWith('a/') ? aPath.slice(2) : aPath;
|
|
112
|
+
}
|
|
113
|
+
// Clean quotes if path was enclosed in quotes by git
|
|
114
|
+
if (filePath.startsWith('"') && filePath.endsWith('"')) {
|
|
115
|
+
filePath = filePath.slice(1, -1);
|
|
116
|
+
}
|
|
117
|
+
if (filePath) {
|
|
118
|
+
filePatches.set(filePath.replace(/\\/g, '/'), trimmed);
|
|
119
|
+
}
|
|
101
120
|
}
|
|
102
121
|
}
|
|
103
122
|
return filePatches;
|
|
@@ -13,6 +13,10 @@ export declare class TestSelector {
|
|
|
13
13
|
private findComponentRuleSpecs;
|
|
14
14
|
private findSmokeTests;
|
|
15
15
|
private normalizeAndFilterSpecs;
|
|
16
|
+
/**
|
|
17
|
+
* Safe glob matching preventing CodeQL js/incomplete-sanitization alerts (CWE-20, CWE-80, CWE-116).
|
|
18
|
+
* Backslashes are escaped first, followed by all regex metacharacters, then converting glob wildcards.
|
|
19
|
+
*/
|
|
16
20
|
private simpleGlobMatch;
|
|
17
21
|
private buildPlaywrightCommand;
|
|
18
22
|
}
|
|
@@ -278,20 +278,33 @@ export class TestSelector {
|
|
|
278
278
|
}
|
|
279
279
|
return selected;
|
|
280
280
|
}
|
|
281
|
+
/**
|
|
282
|
+
* Safe glob matching preventing CodeQL js/incomplete-sanitization alerts (CWE-20, CWE-80, CWE-116).
|
|
283
|
+
* Backslashes are escaped first, followed by all regex metacharacters, then converting glob wildcards.
|
|
284
|
+
*/
|
|
281
285
|
simpleGlobMatch(str, pattern) {
|
|
282
|
-
|
|
286
|
+
const normalizedStr = str.replace(/\\/g, '/');
|
|
287
|
+
let p = pattern.replace(/\\/g, '/');
|
|
288
|
+
let prefix = '';
|
|
289
|
+
let suffix = '';
|
|
283
290
|
if (p.startsWith('**/')) {
|
|
284
|
-
|
|
291
|
+
prefix = '(?:.+/)?';
|
|
292
|
+
p = p.slice(3);
|
|
285
293
|
}
|
|
286
294
|
if (p.endsWith('/**')) {
|
|
287
|
-
|
|
295
|
+
suffix = '(?:/.*)?';
|
|
296
|
+
p = p.slice(0, -3);
|
|
288
297
|
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
298
|
+
// CodeQL compliance:
|
|
299
|
+
// 1. Explicitly escape backslashes before other operations
|
|
300
|
+
// 2. Escape all special regex metacharacters: . + ? ^ $ { } ( ) | [ ]
|
|
301
|
+
// 3. Translate glob wildcards: ** -> .*, * -> [^/]*
|
|
302
|
+
const escaped = p
|
|
303
|
+
.replace(/\\/g, '\\\\')
|
|
304
|
+
.replace(/[.+?^${}()|[\]]/g, '\\$&')
|
|
305
|
+
.replace(/\*\*/g, '.*')
|
|
306
|
+
.replace(/\*/g, '[^/]*');
|
|
307
|
+
return new RegExp(`^${prefix}${escaped}${suffix}$`, 'i').test(normalizedStr);
|
|
295
308
|
}
|
|
296
309
|
buildPlaywrightCommand(selectedSpecs, isFull) {
|
|
297
310
|
if (isFull || selectedSpecs.length === 0) {
|