Skip to content

Commit 6c02b73

Browse files
authored
fix: normalizePath does not handle all base64 characters (#110)
Update normalizePath function regex to handle all the base64 characters and dashes.
1 parent bdc0533 commit 6c02b73

File tree

5 files changed

+34
-16
lines changed

5 files changed

+34
-16
lines changed

.changeset/warm-feet-cry.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@codecov/bundler-plugin-core": patch
3+
"@codecov/webpack-plugin": patch
4+
"@codecov/rollup-plugin": patch
5+
"@codecov/vite-plugin": patch
6+
---
7+
8+
Fix normalizePath not handling all base64 characters and dashes

integration-tests/fixtures/generate-bundle-stats/rollup/__snapshots__/rollup-plugin.test.ts.snap

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ exports[`Generating rollup stats 4 {"format":"cjs","expected":"cjs"} matches the
765765
"assets": [
766766
{
767767
"name": "main-MVbZZknk.js",
768-
"normalized": "main-MVbZZknk.js",
768+
"normalized": "main-*.js",
769769
"size": 560886,
770770
},
771771
],
@@ -841,7 +841,7 @@ exports[`Generating rollup stats 4 {"format":"es","expected":"esm"} matches the
841841
"assets": [
842842
{
843843
"name": "main-v-vWaFyT.js",
844-
"normalized": "main-v-vWaFyT.js",
844+
"normalized": "main-*.js",
845845
"size": 560871,
846846
},
847847
],
@@ -917,7 +917,7 @@ exports[`Generating rollup stats 4 {"format":"esm","expected":"esm"} matches the
917917
"assets": [
918918
{
919919
"name": "main-v-vWaFyT.js",
920-
"normalized": "main-v-vWaFyT.js",
920+
"normalized": "main-*.js",
921921
"size": 560871,
922922
},
923923
],
@@ -993,7 +993,7 @@ exports[`Generating rollup stats 4 {"format":"module","expected":"esm"} matches
993993
"assets": [
994994
{
995995
"name": "main-v-vWaFyT.js",
996-
"normalized": "main-v-vWaFyT.js",
996+
"normalized": "main-*.js",
997997
"size": 560871,
998998
},
999999
],
@@ -1069,7 +1069,7 @@ exports[`Generating rollup stats 4 {"format":"iife","expected":"iife"} matches t
10691069
"assets": [
10701070
{
10711071
"name": "main-ChwnvxRF.js",
1072-
"normalized": "main-ChwnvxRF.js",
1072+
"normalized": "main-*.js",
10731073
"size": 577066,
10741074
},
10751075
],
@@ -1145,7 +1145,7 @@ exports[`Generating rollup stats 4 {"format":"umd","expected":"umd"} matches the
11451145
"assets": [
11461146
{
11471147
"name": "main-ymXr0nql.js",
1148-
"normalized": "main-ymXr0nql.js",
1148+
"normalized": "main-*.js",
11491149
"size": 577165,
11501150
},
11511151
],
@@ -1221,7 +1221,7 @@ exports[`Generating rollup stats 4 {"format":"system","expected":"system"} match
12211221
"assets": [
12221222
{
12231223
"name": "main-VyFuBFOR.js",
1224-
"normalized": "main-VyFuBFOR.js",
1224+
"normalized": "main-*.js",
12251225
"size": 609444,
12261226
},
12271227
],
@@ -1297,7 +1297,7 @@ exports[`Generating rollup stats 4 {"format":"systemjs","expected":"system"} mat
12971297
"assets": [
12981298
{
12991299
"name": "main-VyFuBFOR.js",
1300-
"normalized": "main-VyFuBFOR.js",
1300+
"normalized": "main-*.js",
13011301
"size": 609444,
13021302
},
13031303
],

integration-tests/fixtures/generate-bundle-stats/vite/__snapshots__/vite-plugin.test.ts.snap

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,7 @@ exports[`Generating vite stats v5 {"format":"amd","expected":"amd"} matches the
815815
"assets": [
816816
{
817817
"name": "assets/index-neb5ATfh.js",
818-
"normalized": "assets/index-neb5ATfh.js",
818+
"normalized": "assets/index-*.js",
819819
"size": 72360,
820820
},
821821
],
@@ -905,7 +905,7 @@ exports[`Generating vite stats v5 {"format":"cjs","expected":"cjs"} matches the
905905
"assets": [
906906
{
907907
"name": "assets/index-9JQbcWYj.js",
908-
"normalized": "assets/index-9JQbcWYj.js",
908+
"normalized": "assets/index-*.js",
909909
"size": 72342,
910910
},
911911
],
@@ -995,7 +995,7 @@ exports[`Generating vite stats v5 {"format":"es","expected":"esm"} matches the s
995995
"assets": [
996996
{
997997
"name": "assets/index-snsAD2Cg.js",
998-
"normalized": "assets/index-snsAD2Cg.js",
998+
"normalized": "assets/index-*.js",
999999
"size": 73071,
10001000
},
10011001
],
@@ -1085,7 +1085,7 @@ exports[`Generating vite stats v5 {"format":"esm","expected":"esm"} matches the
10851085
"assets": [
10861086
{
10871087
"name": "assets/index-snsAD2Cg.js",
1088-
"normalized": "assets/index-snsAD2Cg.js",
1088+
"normalized": "assets/index-*.js",
10891089
"size": 73071,
10901090
},
10911091
],
@@ -1175,7 +1175,7 @@ exports[`Generating vite stats v5 {"format":"module","expected":"esm"} matches t
11751175
"assets": [
11761176
{
11771177
"name": "assets/index-snsAD2Cg.js",
1178-
"normalized": "assets/index-snsAD2Cg.js",
1178+
"normalized": "assets/index-*.js",
11791179
"size": 73071,
11801180
},
11811181
],
@@ -1265,7 +1265,7 @@ exports[`Generating vite stats v5 {"format":"iife","expected":"iife"} matches th
12651265
"assets": [
12661266
{
12671267
"name": "assets/index-HczW45b9.js",
1268-
"normalized": "assets/index-HczW45b9.js",
1268+
"normalized": "assets/index-*.js",
12691269
"size": 72356,
12701270
},
12711271
],
@@ -1355,7 +1355,7 @@ exports[`Generating vite stats v5 {"format":"umd","expected":"umd"} matches the
13551355
"assets": [
13561356
{
13571357
"name": "assets/index-5tDKlLKo.js",
1358-
"normalized": "assets/index-5tDKlLKo.js",
1358+
"normalized": "assets/index-*.js",
13591359
"size": 72423,
13601360
},
13611361
],

packages/bundler-plugin-core/src/utils/__tests__/normalizePath.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ const tests: Test[] = [
1818
},
1919
expected: "test.*.chunk.js",
2020
},
21+
{
22+
name: "can handle all base64 characters and '-'",
23+
input: {
24+
path: "test.ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=-.js",
25+
format: "[name].[hash].js",
26+
},
27+
expected: "test.*.js",
28+
},
2129
{
2230
name: "should replace '[contenthash]' with '*'",
2331
input: {

packages/bundler-plugin-core/src/utils/normalizePath.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ export const normalizePath = (path: string, format: string): string => {
3939
const endingRegex = `(?<endingDelimiter>${escapeRegex(endingDelimiter)})`;
4040

4141
// create a regex that will match the hash
42-
const regexString = `(${leadingRegex}(?<hash>[0-9a-f]+)${endingRegex})`;
42+
// potential values gathered from: https://en.wikipedia.org/wiki/Base64
43+
// added in `\-` to account for the `-` character which seems to be used by Rollup through testing
44+
const regexString = `(${leadingRegex}(?<hash>[0-9a-zA-Z\/+=-]+)${endingRegex})`;
4345
const HASH_REPLACE_REGEX = new RegExp(regexString, "i");
4446

4547
// replace the hash with a wildcard and the delimiters

0 commit comments

Comments
 (0)