Skip to content

Commit 5e38756

Browse files
committed
Merge pull request openlayers#1477 from ahocevar/fix-cql
Fix value RegExp for CQL filter
2 parents 249899a + ce1209a commit 5e38756

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

lib/OpenLayers/Format/CQL.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212

1313
/**
1414
* Class: OpenLayers.Format.CQL
15-
* Read CQL strings to get <OpenLayers.Filter> objects. Write
16-
* <OpenLayers.Filter> objects to get CQL strings. Create a new parser with
15+
* Read CQL strings to get <OpenLayers.Filter> objects. Write
16+
* <OpenLayers.Filter> objects to get CQL strings. Create a new parser with
1717
* the <OpenLayers.Format.CQL> constructor.
1818
*
1919
* Inherits from:
2020
* - <OpenLayers.Format>
2121
*/
2222
OpenLayers.Format.CQL = (function() {
23-
23+
2424
var tokens = [
2525
"PROPERTY", "COMPARISON", "VALUE", "LOGICAL"
2626
],
@@ -31,7 +31,7 @@ OpenLayers.Format.CQL = (function() {
3131
IS_NULL: /^IS NULL/i,
3232
COMMA: /^,/,
3333
LOGICAL: /^(AND|OR)/i,
34-
VALUE: /^('([^']|'')*'|^-?\d*(\.\d+)?)/,
34+
VALUE: /^('([^']|'')*'|-?\d+(\.\d*)?|\.\d+)/,
3535
LPAREN: /^\(/,
3636
RPAREN: /^\)/,
3737
SPATIAL: /^(BBOX|INTERSECTS|DWITHIN|WITHIN|CONTAINS)/i,
@@ -355,7 +355,7 @@ OpenLayers.Format.CQL = (function() {
355355
* Returns:
356356
* {<OpenLayers.Filter>} A filter based on the CQL text.
357357
*/
358-
read: function(text) {
358+
read: function(text) {
359359
var result = buildAst(tokenize(text));
360360
if (this.keepData) {
361361
this.data = result;
@@ -407,7 +407,7 @@ OpenLayers.Format.CQL = (function() {
407407
}
408408
case "OpenLayers.Filter.Logical":
409409
if (filter.type == OpenLayers.Filter.Logical.NOT) {
410-
// TODO: deal with precedence of logical operators to
410+
// TODO: deal with precedence of logical operators to
411411
// avoid extra parentheses (not urgent)
412412
return "NOT (" + this.write(filter.filters[0]) + ")";
413413
} else {
@@ -425,12 +425,12 @@ OpenLayers.Format.CQL = (function() {
425425
}
426426
case "OpenLayers.Filter.Comparison":
427427
if (filter.type == OpenLayers.Filter.Comparison.BETWEEN) {
428-
return filter.property + " BETWEEN " +
429-
this.write(filter.lowerBoundary) + " AND " +
428+
return filter.property + " BETWEEN " +
429+
this.write(filter.lowerBoundary) + " AND " +
430430
this.write(filter.upperBoundary);
431431
} else {
432432
return (filter.value !== null) ? filter.property +
433-
" " + operatorReverse[filter.type] + " " +
433+
" " + operatorReverse[filter.type] + " " +
434434
this.write(filter.value) : filter.property +
435435
" " + operatorReverse[filter.type];
436436
}
@@ -449,4 +449,3 @@ OpenLayers.Format.CQL = (function() {
449449

450450
});
451451
})();
452-

tests/Format/CQL.html

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
"Property extracted from CQL text");
3131
t.eq(filter.value, 'B',
3232
"Value extracted from CQL text");
33-
34-
33+
34+
3535
t.eq(format.write(filter), test_cql, "write returned test cql");
3636
}
3737

@@ -112,8 +112,8 @@
112112
"Property extracted from CQL text");
113113
t.eq(filter.value, 10,
114114
"Value extracted from CQL text");
115-
116-
115+
116+
117117
t.eq(format.write(filter), test_cql, "write returned test cql");
118118
}
119119

@@ -212,7 +212,7 @@
212212
}
213213

214214
function test_BBOX(t) {
215-
t.plan(5);
215+
t.plan(6);
216216
var format = new OpenLayers.Format.CQL(),
217217
cql = "BBOX(the_geom,1,2,3,4)",
218218
filter = format.read(cql);
@@ -224,9 +224,12 @@
224224
"Property name is as specified in CQL");
225225
t.eq(filter.value.toBBOX(), "1,2,3,4",
226226
"Value is as specified in CQL");
227-
228227
t.eq(format.write(filter), cql, "write returned test cql");
229228

229+
var negCql = "BBOX(the_geom,-1,-2,3,4)"
230+
filter = format.read(negCql)
231+
t.eq(filter.value.toBBOX(), "-1,-2,3,4",
232+
"Negative value is as specified in CQL");
230233
}
231234

232235
function test_INTERSECTS(t) {
@@ -242,7 +245,7 @@
242245
"Property name is as specified in CQL");
243246
t.ok(filter.value instanceof OpenLayers.Geometry,
244247
"Value is a geometry");
245-
248+
246249
t.eq(format.write(filter), cql, "write returned test cql");
247250

248251
}

0 commit comments

Comments
 (0)