Skip to content

fix: initialize nil patterns map in extractPlaceID to prevent panic#261

Merged
gosom merged 2 commits into
gosom:mainfrom
aurbina83:bugfix/nil-map-panic-extractPlaceID
Apr 19, 2026
Merged

fix: initialize nil patterns map in extractPlaceID to prevent panic#261
gosom merged 2 commits into
gosom:mainfrom
aurbina83:bugfix/nil-map-panic-extractPlaceID

Conversation

@aurbina83
Copy link
Copy Markdown
Contributor

Bug Fix

The patterns map in extractPlaceID (gmaps/reviews.go) was declared but never initialized before being written to inside the sync.Once block. This caused a nil map assignment panic at runtime when extractPlaceID was called for the first time.

Fix

Added patterns = make(map[string]*regexp.Regexp) before the loop that populates the map.

Tests

Added gmaps/reviews_test.go with unit tests for extractPlaceID covering:

  • Standard hex format place IDs
  • place_id query parameter format
  • Full place URL with data segment
  • Search URLs with no place ID (error case)
  • Empty URL (error case)

The patterns map was declared but never initialized before being
written to in the sync.Once block, causing a nil map assignment
panic at runtime.

Added unit tests for extractPlaceID covering various URL formats.
@aurbina83 aurbina83 force-pushed the bugfix/nil-map-panic-extractPlaceID branch from 7aa42e8 to 3623ea4 Compare April 17, 2026 13:56
@gosom
Copy link
Copy Markdown
Owner

gosom commented Apr 19, 2026

@aurbina83 thanks for you contribution. I will fix linter and merge asap

@gosom gosom merged commit d2b36e7 into gosom:main Apr 19, 2026
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