Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 3 additions & 1 deletion src/expression/evaluation_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ export class EvaluationContext {
this.feature = null;
this.featureState = null;
this.formattedSection = null;
this._parseColorCache = {};
// the cache keys are user controlled (from the source JSON), so
// avoid prototype pollution by creating a record with a null prototype
this._parseColorCache = Object.create(null) as {[_: string]: Color};
this.availableImages = null;
this.canonical = null;
}
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
}
]