mirror of
https://github.com/maputnik/editor.git
synced 2025-12-05 22:00:00 +00:00
allow root relative paths (#1549)
## Launch Checklist <!-- Thanks for the PR! Feel free to add or remove items from the checklist. --> - [x] Briefly describe the changes in this PR. when launching maputnik with `--static /data` those files are available under e.g. `localhost:8000/static`. In this case, root relative urls are enough (e.g. requsting `/static/fonts`...). This does currently lead to a validation error: <img width="361" height="61" alt="grafik" src="https://github.com/user-attachments/assets/2be1d649-51c9-4e64-ac44-c0089b462be2" /> - [x] Include before/after visuals or gifs if this PR includes visual changes. after this change it works: <img width="338" height="68" alt="grafik" src="https://github.com/user-attachments/assets/27f23d1b-11f6-4efc-b508-2f51bf254953" /> - [x] Write tests for all new functionality. - [x] Add an entry to `CHANGELOG.md` under the `## main` section.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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", {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user