[Groonga-commit] groonga/gcs [master] bq: throw exception for no escaped value

Back to archive index

null+****@clear***** null+****@clear*****
2012年 8月 6日 (月) 14:53:05 JST


Kouhei Sutou	2012-08-06 14:53:05 +0900 (Mon, 06 Aug 2012)

  New Revision: f0248478311847a2f3826bdc2b12d4c7f810a02f
  https://github.com/groonga/gcs/commit/f0248478311847a2f3826bdc2b12d4c7f810a02f

  Log:
    bq: throw exception for no escaped value

  Modified files:
    lib/bq-translator.js
    test/bq-translator.test.js

  Modified: lib/bq-translator.js (+7 -2)
===================================================================
--- lib/bq-translator.js    2012-08-06 14:52:34 +0900 (70347d8)
+++ lib/bq-translator.js    2012-08-06 14:53:05 +0900 (d04011c)
@@ -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 == "\"") {
@@ -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 == "\"") {

  Modified: test/bq-translator.test.js (+8 -0)
===================================================================
--- test/bq-translator.test.js    2012-08-06 14:52:34 +0900 (78ae0a9)
+++ test/bq-translator.test.js    2012-08-06 14:53:05 +0900 (6a2d528)
@@ -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");
 });
-------------- next part --------------
HTML$B$NE:IU%U%!%$%k$rJ]4I$7$^$7$?(B...
Download 



Groonga-commit メーリングリストの案内
Back to archive index