mapbox / mapbox/mapbox-gl-js

Style spec validator allows any `string` as a value for `projection` field

Open
#12,198 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug :lady_beetle:
Dominant language
TypeScript
Stars
12.4k
Forks
2.4k
PR merge metrics
No merged PRs in 30d

Description

Style-spec validator allows projection to be a string which is not supported by the spec itself. The spec states that it should be an object with a name field.

This line is the source of the problem: https://github.com/mapbox/mapbox-gl-js/blob/5859fd8103adc1781e047d89189d7e5f96f5df9a/src/style-spec/validate/validate_projection.js#L29

Somewhat related: https://github.com/mapbox/mapbox-gl-js/issues/12028

This page in the documentation describes where shorthand is appropriate. It seems like it should never be present in a style.

const token = 'pk.eyJ1IjoiYWxleGFuZGVyLWJlbG9rb24iLCJhIjoiY2w3Z2R0cTRiMDNmZTN2b2E1NTNoZGVsOCJ9.UJGcVwpGNY34ApOhnkw4wg'
mapboxgl.accessToken = token

async function create() {
  const res = await fetch(`https://api.mapbox.com/styles/v1/mapbox/streets-v11?access_token=${token}`)
  const style = await res.json()

  // works
  const map1 = new mapboxgl.Map({ container: 'map1', style: { ...style }, projection: 'globe' })
  
  // doesn't work
  const map2 = new mapboxgl.Map({ container: 'map2', style: { ...style, projection: 'globe' } })
}
create()

mapbox-gl-js version: 2.10.0

browser: any

Steps to Trigger Behavior
  1. create a style with { "projection": "chair" }
  2. try to validate it
  3. observe return value
Link to Demonstration

JSBin

Expected Behavior

Validator rejects string values for the projection field

Actual Behavior

Validator allows string values for the projection field

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with src/style-spec/validate/validate_projection.js at the linked line, then compare its accepted values with the projection definition in src/style-spec/reference/v8.json. Run the validation steps from the issue with a string projection and an object projection; done means the validator rejects string values for projection while preserving the supported object form.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.