diff --git a/lib/OpenLayers/Filter/Comparison.js b/lib/OpenLayers/Filter/Comparison.js index 9271cc5975..a707928f0f 100644 --- a/lib/OpenLayers/Filter/Comparison.js +++ b/lib/OpenLayers/Filter/Comparison.js @@ -55,7 +55,7 @@ OpenLayers.Filter.Comparison = OpenLayers.Class(OpenLayers.Filter, { * elements. This property will be serialized with those elements only * if using the v1.1.0 filter format. However, when evaluating filters * here, the matchCase property will always be respected (for EQUAL_TO - * and NOT_EQUAL_TO). Default is true. + * and NOT_EQUAL_TO). Default is true. */ matchCase: true, @@ -90,6 +90,12 @@ OpenLayers.Filter.Comparison = OpenLayers.Class(OpenLayers.Filter, { */ initialize: function(options) { OpenLayers.Filter.prototype.initialize.apply(this, [options]); + // since matchCase on PropertyIsLike is not schema compliant, we only + // want to use this if explicitly asked for + if (this.type === OpenLayers.Filter.Comparison.LIKE + && options.matchCase === undefined) { + this.matchCase = null; + } }, /** diff --git a/lib/OpenLayers/Format/Filter/v1_1_0.js b/lib/OpenLayers/Format/Filter/v1_1_0.js index ea0333b87b..cd36a94c89 100644 --- a/lib/OpenLayers/Format/Filter/v1_1_0.js +++ b/lib/OpenLayers/Format/Filter/v1_1_0.js @@ -15,9 +15,9 @@ * Differences from the v1.0.0 parser: * - uses GML v3 instead of GML v2 * - reads matchCase attribute on ogc:PropertyIsEqual and - * ogc:PropertyIsNotEqualelements. - * - writes matchCase attribute from comparison filters of type EQUAL_TO and - * type NOT_EQUAL_TO. + * ogc:PropertyIsNotEqual elements. + * - writes matchCase attribute from comparison filters of type EQUAL_TO, + * NOT_EQUAL_TO and LIKE. * * Inherits from: * - @@ -127,6 +127,7 @@ OpenLayers.Format.Filter.v1_1_0 = OpenLayers.Class( "PropertyIsLike": function(filter) { var node = this.createElementNSPlus("ogc:PropertyIsLike", { attributes: { + matchCase: filter.matchCase, wildCard: "*", singleChar: ".", escapeChar: "!" } }); @@ -185,4 +186,4 @@ OpenLayers.Format.Filter.v1_1_0 = OpenLayers.Class( CLASS_NAME: "OpenLayers.Format.Filter.v1_1_0" -}); \ No newline at end of file +}); diff --git a/tests/Format/Filter/v1_1_0.html b/tests/Format/Filter/v1_1_0.html index 52787913a3..ef8c9ab61b 100644 --- a/tests/Format/Filter/v1_1_0.html +++ b/tests/Format/Filter/v1_1_0.html @@ -314,9 +314,39 @@ t.xml_eq(node, out, "spatial dwithin filter with nested functions correctly written"); } + function test_write_like_matchcase(t) { + t.plan(1); + + var filter = new OpenLayers.Filter.Comparison({ + type: OpenLayers.Filter.Comparison.LIKE, + property: "person", + value: "*me*", + matchCase: false + }); + + var format = new OpenLayers.Format.Filter.v1_1_0(); + + var got = format.write(filter); + var exp = readXML("LikeMatchCase"); + t.xml_eq(got, exp, "wrote matchCase attribute on PropertyIsLike"); + } + + function readXML(id) { + var xml = document.getElementById(id).firstChild.nodeValue; + return new OpenLayers.Format.XML().read(xml).documentElement; + } + +