Navigation Menu

Skip to content

Commit

Permalink
q: add unterminated \ escape check
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Aug 3, 2012
1 parent bc11ffb commit dd2a83b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/q-translator.js
Expand Up @@ -51,6 +51,9 @@ QueryTranslator.prototype = {
if (character == "\\") {
phrase += character;
this.offset++;
if (this.offset == this.query.length) {
this.throwTranslateError("escaped character is missing");
}
character = this.query[this.offset];
}
phrase += character;
Expand Down
4 changes: 4 additions & 0 deletions test/q-translator.test.js
Expand Up @@ -98,6 +98,10 @@ suite('QueryTranslator', function() {
'star wars"',
'|s|tar wars"',
"phrase must start with <\">");
testPhraseTermError("ended with <\\>",
'"star wars\\',
'"star wars\\||',
"escaped character is missing");
testPhraseTermError("not terminated",
'"star wars',
'"star wars||',
Expand Down

0 comments on commit dd2a83b

Please sign in to comment.