Skip to content

fix: encode !path geojson.io URL with safe='' so slashes don't break the map - #19

Merged
sg merged 1 commit into
mainfrom
fix/path-url-encoding
Jun 15, 2026
Merged

sg merged 1 commit into
mainfrom
fix/path-url-encoding

Conversation

@sg

@sg sg commented Jun 15, 2026

Copy link
Copy Markdown
Owner

Problem

!path sometimes produced a geojson.io map link that errored with "unterminated string in the json data" — but only for some paths.

Root cause

geojson.io's data-URL API expects encodeURIComponent(JSON.stringify(...)). path.py built the link with urllib.parse.quote(data), whose default safe="/" leaves forward slashes unescaped (unlike encodeURIComponent, which escapes /). So a hop whose node name contains / put a bare / inside the JSON payload in the #data= hash, and geojson.io's parser cut the JSON at that slash → "unterminated string." Only /-bearing names trip it, hence "some paths."

Ruled out: da.gd (stores targets intact to 10 KB+ in testing) and the JSON itself (valid, round-trips).

Fix

enc = urllib.parse.quote(data, safe="")   # was urllib.parse.quote(data)

safe="" matches encodeURIComponent, percent-encoding / (and everything else). Strictly more correct; over-encoding decodes identically, so working paths are unaffected.

Verification

For a path with a /-named hop: slash now encodes to %2F, the payload parses as valid JSON, and the full da.gd → geojson.io round-trip parses cleanly.

@sg
sg merged commit 0fb7a3d into main Jun 15, 2026
1 check passed
@sg
sg deleted the fix/path-url-encoding branch June 15, 2026 23:07
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.

1 participant