Repository navigation
gmaps: keep the /maps/place/ marker when a place URL has a ".." segment - #330
Merged
Merged
Conversation
Some place links look like /maps/place/../data=... The ".." is a normal RFC 3986 dot segment, so resolving the URL before the request collapses "/maps/place/.." down to "/maps" and the "/maps/place/" marker is lost. Job.Process detects places with strings.Contains(resp.URL, "/maps/place/"), so it then no longer recognizes the page as a place and the detail is dropped. sanitizePlaceURL rewrites the "/place/../" path segment to "/place/_/" on the raw URL string so normalization leaves the path intact. It works on the raw string on purpose: parsing and re-serializing the URL would re-encode the data= payload (the %2F and ! bytes), which must stay byte-for-byte intact. NewPlaceJob applies it to every place URL it builds, both the resp.URL path and the extracted-href path in job.go. Fixes gosom#320.
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The sanitization is not applied to seed URLs handled via NewGmapJob (when the input query is already a Maps URL), so the reported “feed a place URL into the pipeline” scenario can still lose the /maps/place/ marker before place detection runs.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 1
Open (1)
What changed in this PR
This PR addresses a Google Maps URL normalization edge case where /maps/place/../data=... loses the /maps/place/ marker during dot-segment removal, causing place pages to be misclassified and their detail results to be dropped.
Changes:
- Sanitize place-detail URLs by rewriting the
/place/../path segment to/place/_/to prevent RFC 3986 dot-segment collapsing. - Apply the sanitization in
NewPlaceJobso generated place jobs retain the/maps/place/marker. - Add table-driven tests and a normalization regression test to ensure the marker and
data=payload survive.
| File | Description |
|---|---|
| gmaps/place.go | Adds sanitizePlaceURL and applies it in NewPlaceJob to preserve /maps/place/ through normalization. |
| gmaps/place_url_test.go | Adds tests validating the sanitization behavior and a regression test for URL normalization survival. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+34
to
+35
| u = sanitizePlaceURL(u) | ||
|
|
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.

Fixes #320.
What happens now:
Some place links Google returns look like /maps/place/../data=!4m2!3m1!1s0x... The ".." is a normal RFC 3986 dot segment, so when the URL is resolved before the request is made, remove_dot_segments collapses "/maps/place/.." down to "/maps" and the URL becomes /maps/data=!4m2!... The "/maps/place/" marker is gone. Job.Process detects places with strings.Contains(resp.URL, "/maps/place/"), so it no longer recognizes the page as a place, and the detail result is dropped.
Root cause:
The ".." is only special because it is a dot segment. Nothing else in the URL needs to change. If the ".." is replaced with a value that is not a dot segment, normalization leaves the path intact and the marker survives.
The fix:
sanitizePlaceURL rewrites the "/place/../" path segment to "/place/_/" on the raw URL string, and NewPlaceJob applies it to every place URL it builds. Both entry points in job.go route through NewPlaceJob (the resp.URL redirect path and the extracted-href path), so every place URL is covered. It operates on the raw string on purpose: parsing and re-serializing the URL would re-encode the data= payload (the %2F and ! bytes), and this fix must leave that payload byte-for-byte intact. The surrounding slashes require "place" to be a full path segment, so an unrelated path like /myplace/../ is left alone.
Steps to reproduce:
Verification: