Skip to content

🎥 Make videos programmatically with React

docs

Patric Salvisberge8884e4ecfa1
diff --git a/packages/core/src/static-file.ts b/packages/core/src/static-file.ts
index de1e226f0c..3eca1626eb 100644
--- a/packages/core/src/static-file.ts
+++ b/packages/core/src/static-file.ts
@@ -61,7 +61,6 @@ export const includesHexOfUnsafeChar = (path: string): HexInfo => {
decodedChars
) as (keyof typeof decodedChars)[]) {
if (path.includes(key)) {
- console.log(`Path contains ${decodedChars[key]}`);
return {containsHex: true, hexCode: key as HexCode};
}
}
diff --git a/packages/docs/docs/4-0-migration.md b/packages/docs/docs/4-0-migration.md
index ddc52fb1e9..3014fa5dc2 100644
--- a/packages/docs/docs/4-0-migration.md
+++ b/packages/docs/docs/4-0-migration.md
@@ -169,3 +169,9 @@ If this happens now and the error is not handled, the render will be aborted and
## `crf` is not allowed for GIFs anymore
Previously you were able to set a value for `crf` when rendering a GIF. This was a mistake and GIF does not support them.
+
+## `staticFile()` URI-unsafe characters handling
+
+Up to now, [`staticFile()`](/docs/staticfile) did not handle URI-unsafe characters contained in the provided path. This could in some specific cases lead to problems, which forced users to encode paths containing unsafe characters by themselves.
+
+Now, `staticFile()` checks for aforementioned characters and encodes them if contained in the path. If you encoded the path by yourself until now, make sure to drop your encoding before passing the path into `staticFile()` to avoid double encoding.
diff --git a/packages/docs/docs/staticfile.md b/packages/docs/docs/staticfile.md
index 59b294167c..730620fd36 100644
--- a/packages/docs/docs/staticfile.md
+++ b/packages/docs/docs/staticfile.md
@@ -67,6 +67,35 @@ If you are a Create React App or Next.JS user, you might be used to just to be a
Use the `getStaticFiles()` API to get a list of available options.
+## Handling URI-unsafe characters <AvailableFrom v="4.0"/>
+
+Before `v4.0`, `staticFile()` did not handle URI-unsafe characters contained in the provided path. This could lead to problems in some cases, which forced users to encode paths containing unsafe characters by themselves.
+
+Since `v4.0`, `staticFile()` checks for URI-unsave characters and encodes them into their hexadeciaml code. If you encoded the path by yourself until now, make sure to drop your encoding before passing the path into `staticFile()` to avoid double encoding.
+
+### Example
+
+Before `v4`
+
+```tsx
+const path = "/my-image#portrait.png";
+const url = staticFile(path);
+console.log(url); //output: "/my-image#portrait.png"
+```
+
+If this URL is passed to a component accepting an URL, the part after the # will simply be left away, leading
+to an error because the file can't be found.
+
+Since `v4`
+
+```tsx
+const path = "/my-image#portrait.png";
+const url = staticFile(path);
+console.log(url); //output: "/my-image%23portrait.png"
+```
+
+The `#` will be encoded into hexadecimal code.
+
## See also
- [Source code for this function](https://github.com/remotion-dev/remotion/blob/main/packages/core/src/static-file.ts)