Handle whitespace and escaped quotes in CQL values

See #743.
This commit is contained in:
tschaub
2012-11-02 11:44:41 -06:00
parent 8d0da09454
commit 47ef7e87f7
2 changed files with 68 additions and 4 deletions

View File

@@ -30,7 +30,7 @@ OpenLayers.Format.CQL = (function() {
COMPARISON: /^(=|<>|<=|<|>=|>|LIKE)/i,
COMMA: /^,/,
LOGICAL: /^(AND|OR)/i,
VALUE: /^('\w+'|\d+(\.\d*)?|\.\d+)/,
VALUE: /^('([^']|'')*'|\d+(\.\d*)?|\.\d+)/,
LPAREN: /^\(/,
RPAREN: /^\)/,
SPATIAL: /^(BBOX|INTERSECTS|DWITHIN|WITHIN|CONTAINS)/i,
@@ -258,8 +258,9 @@ OpenLayers.Format.CQL = (function() {
type: operators[tok.text.toUpperCase()]
});
case "VALUE":
if ((/^'.*'$/).test(tok.text)) {
return tok.text.substr(1, tok.text.length - 2);
var match = tok.text.match(/^'(.*)'$/);
if (match) {
return match[1].replace(/''/g, "'");
} else {
return Number(tok.text);
}
@@ -425,7 +426,7 @@ OpenLayers.Format.CQL = (function() {
}
case undefined:
if (typeof filter === "string") {
return "'" + filter + "'";
return "'" + filter.replace(/'/g, "''") + "'";
} else if (typeof filter === "number") {
return String(filter);
}