[Groonga-commit] groonga/gcs [master] bq: add validation for invalid (not ...) syntax

Back to archive index

Kouhei Sutou null+****@clear*****
Tue Aug 28 12:57:18 JST 2012


Kouhei Sutou	2012-08-28 12:57:18 +0900 (Tue, 28 Aug 2012)

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

  Log:
    bq: add validation for invalid (not ...) syntax

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

  Modified: lib/bq-translator.js (+11 -4)
===================================================================
--- lib/bq-translator.js    2012-08-28 12:51:02 +0900 (7d1fed6)
+++ lib/bq-translator.js    2012-08-28 12:57:18 +0900 (65ec6d3)
@@ -211,12 +211,19 @@ BooleanQueryTranslator.prototype = {
   translateGroupNot: function() {
     var expression = this.translateExpression();
     this.skipSpaces();
-    if (this.query[this.offset] == ")") {
-      this.offset++;
-      return "(all_records() &! " + expression + ")";
-    } else {
+
+    if (this.offset == this.query.length) {
       this.throwSyntaxError("close parenthesis is missing: operator:<not>");
     }
+
+    var character = this.query[this.offset];
+    if (character != ")") {
+      this.throwSyntaxError("a garbage character after value: " +
+                            "<" + character + ">");
+    }
+
+    this.offset++;
+    return "(all_records() &! " + expression + ")";
   },
   translateExpression: function() {
     if (this.query[this.offset] == "(") {

  Modified: test/bq-translator.test.js (+9 -0)
===================================================================
--- test/bq-translator.test.js    2012-08-28 12:51:02 +0900 (43bf265)
+++ test/bq-translator.test.js    2012-08-28 12:57:18 +0900 (3a24bc1)
@@ -323,6 +323,15 @@ suite('BoolanQueryTranslator', function() {
                  "(and field1:'k1' field2:'k2'||",
                  "close parenthesis is missing: operator:<and>");
 
+  testGroupError("not: garbage after value",
+                 "(not field1:'k1' field2:'k2')",
+                 "(not field1:'k1' |f|ield2:'k2')",
+                 "a garbage character after value: <f>");
+  testGroupError("not: missing close parentheis",
+                 "(not field1:'k1'",
+                 "(not field1:'k1'||",
+                 "close parenthesis is missing: operator:<not>");
+
   testExpression("value only: stirng: and: space",
                  "'keyword1 keyword2' 'other keyword'",
                  "'keyword1 keyword2'".length,
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index