Skip to content
This repository has been archived by the owner on Mar 8, 2023. It is now read-only.

Commit

Permalink
UrlUtils: Support for data: URI scheme.
Browse files Browse the repository at this point in the history
In order to support `data:` scheme in `Theme`, we must recognize
`data:` as absolute uri (before this patch `data:` URIs were threated
as `relative path` and thus resolved vs `baseURL`.

Related-to: HARP-7206

Signed-off-by: Zbigniew Zagorski <ext-zbyszek.zagorski@here.com>
  • Loading branch information
Zbigniew Zagorski authored and zbigg committed Mar 20, 2020
1 parent d8eab9f commit 3cedac9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion @here/harp-utils/lib/UrlUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
*
* See [[baseUri]] for reference how base URL of `parentUri` is determined.
*
* Supports `http:`, `https:`, `file:`, `data:` schemes.
*
* Examples:
*
* // normal case, child is sibling
Expand Down Expand Up @@ -47,7 +49,7 @@ export function resolveReferenceUri(parentUri: string | undefined, childUri: str
}
}

const absoluteUrlWithOriginRe = new RegExp("^(?:[a-z]+:)?//", "i");
const absoluteUrlWithOriginRe = new RegExp("^(((?:[a-z]+:)?//)|(file:/)|(data:))", "i");

/**
* Returns base URL of given resource URL.
Expand Down
6 changes: 6 additions & 0 deletions @here/harp-utils/test/UrlUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ describe("UrlUtils", function() {
assert.equal(resolveReferenceUri("file://foo/", "bar.js"), "file://foo/bar.js");
assert.equal(resolveReferenceUri("file://foo/", "/bar.js"), "file:///bar.js");
});
it("handles data: scheme", function() {
assert.equal(
resolveReferenceUri("https://bar.com/foo/", "data:whatever"),
"data:whatever"
);
});
it("handles relative parent URL", function() {
assert.equal(
resolveReferenceUri("resources/day.json", "font.json"),
Expand Down

0 comments on commit 3cedac9

Please sign in to comment.