mapbox-gl-js icon indicating copy to clipboard operation
mapbox-gl-js copied to clipboard

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

Open AlexanderBelokon opened this issue 2 years ago • 0 comments

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

AlexanderBelokon avatar Aug 29 '22 11:08 AlexanderBelokon