Navigation Menu

Skip to content

Commit

Permalink
bq: unsigned integer value only expression is invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Aug 14, 2012
1 parent 731c9d7 commit bc15018
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 27 deletions.
13 changes: 3 additions & 10 deletions lib/bq-translator.js
Expand Up @@ -194,17 +194,10 @@ BooleanQueryTranslator.prototype = {
}
field += character;
}
if (this.query[this.offset] == ":") {
this.offset++;
} else {
var is_unsigned_integer_value = /^[0-9]+$/.test(field);
if (is_unsigned_integer_value) {
field = this.defaultField;
this.offset = startOffset;
} else {
this.throwTranslateError("field value separator is missing");
}
if (this.query[this.offset] != ":") {
this.throwTranslateError("field value separator is missing");
}
this.offset++;
} else {
field = this.defaultField;
}
Expand Down
23 changes: 6 additions & 17 deletions test/bq-translator.test.js
Expand Up @@ -236,22 +236,6 @@ suite('BoolanQueryTranslator', function() {
"'\"keyword1 keyword2\"|\"keyword3\"' 'other keyword'",
"'\"keyword1 keyword2\"|\"keyword3\"'".length,
"field @ \"keyword1 keyword2\" || field @ \"keyword3\"");
testExpression("value only: unsigned integer",
"29 75",
"29".length,
"field == 29");
testExpression("value only: unsigned integer range: min only",
"29.. 75",
"29..".length,
"field >= 29");
testExpression("value only: unsigned integer range: max only",
"..29 75",
"..29".length,
"field <= 29");
testExpression("value only: unsigned integer range: min and max",
"14..29 75",
"14..29".length,
"(field >= 14 && field <= 29)");

testExpression("field value: string",
"field1:'keyword1 keyword2' field2:'other keyword'",
Expand All @@ -262,10 +246,15 @@ suite('BoolanQueryTranslator', function() {
"field1:29".length,
"field1 == 29");

testExpressionError("missing field value separator",
testExpressionError("missing field value separator: normal field name",
"f1 'k1'",
"f1| |'k1'",
"field value separator is missing");
testExpressionError("missing field value separator: " +
"unsigned integer like field name",
"29 75",
"29| |75",
"field value separator is missing");
testExpressionError("invalid value",
"f1:value",
"f1:|v|alue",
Expand Down

0 comments on commit bc15018

Please sign in to comment.