Skip to content

Commit

Permalink
fixed filter for encoded url
Browse files Browse the repository at this point in the history
  • Loading branch information
cenfun committed Dec 7, 2024
1 parent a63e168 commit c99a6bf
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

- 2.11.4
- fixed encoded source url issue
- fixed filter for encoded url

- 2.11.3
- fixed cli to support `merge` command
Expand Down
6 changes: 3 additions & 3 deletions lib/converter/untested.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const { pathToFileURL, fileURLToPath } = require('url');
const { normalizeSourcePath, getSourcePathReplacer } = require('../utils/source-path.js');

// const EC = require('eight-colors');
const { minimatch, convertSourceMap } = require('../packages/monocart-coverage-vendor.js');
const { convertSourceMap } = require('../packages/monocart-coverage-vendor.js');

// ========================================================================================================

Expand Down Expand Up @@ -37,7 +37,7 @@ const resolveAllFilter = (input) => {
input = obj;
} else {
return (filePath) => {
return minimatch(filePath, input);
return Util.betterMinimatch(filePath, input);
};
}
}
Expand All @@ -47,7 +47,7 @@ const resolveAllFilter = (input) => {
const patterns = Object.keys(input);
return (filePath) => {
for (const pattern of patterns) {
if (minimatch(filePath, pattern)) {
if (Util.betterMinimatch(filePath, pattern)) {
return input[pattern];
}
}
Expand Down
5 changes: 2 additions & 3 deletions lib/reports/console-details.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const CG = require('console-grid');
const EC = require('eight-colors');
const { minimatch } = require('../packages/monocart-coverage-vendor.js');
const { getGroupedRows } = require('../utils/snapshot.js');
const Util = require('../utils/util.js');

Expand Down Expand Up @@ -78,7 +77,7 @@ const getFileFilter = (input) => {
input = obj;
} else {
return (file) => {
return minimatch(file.sourcePath, input);
return Util.betterMinimatch(file.sourcePath, input);
};
}
}
Expand All @@ -89,7 +88,7 @@ const getFileFilter = (input) => {
return (file) => {
const sourcePath = file.sourcePath;
for (const pattern of patterns) {
if (minimatch(sourcePath, pattern)) {
if (Util.betterMinimatch(sourcePath, pattern)) {
return input[pattern];
}
}
Expand Down
36 changes: 32 additions & 4 deletions lib/utils/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,34 @@ const Util = {
};
},

betterMinimatch: (str, pattern) => {
str = `${str}`;
pattern = `${pattern}`;

// mini match
if (minimatch(str, pattern)) {
return true;
}

// includes
if (str.includes(pattern)) {
return true;
}

// try decode url
str = decodeURIComponent(str);

if (minimatch(str, pattern)) {
return true;
}

if (str.includes(pattern)) {
return true;
}

return false;
},

// eslint-disable-next-line complexity
getEntryFilter: (options) => {
// for entry.url
Expand All @@ -197,7 +225,7 @@ const Util = {
input = obj;
} else {
const handler = (entry) => {
return minimatch(entry.url, input);
return Util.betterMinimatch(entry.url, input);
};
options.entryFilterHandler = handler;
return handler;
Expand All @@ -210,7 +238,7 @@ const Util = {
const handler = (entry) => {
const url = entry.url;
for (const pattern of patterns) {
if (minimatch(url, pattern)) {
if (Util.betterMinimatch(url, pattern)) {
return input[pattern];
}
}
Expand Down Expand Up @@ -252,7 +280,7 @@ const Util = {
input = obj;
} else {
const handler = (sourcePath) => {
return minimatch(sourcePath, input);
return Util.betterMinimatch(sourcePath, input);
};
options.sourceFilterHandler = handler;
return handler;
Expand All @@ -264,7 +292,7 @@ const Util = {
const patterns = Object.keys(input);
const handler = (sourcePath) => {
for (const pattern of patterns) {
if (minimatch(sourcePath, pattern)) {
if (Util.betterMinimatch(sourcePath, pattern)) {
return input[pattern];
}
}
Expand Down

0 comments on commit c99a6bf

Please sign in to comment.