Navigation Menu

Skip to content

Commit

Permalink
bq: throw exception for no escaped value
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Aug 6, 2012
1 parent fe93722 commit f024847
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/bq-translator.js
Expand Up @@ -253,7 +253,10 @@ BooleanQueryTranslator.prototype = {
tokens.push("||");
} else if (character == "\\") {
this.offset++;
// TODO: check length
if (this.offset == this.query.length) {
this.throwTranslateError("escaped character is missing " +
"in string value");
}
character = this.query[this.offset];
value += character;
} else if (character == "\"") {
Expand Down Expand Up @@ -289,7 +292,9 @@ BooleanQueryTranslator.prototype = {
var character = this.query[this.offset];
if (character == "\\") {
this.offset++;
// TODO: check length
if (this.offset == this.query.length) {
this.throwTranslateError("escaped character is missing in phrase");
}
character = this.query[this.offset];
value += character;
} else if (character == "\"") {
Expand Down
8 changes: 8 additions & 0 deletions test/bq-translator.test.js
Expand Up @@ -280,4 +280,12 @@ suite('BoolanQueryTranslator', function() {
"'keyword1\"keyword2\"' 'other keyword'",
"'keyword1|\"|keyword2\"' 'other keyword'",
"operator is missing: keyword:<keyword1>");
testExpressionError("value only: stirng: missing escaped value",
"'keyword1\\",
"'keyword1\\||",
"escaped character is missing in string value");
testExpressionError("value only: phrase: missing escaped value",
"'\"keyword1\\",
"'\"keyword1\\||",
"escaped character is missing in phrase");
});

0 comments on commit f024847

Please sign in to comment.