feat: validate style IDs in style_comparison_tool#121
Merged
Conversation
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add input validation for the before/after style parameters to ensure they contain only alphanumeric characters, hyphens, and underscores. Validation is enforced at both the Zod schema layer and inside processStyleId() after the mapbox://styles/ prefix is stripped, so malformed style IDs are rejected with a descriptive error before any comparison URL is constructed. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
zmofei
approved these changes
Jun 23, 2026
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.
Summary
beforeandafterstyle inputs are now validated to only accept well-formed style identifiers.regex()on the input schema (rejects bad input immediately on the way in) and avalidateStyleId()check insideprocessStyleId()after themapbox://styles/prefix is strippedusername/styleIdwhere each segment is[a-zA-Z0-9_-]only; anything else is rejected with a descriptive error before any comparison URL is constructedmapbox://styles/prefixed inputs (14 tests total)Test plan
npm test -- test/tools/style-comparison-tool/StyleComparisonTool.test.ts— 14 tests passmapbox/streets-v12,mapbox://styles/mapbox/outdoors-v12, bare style ID with token) continue to work unchanged"Invalid style format"error🤖 Generated with Claude Code