🎥 Make videos programmatically with React
throw error when nested staticFile is detected
Patric Salvisberg01df8ff3d117
diff --git a/packages/core/src/static-file.ts b/packages/core/src/static-file.tsindex 98ebbeba64..671fd6eb3c 100644--- a/packages/core/src/static-file.ts+++ b/packages/core/src/static-file.ts@@ -61,6 +61,10 @@ const trimLeadingSlash = (path: string): string => {const inner = (path: string): string => {if (typeof window !== 'undefined' && window.remotion_staticBase) {+ if (path.includes(window.remotion_staticBase)) {+ throw new Error("You can't nest staticFile() inside of staticFile()");+ }+return `${window.remotion_staticBase}/${trimLeadingSlash(path)}`;}diff --git a/packages/core/src/test/static-file-errors.test.ts b/packages/core/src/test/static-file-errors.test.tsnew file mode 100644index 0000000000..28801f0fba--- /dev/null+++ b/packages/core/src/test/static-file-errors.test.ts@@ -0,0 +1,22 @@+import {expect, test} from 'vitest';+import {staticFile} from '../static-file.js';++test('duplicate staticFile() should throw a warning', () => {+ global.window = {+ remotion_staticBase: '/static-abcdef',+ };+ expect(() => staticFile(staticFile('file.mp3'))).toThrow(+ "You can't nest staticFile() inside of staticFile()"+ );+});++test('"https//" in staticFile() should throw an error', () => {+ expect(() => staticFile(staticFile('https://'))).toThrow(+ 'staticFile() does not support remote URLs - got "https://". Instead, pass the URL without wrapping it in staticFile(). See: https://remotion.dev/docs/staticfile-remote-urls'+ );+});++test('Single use of staticFile should not thrown an error', () => {+ const staticBase = window.remotion_staticBase;+ expect(staticFile('file.mp3')).toBe(staticBase + '/file.mp3');+});