Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix format expression options validation #8339

Merged
merged 7 commits into from
Jun 13, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/style-spec/util/unbundle_jsonlint.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
function isPrimitive(value) {
return value instanceof Number || value instanceof String || value instanceof Boolean;
}

// Turn jsonlint-lines-primitives objects into primitive objects
export function unbundle(value) {
if (value instanceof Number || value instanceof String || value instanceof Boolean) {
if (isPrimitive(value)) {
return value.valueOf();
} else {
return value;
Expand All @@ -11,7 +14,14 @@ export function unbundle(value) {
export function deepUnbundle(value) {
if (Array.isArray(value)) {
return value.map(deepUnbundle);
} else if (value instanceof Object && !isPrimitive(value)) {
const unbundledValue = {};
for (const key in value) {
unbundledValue[key] = deepUnbundle(value[key]);
}
return unbundledValue;
}

return unbundle(value);
}

45 changes: 45 additions & 0 deletions test/unit/style-spec/fixture/text-field-format.input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"version": 8,
"sources": {
"point": {
"type": "geojson",
"data": {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"name": "Napoli",
"name_en": "Naples",
"name_color": "blue"
},
"geometry": {
"type": "Point",
"coordinates": [ 0, 0 ]
}
}
]
}
}
},
"glyphs": "local://glyphs/{fontstack}/{range}.pbf",
"layers": [
{
"id": "text",
"type": "symbol",
"source": "point",
"layout": {
"text-field": [
"format",
"x",
{ "font-scale": 1.5 }
],
"text-font": [
"Open Sans Semibold",
"Arial Unicode MS Bold"
],
"text-size": 20
}
}
]
}
1 change: 1 addition & 0 deletions test/unit/style-spec/fixture/text-field-format.output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.0.0.tgz#06e2ab19bdb535385559aabb5ba59729482800f8"
integrity sha512-OfC2uemaknXr87bdLUkWog7nYuliM9Ij5HUcajsVcMCpQrcLmtxRbVFTIqmcSkSeYRBFBRxs2FiUqFJDLdiebA==
dependencies:
"@babel/highlight" "^7.0.0"
"@babel/highlight" "~7.0.0"

"@babel/core@>=7.1.0", "@babel/core@^7.1.2":
version "7.4.3"
Expand Down