-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Escape release string in injection snippet (#585)
- Loading branch information
Showing
4 changed files
with
51 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
packages/integration-tests/fixtures/release-value-with-quotes/input/bundle.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Simply output the metadata to the console so it can be checked in a test | ||
// eslint-disable-next-line no-console, @typescript-eslint/no-unsafe-member-access | ||
console.log(JSON.stringify(global.SENTRY_RELEASE.id)); |
32 changes: 32 additions & 0 deletions
32
...es/integration-tests/fixtures/release-value-with-quotes/release-value-with-quotes.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* eslint-disable jest/no-standalone-expect */ | ||
/* eslint-disable jest/expect-expect */ | ||
import { execSync } from "child_process"; | ||
import path from "path"; | ||
import { testIfNodeMajorVersionIsLessThan18 } from "../../utils/testIf"; | ||
|
||
function checkBundle(bundlePath: string): void { | ||
const output = execSync(`node ${bundlePath}`, { encoding: "utf-8" }); | ||
expect(output.trimEnd()).toBe('"i am a dangerous release value because I contain a \\""'); | ||
} | ||
|
||
describe("Properly escapes release values before injecting", () => { | ||
testIfNodeMajorVersionIsLessThan18("webpack 4 bundle", () => { | ||
checkBundle(path.join(__dirname, "out", "webpack4", "bundle.js")); | ||
}); | ||
|
||
test("webpack 5 bundle", () => { | ||
checkBundle(path.join(__dirname, "out", "webpack5", "bundle.js")); | ||
}); | ||
|
||
test("esbuild bundle", () => { | ||
checkBundle(path.join(__dirname, "out", "esbuild", "bundle.js")); | ||
}); | ||
|
||
test("rollup bundle", () => { | ||
checkBundle(path.join(__dirname, "out", "rollup", "bundle.js")); | ||
}); | ||
|
||
test("vite bundle", () => { | ||
checkBundle(path.join(__dirname, "out", "vite", "bundle.js")); | ||
}); | ||
}); |
15 changes: 15 additions & 0 deletions
15
packages/integration-tests/fixtures/release-value-with-quotes/setup.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import * as path from "path"; | ||
import { createCjsBundles } from "../../utils/create-cjs-bundles"; | ||
|
||
const outputDir = path.resolve(__dirname, "out"); | ||
|
||
createCjsBundles( | ||
{ | ||
bundle: path.resolve(__dirname, "input", "bundle.js"), | ||
}, | ||
outputDir, | ||
{ | ||
release: { name: 'i am a dangerous release value because I contain a "' }, | ||
}, | ||
["webpack4", "webpack5", "esbuild", "rollup", "vite"] | ||
); |