Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(middleware-code-coverage): incomplete string escaping or encoding #194

Merged
merged 3 commits into from
Nov 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions packages/middleware-code-coverage/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,14 @@ async function excludePatterns(resources) {
if (sPattern.endsWith("**")) {
sPattern = sPattern + "/*";
}

// quote characters that might have been used but have a special meaning in regular expressions
// TODO: clarify is this regex is valid
// eslint-disable-next-line no-useless-escape
sPattern = sPattern.replace(/[\[\]\(\)\.]/g, "\\$&");
sPattern = sPattern
.replaceAll("[", "\\[")
.replaceAll("]", "\\]")
.replaceAll("(", "\\(")
.replaceAll(")", "\\)")
.replaceAll(".", "\\.");
// our wildcard '*' means 'any name segment, but not multiple components'
sPattern = sPattern.replace(/\*/g, "[^/]*");
// our wildcard '**/' means 'any number of name segments'
Expand Down
Loading