Navigation Menu

Skip to content

Commit

Permalink
bq: add validation for invalid (not ...) syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Aug 28, 2012
1 parent de5b3c1 commit b48a842
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
15 changes: 11 additions & 4 deletions lib/bq-translator.js
Expand Up @@ -211,12 +211,19 @@ BooleanQueryTranslator.prototype = {
translateGroupNot: function() {
var expression = this.translateExpression();
this.skipSpaces();
if (this.query[this.offset] == ")") {
this.offset++;
return "(all_records() &! " + expression + ")";
} else {

if (this.offset == this.query.length) {
this.throwSyntaxError("close parenthesis is missing: operator:<not>");
}

var character = this.query[this.offset];
if (character != ")") {
this.throwSyntaxError("a garbage character after value: " +
"<" + character + ">");
}

this.offset++;
return "(all_records() &! " + expression + ")";
},
translateExpression: function() {
if (this.query[this.offset] == "(") {
Expand Down
9 changes: 9 additions & 0 deletions test/bq-translator.test.js
Expand Up @@ -323,6 +323,15 @@ suite('BoolanQueryTranslator', function() {
"(and field1:'k1' field2:'k2'||",
"close parenthesis is missing: operator:<and>");

testGroupError("not: garbage after value",
"(not field1:'k1' field2:'k2')",
"(not field1:'k1' |f|ield2:'k2')",
"a garbage character after value: <f>");
testGroupError("not: missing close parentheis",
"(not field1:'k1'",
"(not field1:'k1'||",
"close parenthesis is missing: operator:<not>");

testExpression("value only: stirng: and: space",
"'keyword1 keyword2' 'other keyword'",
"'keyword1 keyword2'".length,
Expand Down

0 comments on commit b48a842

Please sign in to comment.