Detect and report basic self-conflicting filters.
This does not yet report anything for more complex cases. We were also testing for tolerance of self-conflicting filters, which this breaks, in partial_overrides. This patch may want to wait for warning reporting since it may break stylesheets in the wild.
This commit is contained in:
parent
6f687ff9e3
commit
29b641c72d
@ -530,12 +530,18 @@ carto.Parser = function Parser(env) {
|
||||
zooms.push(z);
|
||||
conditions++;
|
||||
} else if (f) {
|
||||
filters.add(f);
|
||||
var err = filters.add(f);
|
||||
if (err) {
|
||||
throw makeError({
|
||||
message: err,
|
||||
index: i - 1
|
||||
});
|
||||
}
|
||||
conditions++;
|
||||
} else if (attachment) {
|
||||
throw makeError({
|
||||
message:'Encountered second attachment name.',
|
||||
index:i - 1
|
||||
message: 'Encountered second attachment name.',
|
||||
index: i - 1
|
||||
});
|
||||
} else {
|
||||
attachment = a;
|
||||
|
@ -155,9 +155,37 @@ tree.Filterset.prototype.addable = function(filter) {
|
||||
}
|
||||
};
|
||||
|
||||
// Does the new filter constitute a conflict?
|
||||
tree.Filterset.prototype.conflict = function(filter) {
|
||||
var key = filter.key.toString(),
|
||||
value = filter.val.toString();
|
||||
|
||||
if (!isNaN(parseFloat(value))) value = parseFloat(value);
|
||||
|
||||
// if (a=b) && (a=c)
|
||||
// if (a=b) && (a!=b)
|
||||
// or (a!=b) && (a=b)
|
||||
if ((filter.op === '=' && key + '=' in this.filters &&
|
||||
value != this.filters[key + '='].val.toString()) ||
|
||||
(filter.op === '!=' && key + '=' in this.filters &&
|
||||
value == this.filters[key + '='].val.toString()) ||
|
||||
(filter.op === '=' && key + '!=' in this.filters &&
|
||||
value == this.filters[key + '!='].val.toString())) {
|
||||
return filter.toString() + ' added to ' + this.toString() + ' produces an invalid filter';
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
// Only call this function for filters that have been cleared by .addable().
|
||||
tree.Filterset.prototype.add = function(filter) {
|
||||
var key = filter.key.toString(), id, op = filter.op, numval;
|
||||
tree.Filterset.prototype.add = function(filter, env) {
|
||||
var key = filter.key.toString(),
|
||||
id,
|
||||
op = filter.op,
|
||||
conflict = this.conflict(filter),
|
||||
numval;
|
||||
|
||||
if (conflict) return conflict;
|
||||
|
||||
if (op === '=') {
|
||||
for (var i in this.filters) {
|
||||
|
15
test/errorhandling/contradiction.mml
Normal file
15
test/errorhandling/contradiction.mml
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
"srs": "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over",
|
||||
"Stylesheet": [
|
||||
"contradiction.mss"
|
||||
],
|
||||
"Layer": [{
|
||||
"name": "world",
|
||||
"srs": "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over",
|
||||
"Datasource": {
|
||||
"file": "http://tilemill-data.s3.amazonaws.com/district.geojson",
|
||||
"type": "ogr",
|
||||
"layer": "OGRGeoJSON"
|
||||
}
|
||||
}]
|
||||
}
|
3
test/errorhandling/contradiction.mss
Normal file
3
test/errorhandling/contradiction.mss
Normal file
@ -0,0 +1,3 @@
|
||||
#world[FeatureCla!=""][FeatureCla=""] {
|
||||
polygon-fill: #fff;
|
||||
}
|
1
test/errorhandling/contradiction.result
Normal file
1
test/errorhandling/contradiction.result
Normal file
@ -0,0 +1 @@
|
||||
contradiction.mss:1:37 [[FeatureCla]=] added to [FeatureCla]!= produces an invalid filter
|
3
test/errorhandling/contradiction_2.mss
Normal file
3
test/errorhandling/contradiction_2.mss
Normal file
@ -0,0 +1,3 @@
|
||||
#world[FeatureCla=""][FeatureCla!=""] {
|
||||
polygon-fill: #fff;
|
||||
}
|
1
test/errorhandling/contradiction_2.result
Normal file
1
test/errorhandling/contradiction_2.result
Normal file
@ -0,0 +1 @@
|
||||
contradiction_2.mss:1:37 [[FeatureCla]!=] added to [FeatureCla]= produces an invalid filter
|
@ -18,10 +18,6 @@
|
||||
line-color: #f00;
|
||||
}
|
||||
|
||||
#world.m_5[NAME="United States"][NAME="Canada"] {
|
||||
line-color: #f00;
|
||||
}
|
||||
|
||||
#world.m_6[NAME!="Canada"][zoom > 5] {
|
||||
line-opacity: .7;
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE Map[]>
|
||||
<Map srs="+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over" maximum-extent="-20037508.34,-20037508.34,20037508.34,20037508.34">
|
||||
<Map srs="+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over" maximum-extent="-20037508.34,-20037508.34,20037508.34,20037508.34">
|
||||
|
||||
|
||||
<Style name="world" filter-mode="first">
|
||||
<Style name="world" filter-mode="first" >
|
||||
<Rule>
|
||||
<MaxScaleDenominator>1500000</MaxScaleDenominator>
|
||||
<Filter>([NAME] = 'United States') and ([POP] > 100000000)</Filter>
|
||||
@ -80,22 +80,6 @@
|
||||
<Filter>([NAME] != 'Canada')</Filter>
|
||||
<LineSymbolizer stroke-width="5" />
|
||||
</Rule>
|
||||
<Rule>
|
||||
<MaxScaleDenominator>1500000</MaxScaleDenominator>
|
||||
<Filter>([NAME] = 'Canada')</Filter>
|
||||
<LineSymbolizer stroke="#ff0000" stroke-opacity="0.4" stroke-width="3" />
|
||||
</Rule>
|
||||
<Rule>
|
||||
<MaxScaleDenominator>100000000</MaxScaleDenominator>
|
||||
<MinScaleDenominator>1500000</MinScaleDenominator>
|
||||
<Filter>([NAME] = 'Canada')</Filter>
|
||||
<LineSymbolizer stroke="#ff0000" stroke-opacity="0.2" stroke-width="3" />
|
||||
</Rule>
|
||||
<Rule>
|
||||
<MinScaleDenominator>100000000</MinScaleDenominator>
|
||||
<Filter>([NAME] = 'Canada')</Filter>
|
||||
<LineSymbolizer stroke="#ff0000" stroke-width="3" />
|
||||
</Rule>
|
||||
<Rule>
|
||||
<MaxScaleDenominator>1500000</MaxScaleDenominator>
|
||||
<LineSymbolizer stroke-opacity="0.4" stroke-width="3" />
|
||||
@ -110,13 +94,12 @@
|
||||
<LineSymbolizer stroke-width="3" />
|
||||
</Rule>
|
||||
</Style>
|
||||
<Layer
|
||||
name="world"
|
||||
srs="+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over">
|
||||
<Layer name="world"
|
||||
srs="+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over">
|
||||
<StyleName>world</StyleName>
|
||||
<Datasource>
|
||||
<Parameter name="file">[absolute path]</Parameter>
|
||||
<Parameter name="type">shape</Parameter>
|
||||
<Parameter name="file"><![CDATA[[absolute path]]]></Parameter>
|
||||
<Parameter name="type"><![CDATA[shape]]></Parameter>
|
||||
</Datasource>
|
||||
</Layer>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user