Kouhei Sutou
null+****@clear*****
Sun Mar 2 15:17:46 JST 2014
Kouhei Sutou 2014-03-02 15:17:46 +0900 (Sun, 02 Mar 2014) New Revision: 2cc3378d411b82bdc5ef186cd370f09ad9b066e2 https://github.com/groonga/gcs/commit/2cc3378d411b82bdc5ef186cd370f09ad9b066e2 Message: bq: fix wrong valid character check "-" is invalid character and "_" is valid character. GitHub: fix #142 Reported by zjx20. Thanks!!! Modified files: lib/bq-translator.js test/bq-translator.test.js Modified: lib/bq-translator.js (+9 -3) =================================================================== --- lib/bq-translator.js 2014-03-02 14:55:38 +0900 (65ec6d3) +++ lib/bq-translator.js 2014-03-02 15:17:46 +0900 (90054ae) @@ -133,7 +133,10 @@ BooleanQueryTranslator.prototype = { var field = ""; for (; this.offset < this.query.length; this.offset++) { var character = this.query[this.offset]; - if (/^[\-a-z0-9]$/.test(character)) { + if (/^[a-z0-9_]$/.test(character)) { + if (field.length == 0 && character == "_") { + this.throwSyntaxError("field name should not start with under score"); + } field += character; } else if (character == " ") { this.skipSpaces(); @@ -165,7 +168,10 @@ BooleanQueryTranslator.prototype = { var field = ""; for (; this.offset < this.query.length; this.offset++) { var character = this.query[this.offset]; - if (/^[\-a-z0-9]$/.test(character)) { + if (/^[a-z0-9_]$/.test(character)) { + if (field.length == 0 && character == "_") { + this.throwSyntaxError("field name should not start with under score"); + } field += character; } else if (character == " ") { this.skipSpaces(); @@ -236,7 +242,7 @@ BooleanQueryTranslator.prototype = { field = ""; for (; this.offset < this.query.length; this.offset++) { var character = this.query[this.offset]; - if (!/^[\-a-z0-9]$/.test(character)) { + if (!/^[a-z0-9_]$/.test(character)) { break; } field += character; Modified: test/bq-translator.test.js (+11 -2) =================================================================== --- test/bq-translator.test.js 2014-03-02 14:55:38 +0900 (3a59f48) +++ test/bq-translator.test.js 2014-03-02 15:17:46 +0900 (950c682) @@ -173,7 +173,8 @@ suite('BoolanQueryTranslator', function() { 'field', 'field1', 'field2', - 'field3' + 'field3', + 'field_name' ].forEach(function(field) { domain.getIndexField(field).setType('text') .setFacetEnabled(true).setSearchEnabled(true).createSync(); @@ -212,6 +213,10 @@ suite('BoolanQueryTranslator', function() { "(label 'keyword1 keyword2')", 'field @ "keyword1" && field @ "keyword2"'); + testQuery("field: valid: _", + "field_name:'keyword'", + 'field_name @ "keyword"'); + testQueryError("garbage", "(and 'keyword' type:'ModelName') garbage1 garbage2", "(and 'keyword' type:'ModelName')| |garbage1 garbage2", @@ -288,10 +293,14 @@ suite('BoolanQueryTranslator', function() { "(field field1 29)", "(field field1 |2|9)", "open single quote for string value is missing"); - testGroupError("field: invalid field name", + testGroupError("field: invalid field name: upper case", "(field fIeld 'value')", "(field f|I|eld 'value')", "invalid field character: <I>"); + testGroupError("field: invalid field name: -", + "(field field-name 'value')", + "(field field|-|name 'value')", + "invalid field character: <->"); testGroupError("field: missing close parenthesis", "(field ", "(field ||", -------------- next part -------------- HTML����������������������������... Download