Skip to content

Commit 0ded887

Browse files
committed
Use socket-registry escapeRegExp helper in get-type-coverage script
Replace manual regex pattern with escapeRegExp helper for safer regex construction when matching percentage symbols.
1 parent c3111bc commit 0ded887

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

scripts/utils/get-type-coverage.mjs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import constants from '@socketsecurity/registry/lib/constants'
2+
import { escapeRegExp } from '@socketsecurity/registry/lib/regexps'
23
import { spawn } from '@socketsecurity/registry/lib/spawn'
34

45
/**
@@ -22,12 +23,15 @@ export async function getTypeCoverage() {
2223
// Parse the output to find the line containing the percentage.
2324
const output = result.stdout || ''
2425
const lines = output.split('\n')
26+
const percentSymbol = escapeRegExp('%')
2527
const percentageLine = lines.find(line => line.includes('%'))
2628

2729
// Extract the percentage value from the line using regex.
2830
if (percentageLine) {
2931
// Matches patterns like "95.12%" or "100%" and extracts the numeric part.
30-
const match = percentageLine.match(/(\d+(?:\.\d+)?)%/)
32+
const match = percentageLine.match(
33+
new RegExp(`(\\d+(?:\\.\\d+)?)${percentSymbol}`),
34+
)
3135
if (match) {
3236
return parseFloat(match[1])
3337
}

0 commit comments

Comments
 (0)