diff --git a/CHANGELOG.md b/CHANGELOG.md index 69c3051c..1b24d650 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ - Upgraded codemirror from version 5 to version 6 - Add code editor to allow editing the entire style - Add support for sprite object in setting modal +- Allow root-relative urls in the stylefile - _...Add new stuff here..._ ### 🐞 Bug fixes diff --git a/src/libs/urlopen.test.ts b/src/libs/urlopen.test.ts index 3dc4c5db..6ee7a310 100644 --- a/src/libs/urlopen.test.ts +++ b/src/libs/urlopen.test.ts @@ -36,6 +36,12 @@ describe("validate", () => { }); }); + describe("when URL is root relative", () => { + it("should return ErrorType.None", () => { + expect(validate("/static/style.json")).toBe(ErrorType.None); + }); + }); + describe("when window.location.protocol is https:", () => { beforeEach(() => { Object.defineProperty(window.location, "protocol", { diff --git a/src/libs/urlopen.ts b/src/libs/urlopen.ts index 86c27a8b..e7aa5bec 100644 --- a/src/libs/urlopen.ts +++ b/src/libs/urlopen.ts @@ -45,8 +45,13 @@ function getProtocolSafe(url: string): { protocol?: string, isLocal?: boolean } } }; -export function validate(url: string): ErrorType { - if (url === "") { +export function validate(url?: string): ErrorType { + if (!url) { + return ErrorType.None; + } + + // allow root-relative URLs ("/static/style.json") but do not allow protocol-relative URLs ("//example.com") + if (url.startsWith("/") && !url.startsWith("//")) { return ErrorType.None; }