Skip to content

Commit 5b89c26

Browse files
authored
fix(chrome-extension): keep background.mjs a text file (#1969)
A stray NUL byte in the candidate key's separator made git classify background.mjs as binary, so it shipped in #1967 with no readable diff. The review bot said as much, having to anchor a comment about that file onto an unrelated test line because a binary diff accepts none. The separator is now written as an escape, which is the same character without the file-level consequence. Also scope the tile-template brace restoration in serviceUrlParameter to the kinds that use `{z}/{x}/{y}`. Rewriting `%7B`/`%7D` for every kind would turn a brace that a WMS or ArcGIS URL legitimately encodes, in a signed parameter or token, into a literal the server never sent.
1 parent 6299590 commit 5b89c26

3 files changed

Lines changed: 28 additions & 1 deletion

File tree

apps/geolibre-desktop/src/lib/data-url.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,21 @@ export interface ServiceUrlParameter {
2424
styleUrl: string | null;
2525
}
2626

27+
/** The service kinds addressed by a `{z}/{x}/{y}` tile template. */
28+
const TILE_TEMPLATE_KINDS = new Set(["xyz", "wmts", "ogc-vector-tiles"]);
29+
2730
export function serviceUrlParameter(search: string): ServiceUrlParameter | null {
2831
const params = new URLSearchParams(search);
2932
const kind = params.get("add");
3033
const rawUrl = params.get("serviceUrl");
31-
const url = httpUrl(rawUrl)?.replace(/%7B/gi, "{").replace(/%7D/gi, "}") ?? null;
34+
// Only a tile template carries braces to restore. Rewriting them for every
35+
// kind would corrupt a WMS or ArcGIS URL whose query legitimately encodes a
36+
// brace, in a signed parameter or token, into one the server never sent.
37+
const parsed = httpUrl(rawUrl);
38+
const url =
39+
parsed && kind && TILE_TEMPLATE_KINDS.has(kind)
40+
? parsed.replace(/%7B/gi, "{").replace(/%7D/gi, "}")
41+
: parsed;
3242
if (!kind || !SERVICE_KINDS.has(kind) || !url) return null;
3343
return {
3444
kind,
5 Bytes
Binary file not shown.

tests/data-url.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,23 @@ describe("serviceUrlParameter", () => {
5454
);
5555
});
5656

57+
it("restores tile-template braces only for the kinds that use them", () => {
58+
// A WMS token that legitimately encodes a brace must reach the server as it
59+
// was signed, not as a literal brace.
60+
assert.equal(
61+
serviceUrlParameter(
62+
"?add=wms&serviceUrl=https%3A%2F%2Fmaps.example.com%2Fwms%3Ftoken%3Da%257Bb%257Dc",
63+
)?.url,
64+
"https://maps.example.com/wms?token=a%7Bb%7Dc",
65+
);
66+
assert.equal(
67+
serviceUrlParameter(
68+
"?add=wmts&serviceUrl=https%3A%2F%2Ftiles.example.com%2Fwmts%3FTileMatrix%3D%257Bz%257D",
69+
)?.url,
70+
"https://tiles.example.com/wmts?TileMatrix={z}",
71+
);
72+
});
73+
5774
it("ignores a blank layer and a non-web style link", () => {
5875
assert.deepEqual(
5976
serviceUrlParameter(

0 commit comments

Comments
 (0)