Navigation Menu

Skip to content

Commit

Permalink
bq: throw exception for garbage after field value
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Aug 6, 2012
1 parent 83c5ac2 commit 8b79209
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/bq-translator.js
Expand Up @@ -118,9 +118,10 @@ BooleanQueryTranslator.prototype = {
this.skipSpaces();
var expression = this.translateExpressionValueString(field);
this.skipSpaces();
if (this.query[this.offset] != ")") {
// TODO: report error: have garbage
return "";
var character = this.query[this.offset];
if (character != ")") {
this.throwTranslateError("a garbage character after value: " +
"<" + character + ">");
}
return expression;
} else if (character == ")") {
Expand Down
5 changes: 5 additions & 0 deletions test/bq-translator.test.js
Expand Up @@ -147,6 +147,11 @@ suite('BoolanQueryTranslator', function() {
"(operat|0|r f1:'k1' f2:'k2')",
"invalid operator character: <0>");

testGroupError("field: garbage after value",
"(field f1 'k1' 'garbage')",
"(field f1 'k1' |'|garbage')",
"a garbage character after value: <'>");

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

0 comments on commit 8b79209

Please sign in to comment.