[Groonga-commit] groonga/gcs [master] q: support unterminated phrase check

Back to archive index

null+****@clear***** null+****@clear*****
2012年 8月 3日 (金) 22:33:29 JST


Kouhei Sutou	2012-08-03 22:33:29 +0900 (Fri, 03 Aug 2012)

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

  Log:
    q: support unterminated phrase check

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

  Modified: lib/q-translator.js (+7 -3)
===================================================================
--- lib/q-translator.js    2012-08-03 22:30:46 +0900 (0fc9657)
+++ lib/q-translator.js    2012-08-03 22:33:29 +0900 (5eca349)
@@ -55,7 +55,7 @@ QueryTranslator.prototype = {
       }
       phrase += character;
     }
-    this.throwTranslateError("phrase is unterminated");
+    this.throwTranslateError("phrase is unterminated: <" + phrase + ">");
   },
   translateTerm: function() {
     this.skipSpaces(this.query, this);
@@ -76,8 +76,12 @@ QueryTranslator.prototype = {
     var message = "";
     message += "<";
     message += this.query.substring(0, this.offset);
-    message += "|" + this.query[this.offset] + "|";
-    message += this.query.substring(this.offset + 1);
+    if (this.offset == this.query.length) {
+      message += "||";
+    } else {
+      message += "|" + this.query[this.offset] + "|";
+      message += this.query.substring(this.offset + 1);
+    }
     message += ">";
     message += ": " + detail;
     throw new Error(message);

  Modified: test/q-translator.test.js (+4 -0)
===================================================================
--- test/q-translator.test.js    2012-08-03 22:30:46 +0900 (fd7dcf0)
+++ test/q-translator.test.js    2012-08-03 22:33:29 +0900 (7c9e731)
@@ -98,6 +98,10 @@ suite('QueryTranslator', function() {
                       'star wars"',
                       '|s|tar wars"',
                       "phrase must start with <\">");
+  testPhraseTermError("not terminated",
+                      '"star wars',
+                      '"star wars||',
+                      "phrase is unterminated: <star wars>");
 
   testTerm("a term",
            "  star wars",
-------------- next part --------------
HTML$B$NE:IU%U%!%$%k$rJ]4I$7$^$7$?(B...
下载 



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