ignore whitespace in filter values

This commit is contained in:
Bart van den Eijnden
2012-03-19 11:13:27 +01:00
parent a0e53931e4
commit 7a769830fe
2 changed files with 58 additions and 4 deletions

View File

@@ -27,7 +27,7 @@ OpenLayers.Format.Filter.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
xlink: "http://www.w3.org/1999/xlink", xlink: "http://www.w3.org/1999/xlink",
xsi: "http://www.w3.org/2001/XMLSchema-instance" xsi: "http://www.w3.org/2001/XMLSchema-instance"
}, },
/** /**
* Property: defaultPrefix * Property: defaultPrefix
*/ */
@@ -180,18 +180,18 @@ OpenLayers.Format.Filter.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
}, },
"Literal": function(node, obj) { "Literal": function(node, obj) {
obj.value = OpenLayers.String.numericIf( obj.value = OpenLayers.String.numericIf(
this.getChildValue(node)); this.getChildValue(node).replace(this.regExes.trimSpace, ""));
}, },
"PropertyName": function(node, filter) { "PropertyName": function(node, filter) {
filter.property = this.getChildValue(node); filter.property = this.getChildValue(node);
}, },
"LowerBoundary": function(node, filter) { "LowerBoundary": function(node, filter) {
filter.lowerBoundary = OpenLayers.String.numericIf( filter.lowerBoundary = OpenLayers.String.numericIf(
this.readers.ogc._expression.call(this, node)); this.readers.ogc._expression.call(this, node).replace(this.regExes.trimSpace, ""));
}, },
"UpperBoundary": function(node, filter) { "UpperBoundary": function(node, filter) {
filter.upperBoundary = OpenLayers.String.numericIf( filter.upperBoundary = OpenLayers.String.numericIf(
this.readers.ogc._expression.call(this, node)); this.readers.ogc._expression.call(this, node).replace(this.regExes.trimSpace, ""));
}, },
"Intersects": function(node, obj) { "Intersects": function(node, obj) {
this.readSpatial(node, obj, OpenLayers.Filter.Spatial.INTERSECTS); this.readSpatial(node, obj, OpenLayers.Filter.Spatial.INTERSECTS);

View File

@@ -523,6 +523,14 @@
} }
function test_whitespace(t) {
t.plan(1);
var xml = readXML("propertyisbetweenwhitespace.sld");
var output = new OpenLayers.Format.SLD().read(xml);
var filter = output.namedLayers['geonode:US_Stat0'].userStyles[0].rules[0].filter;
t.eq(filter.lowerBoundary, 29.7, "whitespace ignored in values and value transformed to number");
}
function test_label_LinePlacement(t) { function test_label_LinePlacement(t) {
t.plan(1); t.plan(1);
var format = new OpenLayers.Format.SLD.v1_0_0({ var format = new OpenLayers.Format.SLD.v1_0_0({
@@ -970,5 +978,51 @@
</sld:FeatureTypeStyle> </sld:FeatureTypeStyle>
</sld:UserStyle> </sld:UserStyle>
--></div> --></div>
<div id="propertyisbetweenwhitespace.sld"><!--
<sld:StyledLayerDescriptor xmlns="http://www.opengis.net/sld" xmlns:sld="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml" version="1.0.0">
<sld:NamedLayer>
<sld:Name>geonode:US_Stat0</sld:Name>
<sld:UserStyle>
<sld:Name>US_Stat0_5cbbe918</sld:Name>
<sld:Title>BMI&lt;25</sld:Title>
<sld:FeatureTypeStyle>
<sld:Name>name</sld:Name>
<sld:Rule>
<sld:Title>BMI&lt;25</sld:Title>
<ogc:Filter>
<ogc:PropertyIsBetween>
<ogc:PropertyName>Hlt_st_BMI</ogc:PropertyName>
<ogc:LowerBoundary>
<ogc:Literal>
29.7
</ogc:Literal>
</ogc:LowerBoundary>
<ogc:UpperBoundary>
<ogc:Literal>
36.2
</ogc:Literal>
</ogc:UpperBoundary>
</ogc:PropertyIsBetween>
</ogc:Filter>
<sld:PolygonSymbolizer>
<sld:Fill>
<sld:CssParameter name="fill">#C0F58C</sld:CssParameter>
</sld:Fill>
<sld:Stroke/>
</sld:PolygonSymbolizer>
</sld:Rule>
</sld:FeatureTypeStyle>
</sld:UserStyle>
</sld:NamedLayer>
</sld:StyledLayerDescriptor>
--></div>
</body> </body>
</html> </html>