Skip to content

fix(chrome-extension): keep background.mjs a text file - #1969

Merged
giswqs merged 1 commit into
mainfrom
fix/chrome-extension-binary-and-braces
Aug 17, 2026
Merged

fix(chrome-extension): keep background.mjs a text file#1969
giswqs merged 1 commit into
mainfrom
fix/chrome-extension-binary-and-braces

Conversation

@giswqs

@giswqs giswqs commented Aug 17, 2026

Copy link
Copy Markdown
Member

Follow-up to #1967.

background.mjs shipped as a binary file

A stray NUL byte sat in the separator of the candidate key, where a plain
separator was meant:

return [service.url, service.layer ?? "", service.styleUrl ?? ""].join(/* NUL */);

One NUL in the first 8000 bytes is all it takes for git to classify a file as
binary, so background.mjs merged with no readable diff. That is not cosmetic:
the review bot had to anchor its comment about that file onto an unrelated line
in tests/chrome-extension.test.ts, because a binary diff accepts no line
comments. Written as the escape ``, it is the same separator with the file
staying text.

Scoped brace restoration

From a review thread on #1967: serviceUrlParameter restored %7B/%7D to
braces across the whole URL for every service kind, though only xyz, wmts
and ogc-vector-tiles use {z}/{x}/{y} templates. For the others that rewrite
could corrupt a URL whose query legitimately encodes a brace, in a signed
parameter or token, into one the origin server never sent. Restoration is now
limited to the three template kinds, with a test covering both directions.

Not addressed here

Two other observations from the last review round on #1967 are left open
deliberately:

  • MV3 worker eviction resets the in-memory maps. stylesByTab,
    lastWritten and the page scope live in module scope, so an evicted worker
    forgets a style it had already seen and a later tile can land without one. It
    degrades rather than breaks (the entry is still addable, the style field is
    just empty), and persisting that state is its own change.
  • The WMS VERSION the page negotiated is not carried over. A 1.3.0-only
    server could fail the first Add before the user hits Retrieve. Worth doing for
    the "no further typing" bar the README sets, as its own change.

Tests: 6285 pass. Verified the file reads as text again with file and
git diff.

Summary by CodeRabbit

  • Bug Fixes

    • Corrected service URL handling so tile-based map services properly recognize {z}, {x}, and {y} placeholders.
    • Preserved encoded braces in WMS URLs to prevent unintended URL changes.
  • Tests

    • Added coverage for tile-template and WMS URL behavior.

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.
Copilot AI lite review requested due to automatic review settings August 17, 2026 01:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: b49bc064-944d-4556-bb16-c6f0fc5979c6

📥 Commits

Reviewing files that changed from the base of the PR and between 6299590 and 0138fd8.

📒 Files selected for processing (3)
  • apps/geolibre-desktop/src/lib/data-url.ts
  • extensions/geolibre-chrome/background.mjs
  • tests/data-url.test.ts

Included review availability: Your plan includes up to 8 reviews per rolling hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

serviceUrlParameter now restores tile placeholders only for xyz, wmts, and ogc-vector-tiles services. Tests verify that WMS braces remain encoded and WMTS placeholders are restored.

Changes

Service URL decoding

Layer / File(s) Summary
Kind-specific brace restoration
apps/geolibre-desktop/src/lib/data-url.ts, tests/data-url.test.ts
Brace decoding is limited to tile-template service kinds. Tests cover encoded braces in WMS URLs and {z} restoration in WMTS URLs.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 0138f

The PR keeps the extension background file readable and limits URL brace restoration to supported template services; no actionable merge-blocking risk remains after normal checks and review.

Possibly related PRs

Poem

A rabbit checks each curly brace,
Tile paths restore their proper place.
WMS keeps tokens safely sealed,
WMTS shows the shape revealed.
Hop by hop, the URLs align.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the Chrome extension file-format fix stated in the PR objectives, although it does not mention the service URL changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/chrome-extension-binary-and-braces

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed: dependency version conflict. Check your lock file or package.json.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

Code review

Reviewed the two functional changes in this PR: the background.mjs binary→text fix (NUL byte → \u0000 escape in candidateKey) and the scoped brace-restoration fix in serviceUrlParameter (apps/geolibre-desktop/src/lib/data-url.ts).

Bugs: None found. The \u0000 escape in background.mjs produces the identical runtime NUL character as before, so candidateKey's dedup behavior is unchanged — this is a pure encoding fix, not a logic change. The scoped brace restoration in data-url.ts correctly limits %7B/%7D{/} rewriting to xyz, wmts, and ogc-vector-tiles (the only kinds that use {z}/{x}/{y} templates), leaving wms, wfs, ogc-features, and arcgis URLs untouched. Verified against the new test cases and against SERVICE_KINDS/TILE_TEMPLATE_KINDS definitions — the logic is internally consistent. (Confidence: high)

Security: None found. This actually improves an existing minor risk: previously a WMS/WFS/ArcGIS URL with a legitimately percent-encoded brace (e.g., in a signed token) could be silently corrupted into a literal brace before being sent to the origin server; now that rewriting is scoped away from those kinds. (Confidence: high)

Performance: No concerns — the change adds a single Set.has() lookup and a conditional string replace, negligible cost.

Quality: Clean, well-scoped change with a clear explanatory comment and matching test coverage for both directions (WMS token preserved, WMTS template restored). No readability or naming concerns.

CLAUDE.md: No applicable guidelines were violated; this is a small, self-contained bug fix consistent with the project's conventions (branch + PR, no direct main commits implied by this being a PR).

No inline comments posted — I didn't find anything rising to a reportable issue in this diff.

@github-actions

Copy link
Copy Markdown
Contributor

🔍 Cloudflare PR preview

Item Value
Site https://eed00e58.geolibre-preview.pages.dev
Demo app https://eed00e58.geolibre-preview.pages.dev/demo/
Commit 0138fd8

@github-actions

Copy link
Copy Markdown
Contributor

🔍 GitHub Pages PR preview

Item Value
Site https://opengeos.org/pages-preview/GeoLibre/pr-1969/
Demo app https://opengeos.org/pages-preview/GeoLibre/pr-1969/demo/
Commit 0138fd8

Note

GitHub Pages built this preview successfully, but its serving edge returned HTTP 403 when checked. The links may still be propagating.

@giswqs
giswqs merged commit 5b89c26 into main Aug 17, 2026
19 checks passed
@giswqs
giswqs deleted the fix/chrome-extension-binary-and-braces branch August 17, 2026 01:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants