Repository navigation
Quote GeoJson identifier properties that aren't valid JS identifiers - #2296
Merged
hansthen merged 1 commit intoOct 11, 2026
Conversation
When GeoJson features have no unique `id`, `find_identifier` picks a property with unique values and emits it with dot notation in the styler and highlighter `switch`. A key like "Time (UTC)" became `feature.properties.Time (UTC)`, which Javascript runs as a call and throws `ReferenceError: UTC is not defined`, so nothing in the layer was drawn (python-visualization#1782). A key like "property-key" turned into a subtraction, and a key with a dot ("osm.id") made `get_feature_id` raise `KeyError` while rendering. Keys that aren't identifiers now use bracket notation with an escaped JSON string, and `get_feature_id` reads that form back. Co-Authored-By: Claude Opus 5.5 <[email protected]>
hansthen
marked this pull request as ready for review
October 11, 2026 11:40
Collaborator
|
Good catch. I see no problems. |
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1782.
The bug
If the features in a
GeoJsonhave no uniqueid,find_identifier()looks for a property with a unique value per feature. It then writes it into the styler/highlighterswitchwith dot notation:feature.properties.<key>. If the key isn't a valid JavaScript identifier, the generated code is wrong:Time (UTC)(the issue's data)switch(feature.properties.Time (UTC))feature.properties.Time(UTC)→ReferenceError: UTC is not definedproperty-keyswitch(feature.properties.property-key)feature.properties.property - key→ReferenceErrorosm.idget_feature_idsplits on.and raisesKeyError: 'osm'in Python duringrender()In the browser the styler throws when Leaflet styles the first feature, so the layer isn't drawn. That's why the reporter's features disappear only when
style_functionis passed: without a style or highlight function no identifier is needed.I reproduced it with the
demo.jsonattached to the issue on currentmain. All 35 features are LineStrings withoutid, and the first property with unique values is"Time (UTC)". I ran the generated_stylerfunction in node against every feature:ReferenceError: UTC is not definedstyled 35 of 35The fix
find_identifier()keepsfeature.properties.<key>whenkey.isidentifier(), so output for ordinary keys is unchanged. Other keys use bracket notation with the key encoded by the existing HTML-safe_to_escaped_json, e.g.feature.properties["Time (UTC)"].GeoJsonStyleMapper.get_feature_id()reads that bracket form back withjson.loadsinstead of splitting the expression on..Tests
test_geojson_find_identifier: the twoproperty-keycases asserted the broken dot form. They now expectfeature.properties["property-key"]. I added an identifier key (property_key) to cover the dot-notation branch.test_geojson_style_identifier_with_special_characters, parametrized overTime (UTC),@idandosm.id. It renders a styled map, checks theswitch(...)expression, and checks the resulting style map.mainand pass with this change.pytest tests(without selenium/playwright/snapshots): 380 passed. 5 failed, and those same 5 also fail on unmodifiedmainin my environment: three PNG-export tests (ImportError),test_timedynamic_geo_json(geodatasetsnot installed) andtest_icon_invalid_marker_colors(no warning emitted).black --checkandruff checkpass on the touched files.🤖 Generated with Claude Code