🎥 Make videos programmatically with React
encoded
Jonny Burgere8f956547da7
diff --git a/packages/core/src/static-file.ts b/packages/core/src/static-file.tsindex 9e782fc7fd..6507582e8f 100644--- a/packages/core/src/static-file.ts+++ b/packages/core/src/static-file.ts@@ -1,4 +1,4 @@-const decodedChars = {+const problematicCharacters = {'%3A': ':','%2F': '/','%3F': '?',@@ -18,9 +18,9 @@ const decodedChars = {'%3B': ';',};-export type HexCode = keyof typeof decodedChars;+type HexCode = keyof typeof problematicCharacters;-export type HexInfo =+type HexInfo =| {containsHex: false;}@@ -41,8 +41,8 @@ const warnOnce = (message: string) => {export const includesHexOfUnsafeChar = (path: string): HexInfo => {for (const key of Object.keys(- decodedChars- ) as (keyof typeof decodedChars)[]) {+ problematicCharacters+ ) as (keyof typeof problematicCharacters)[]) {if (path.includes(key)) {return {containsHex: true, hexCode: key as HexCode};}@@ -53,7 +53,7 @@ export const includesHexOfUnsafeChar = (path: string): HexInfo => {const trimLeadingSlash = (path: string): string => {if (path.startsWith('/')) {- return trimLeadingSlash(path.substr(1));+ return trimLeadingSlash(path.substring(1));}return path;@@ -106,15 +106,15 @@ export const staticFile = (path: string) => {);}- const encodedURI = encodeURIComponent(path);- const preparsed = inner(encodedURI);- const includesHex = includesHexOfUnsafeChar(preparsed);+ const includesHex = includesHexOfUnsafeChar(path);if (includesHex.containsHex) {warnOnce(`WARNING: You seem to pass an already encoded path (path contains ${includesHex.hexCode}). The encoding gets automatically handled by staticFile() `);}+ const preparsed = inner(encodeURIComponent(path));+if (!preparsed.startsWith('/')) {return `/${preparsed}`;}diff --git a/packages/docs/docs/staticfile.md b/packages/docs/docs/staticfile.mdindex 16311b9024..e75ed3e0cb 100644--- a/packages/docs/docs/staticfile.md+++ b/packages/docs/docs/staticfile.md@@ -76,8 +76,6 @@ Before `v4.0`, `staticFile()` did not handle URI-unsafe characters contained in### Example-Before `v4`-```tsx title="Before v4"staticFile("/my-image#portrait.png"); //output: "/my-image#portrait.png"```@@ -85,9 +83,7 @@ staticFile("/my-image#portrait.png"); //output: "/my-image#portrait.png"If this URL is passed to a component accepting an URL, the part after `#` will be left out, leadingto an error because the file can't be found.-Since `v4.0.0`:--```tsx title="After v4"+```tsx title="Since v4.0.0"const url = staticFile("/my-image#portrait.png"); // "/my-image%23portrait.png"```