Skip to content

Commit

Permalink
Fix filename regex escaping (#270)
Browse files Browse the repository at this point in the history
  • Loading branch information
vinaypuppal authored Sep 29, 2023
1 parent c29a2aa commit c65003f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/coverage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,18 @@ export function parseCoverageReport(report: string, files: CommitsComparison): F
return {averageCover: avgCover, newCover, modifiedCover}
}

function escapeRegExp(value: string) {
return value.replace(/[.*+\-?^${}()|[\]\\]/g, '\\$&');
}

export function parseFilesCoverage(
report: string,
source: string,
files: string[] | undefined,
threshold: number
): Coverage[] | undefined {
const coverages = files?.map(file => {
const fileName = file.replace(`${source}/`, '').replace(/\//g, '\\/')
const fileName = escapeRegExp(file.replace(`${source}/`, ''))
const regex = new RegExp(`.*filename="${fileName}".*line-rate="(?<cover>[0-9]+[.]*[0-9]*)".*`)
const match = report.match(regex)
const cover = match?.groups ? parseFloat(match.groups['cover']) : -1
Expand Down

0 comments on commit c65003f

Please sign in to comment.