Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@

### 🐞 Bug fixes
- Fix RuntimeError class, make it inherited from Error ([#983](https://github.com/maplibre/maplibre-style-spec/issues/983))
- Fix `validate_object` crashing when object prototype keys used in style's objects ([#1028](https://github.com/maplibre/maplibre-style-spec/pull/1028))
- Validate that `layers` array items are objects instead of throwing an error if not ([!1026](https://github.com/maplibre/maplibre-style-spec/pull/1026))
- Validate that `layers` array items are objects instead of throwing an error if not ([#1026](https://github.com/maplibre/maplibre-style-spec/pull/1026))
- Multiple fixes related to validating and parsing of strings containing object prototype keys
- Fix `validate_object` crashing when object prototype keys used in style's objects ([#1028](https://github.com/maplibre/maplibre-style-spec/pull/1028))
- Fix `validate_color` crashing when object prototype keys used as color strings ([#1036](https://github.com/maplibre/maplibre-style-spec/pull/1036))
- Fix color coercion in expressions (e.g. `to_color`) producing invalid colors when object prototype keys used as color strings ([#1036](https://github.com/maplibre/maplibre-style-spec/pull/1036))

## 23.1.0

Expand Down
9 changes: 5 additions & 4 deletions src/expression/evaluation_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ export class EvaluationContext {
availableImages: Array<string>;
canonical: ICanonicalTileID;

_parseColorCache: {[_: string]: Color};
_parseColorCache: Map<string, Color>;

constructor() {
this.globals = null;
this.feature = null;
this.featureState = null;
this.formattedSection = null;
this._parseColorCache = {};
this._parseColorCache = new Map<string, Color>();
this.availableImages = null;
this.canonical = null;
}
Expand All @@ -46,9 +46,10 @@ export class EvaluationContext {
}

parseColor(input: string): Color {
let cached = this._parseColorCache[input];
let cached = this._parseColorCache.get(input);
if (!cached) {
cached = this._parseColorCache[input] = Color.parse(input);
cached = Color.parse(input);
this._parseColorCache.set(input, cached);
}
return cached;
}
Expand Down
2 changes: 2 additions & 0 deletions src/expression/types/parse_css_color.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ describe('parseCssColor', () => {
expect(parse('aqua-marine')).toBeUndefined();
expect(parse('aqua_marine')).toBeUndefined();
expect(parse('aqua marine')).toBeUndefined();
expect(parse('__proto__')).toBeUndefined();
expect(parse('valueOf')).toBeUndefined();
});

});
Expand Down
3 changes: 2 additions & 1 deletion src/expression/types/parse_css_color.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {getOwn} from '../../util/get_own';
import {HSLColor, hslToRgb, RGBColor} from './color_spaces';

/**
Expand Down Expand Up @@ -37,7 +38,7 @@ export function parseCssColor(input: string): RGBColor | undefined {
}

// 'white', 'black', 'blue'
const namedColorsMatch = namedColors[input];
const namedColorsMatch = getOwn(namedColors, input);
if (namedColorsMatch) {
const [r, g, b] = namedColorsMatch;
return [r / 255, g / 255, b / 255, 1];
Expand Down
11 changes: 11 additions & 0 deletions test/integration/expression/tests/to-color/basic/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@
}
}
],
[
{},
{
"properties": {
"x": "__proto__"
}
}
],
[
{},
{
Expand Down Expand Up @@ -85,6 +93,9 @@
{
"error": "Could not parse color from value 'invalid'"
},
{
"error": "Could not parse color from value '__proto__'"
},
[
0,
1,
Expand Down
16 changes: 16 additions & 0 deletions test/integration/style-spec/tests/bad-color.input.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,22 @@
"paint": {
"fill-outline-color": ["darken", 10, "#FF0000"]
}
},
{
"id": "prototype",
"type": "fill",
"source": "vector",
"source-layer": "layer",
"paint": {
"fill-color": "__proto__",
"fill-outline-color": {
"property": "fill",
"stops": [
[{ "zoom": 10, "value": 10 }, "valueOf"],
[{ "zoom": 11, "value": 20 }, "__proto__"]
]
}
}
}
]
}
12 changes: 12 additions & 0 deletions test/integration/style-spec/tests/bad-color.output.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,17 @@
{
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that there were both *.output-api-supported.json and *.output.json files in the tests, but was unable to find references to output-api-supported or api-supported in the codebase, other than a changelog entry saying --mapbox-api-supported had been removed from gl-style-validation in 14.0.0. Are the .output-api-supported.json files still used, or subject for removal in a later PR?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't find anything related to this in the history of the repo, I'm not sure they were ever used, and also from a very shallow test I made these looks duplicates of the output files, so I would recommend removing them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Remove in this PR or shall I make a separate PR?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A separate PR seems like the right approach.

"message": "layers[1].paint.fill-outline-color: color expected, array found",
"line": 26
},
{
"message": "layers[2].paint.fill-color: color expected, \"__proto__\" found",
"line": 35
},
{
"message": "layers[2].paint.fill-outline-color.stops[0][1]: color expected, \"valueOf\" found",
"line": 39
},
{
"message": "layers[2].paint.fill-outline-color.stops[1][1]: color expected, \"__proto__\" found",
"line": 40
}
]
16 changes: 16 additions & 0 deletions test/integration/style-spec/tests/light-malformed-color.input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"version": 8,
"sources": {
"vector": {
"type": "vector",
"url": "https://demotiles.maplibre.org/tiles/tiles.json"
}
},
"light": {
"anchor": "map",
"position": [1, 90, 90],
"color": "__proto__",
"intensity": 0.75
},
"layers": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"message": "color: color expected, \"__proto__\" found",
"line": 12
}
]