Skip to content

Commit 2962314

Browse files
committed
Fix WFS CQL->OGC null filter parsing
1 parent 0ab1749 commit 2962314

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

web/client/utils/filter/converters/__tests__/cql-test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,25 @@ describe('CQL converter', () => {
3737
cql: 'prop1 <= 1',
3838
opts: {filterNS: 'ogc'},
3939
ogc: '<ogc:PropertyIsLessThanOrEqualTo><ogc:PropertyName>prop1</ogc:PropertyName><ogc:Literal>1</ogc:Literal></ogc:PropertyIsLessThanOrEqualTo>'
40+
}, {
41+
cql: '(NOT ("STATE_NAME" IS NULL))',
42+
opts: {filterNS: 'ogc'},
43+
ogc: '<ogc:Not><ogc:PropertyIsNull><ogc:PropertyName>STATE_NAME</ogc:PropertyName></ogc:PropertyIsNull></ogc:Not>'
44+
},
45+
{
46+
cql: '"STATE_NAME" IS NULL AND prop1 = 1',
47+
opts: {filterNS: 'ogc'},
48+
ogc: '<ogc:And><ogc:PropertyIsNull><ogc:PropertyName>STATE_NAME</ogc:PropertyName></ogc:PropertyIsNull><ogc:PropertyIsEqualTo><ogc:PropertyName>prop1</ogc:PropertyName><ogc:Literal>1</ogc:Literal></ogc:PropertyIsEqualTo></ogc:And>'
49+
},
50+
{
51+
cql: 'isNull("STATE_NAME")=true',
52+
opts: {filterNS: 'ogc'},
53+
ogc: '<ogc:PropertyIsEqualTo><ogc:Function name="isNull"><ogc:PropertyName>STATE_NAME</ogc:PropertyName></ogc:Function><ogc:Literal>true</ogc:Literal></ogc:PropertyIsEqualTo>'
54+
},
55+
{
56+
cql: '(NOT (isNull("STATE_NAME")=true))',
57+
opts: {filterNS: 'ogc'},
58+
ogc: '<ogc:Not><ogc:PropertyIsEqualTo><ogc:Function name="isNull"><ogc:PropertyName>STATE_NAME</ogc:PropertyName></ogc:Function><ogc:Literal>true</ogc:Literal></ogc:PropertyIsEqualTo></ogc:Not>'
4059
}
4160

4261
];

web/client/utils/ogc/Filter/CQL/parser.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const patterns = {
2121
EXCLUDE: /^EXCLUDE$/,
2222
PROPERTY: /^"?[_a-zA-Z"]\w*"?/,
2323
COMPARISON: /^(=|<>|<=|<|>=|>|LIKE|ILIKE)/i,
24-
IS_NULL: /^IS NULL/i,
24+
IS_NULL: /^[`"'\\\u200B-\u200D\uFEFF\s]*IS\s+NULL/i,
2525
COMMA: /^,/,
2626
AND: /^(AND)/i,
2727
OR: /^(OR)/i,
@@ -69,11 +69,11 @@ export const patterns = {
6969
const follows = {
7070
INCLUDE: ['END'],
7171
EXCLUDE: ['END'],
72-
LPAREN: ['GEOMETRY', 'SPATIAL', 'FUNCTION', 'PROPERTY', 'VALUE', 'LPAREN', 'RPAREN', 'NOT'],
72+
LPAREN: ['GEOMETRY', 'SPATIAL', 'FUNCTION', 'NOT', 'PROPERTY', 'VALUE', 'LPAREN', 'RPAREN'],
7373
RPAREN: ['NOT', 'AND', 'OR', 'END', 'RPAREN', 'COMMA', 'COMPARISON', 'BETWEEN', 'IS_NULL'],
7474
PROPERTY: ['COMPARISON', 'BETWEEN', 'COMMA', 'IS_NULL', 'RPAREN'],
7575
BETWEEN: ['VALUE'],
76-
IS_NULL: ['END'],
76+
IS_NULL: ['AND', 'OR', 'COMMA', 'RPAREN', 'END'],
7777
COMPARISON: ['VALUE', 'FUNCTION'],
7878
COMMA: ['GEOMETRY', 'FUNCTION', 'VALUE', 'PROPERTY'],
7979
VALUE: ['AND', 'OR', 'COMMA', 'RPAREN', 'END'],
@@ -113,7 +113,8 @@ const precedence = {
113113
'RPAREN': 4,
114114
'OR': 3,
115115
'AND': 2,
116-
'COMPARISON': 1
116+
'COMPARISON': 1,
117+
'IS_NULL': 1
117118
};
118119

119120
const tryToken = (text, pattern) => {

web/client/utils/ogc/Filter/fromObject.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ const operators = {
1010
'>': "greater",
1111
'>=': "greaterOrEqual",
1212
'like': "like",
13-
'ilike': "ilike"
14-
// TODO: support unary operators like isNull
13+
'ilike': "ilike",
14+
'isNull': "isNull"
1515
// TODO: support geometry operations
1616
};
1717
const spatial = ["intersects", "within", "bbox", "dwithin", "contains"];

0 commit comments

Comments
 (0)