mapbox / mapbox/mapbox-gl-js

Literal expression validation does not match documentation

Open
#9,308 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

docs :scroll: style-spec
Dominant language
TypeScript
Stars
12.4k
Forks
2.4k
PR merge metrics
No merged PRs in 30d

Description

The style spec documentation for [literal expressions](https://docs.mapbox.com/mapbox-gl-js/style-spec/expressions/#types-literal) says it requires an array or object in the second argument. However, in Studio, an expression like the one below passes validation.

`
[ "literal", "#333333" ]
`

**mapbox-gl-js version**: `@mapbox/mapbox-gl-style-spec@13.11.0`

**browser**: N/A

### Steps to Trigger Behavior

Save this style, upload to Studio, and try clicking on the single layer.

```
{
"layers": [
{
"id": "this-be-the-problem",
"layout": {},
"paint": {
"fill-extrusion-color": [
"case",
[
"boolean",
false
],
"#333333",
[
"literal",
"#999999"
]
]
},
"source": "composite",
"source-layer": "building",
"type": "fill-extrusion"
}
],
"name": "Problematic Literal",
"sources": {
"composite": {
"type": "vector",
"url": "mapbox://mapbox.mapbox-streets-v8"
}
},
"version": 8
}
```

I'm sorry I don't have a better way to illustrate this, but Studio uses validator functions when you try uploading any style.

This causes issues in our json editor, which enforces Studio limitations around object literals and only allows arrays in `literal` expressions.

I'm not sure how long this behavior has been around, but it's likely that stricting up this validation could break production styles. It would be worth seeing how many styles this would affect, cc @samanpwbb.

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 the style spec documentation for literal expressions and the validator functions used when Studio uploads a style. Compare the documented array-or-object requirement with the accepted string expression and investigate whether existing production styles depend on that behavior. Done means the validation behavior and documentation agree without overlooking the reported editor impact.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.