Skip to content

Commit

Permalink
fix: normalizePath does not handle all base64 characters (#110)
Browse files Browse the repository at this point in the history
Update normalizePath function regex to handle all the base64 characters and dashes.
  • Loading branch information
nicholas-codecov committed Mar 21, 2024
1 parent bdc0533 commit 6c02b73
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 16 deletions.
8 changes: 8 additions & 0 deletions .changeset/warm-feet-cry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@codecov/bundler-plugin-core": patch
"@codecov/webpack-plugin": patch
"@codecov/rollup-plugin": patch
"@codecov/vite-plugin": patch
---

Fix normalizePath not handling all base64 characters and dashes
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ exports[`Generating rollup stats 4 {"format":"cjs","expected":"cjs"} matches the
"assets": [
{
"name": "main-MVbZZknk.js",
"normalized": "main-MVbZZknk.js",
"normalized": "main-*.js",
"size": 560886,
},
],
Expand Down Expand Up @@ -841,7 +841,7 @@ exports[`Generating rollup stats 4 {"format":"es","expected":"esm"} matches the
"assets": [
{
"name": "main-v-vWaFyT.js",
"normalized": "main-v-vWaFyT.js",
"normalized": "main-*.js",
"size": 560871,
},
],
Expand Down Expand Up @@ -917,7 +917,7 @@ exports[`Generating rollup stats 4 {"format":"esm","expected":"esm"} matches the
"assets": [
{
"name": "main-v-vWaFyT.js",
"normalized": "main-v-vWaFyT.js",
"normalized": "main-*.js",
"size": 560871,
},
],
Expand Down Expand Up @@ -993,7 +993,7 @@ exports[`Generating rollup stats 4 {"format":"module","expected":"esm"} matches
"assets": [
{
"name": "main-v-vWaFyT.js",
"normalized": "main-v-vWaFyT.js",
"normalized": "main-*.js",
"size": 560871,
},
],
Expand Down Expand Up @@ -1069,7 +1069,7 @@ exports[`Generating rollup stats 4 {"format":"iife","expected":"iife"} matches t
"assets": [
{
"name": "main-ChwnvxRF.js",
"normalized": "main-ChwnvxRF.js",
"normalized": "main-*.js",
"size": 577066,
},
],
Expand Down Expand Up @@ -1145,7 +1145,7 @@ exports[`Generating rollup stats 4 {"format":"umd","expected":"umd"} matches the
"assets": [
{
"name": "main-ymXr0nql.js",
"normalized": "main-ymXr0nql.js",
"normalized": "main-*.js",
"size": 577165,
},
],
Expand Down Expand Up @@ -1221,7 +1221,7 @@ exports[`Generating rollup stats 4 {"format":"system","expected":"system"} match
"assets": [
{
"name": "main-VyFuBFOR.js",
"normalized": "main-VyFuBFOR.js",
"normalized": "main-*.js",
"size": 609444,
},
],
Expand Down Expand Up @@ -1297,7 +1297,7 @@ exports[`Generating rollup stats 4 {"format":"systemjs","expected":"system"} mat
"assets": [
{
"name": "main-VyFuBFOR.js",
"normalized": "main-VyFuBFOR.js",
"normalized": "main-*.js",
"size": 609444,
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@ exports[`Generating vite stats v5 {"format":"amd","expected":"amd"} matches the
"assets": [
{
"name": "assets/index-neb5ATfh.js",
"normalized": "assets/index-neb5ATfh.js",
"normalized": "assets/index-*.js",
"size": 72360,
},
],
Expand Down Expand Up @@ -905,7 +905,7 @@ exports[`Generating vite stats v5 {"format":"cjs","expected":"cjs"} matches the
"assets": [
{
"name": "assets/index-9JQbcWYj.js",
"normalized": "assets/index-9JQbcWYj.js",
"normalized": "assets/index-*.js",
"size": 72342,
},
],
Expand Down Expand Up @@ -995,7 +995,7 @@ exports[`Generating vite stats v5 {"format":"es","expected":"esm"} matches the s
"assets": [
{
"name": "assets/index-snsAD2Cg.js",
"normalized": "assets/index-snsAD2Cg.js",
"normalized": "assets/index-*.js",
"size": 73071,
},
],
Expand Down Expand Up @@ -1085,7 +1085,7 @@ exports[`Generating vite stats v5 {"format":"esm","expected":"esm"} matches the
"assets": [
{
"name": "assets/index-snsAD2Cg.js",
"normalized": "assets/index-snsAD2Cg.js",
"normalized": "assets/index-*.js",
"size": 73071,
},
],
Expand Down Expand Up @@ -1175,7 +1175,7 @@ exports[`Generating vite stats v5 {"format":"module","expected":"esm"} matches t
"assets": [
{
"name": "assets/index-snsAD2Cg.js",
"normalized": "assets/index-snsAD2Cg.js",
"normalized": "assets/index-*.js",
"size": 73071,
},
],
Expand Down Expand Up @@ -1265,7 +1265,7 @@ exports[`Generating vite stats v5 {"format":"iife","expected":"iife"} matches th
"assets": [
{
"name": "assets/index-HczW45b9.js",
"normalized": "assets/index-HczW45b9.js",
"normalized": "assets/index-*.js",
"size": 72356,
},
],
Expand Down Expand Up @@ -1355,7 +1355,7 @@ exports[`Generating vite stats v5 {"format":"umd","expected":"umd"} matches the
"assets": [
{
"name": "assets/index-5tDKlLKo.js",
"normalized": "assets/index-5tDKlLKo.js",
"normalized": "assets/index-*.js",
"size": 72423,
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ const tests: Test[] = [
},
expected: "test.*.chunk.js",
},
{
name: "can handle all base64 characters and '-'",
input: {
path: "test.ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=-.js",
format: "[name].[hash].js",
},
expected: "test.*.js",
},
{
name: "should replace '[contenthash]' with '*'",
input: {
Expand Down
4 changes: 3 additions & 1 deletion packages/bundler-plugin-core/src/utils/normalizePath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ export const normalizePath = (path: string, format: string): string => {
const endingRegex = `(?<endingDelimiter>${escapeRegex(endingDelimiter)})`;

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

// replace the hash with a wildcard and the delimiters
Expand Down

0 comments on commit 6c02b73

Please sign in to comment.