Kouhei Sutou
null+****@clear*****
Tue Apr 8 18:05:43 JST 2014
Kouhei Sutou 2014-04-08 18:05:43 +0900 (Tue, 08 Apr 2014) New Revision: 6b1ccff56636ba371226c76f78ba1ad6bfc41781 https://github.com/droonga/fluent-plugin-droonga/commit/6b1ccff56636ba371226c76f78ba1ad6bfc41781 Message: search: add invalid attribute value check Added files: test/command/suite/search/output/attributes/invalid.catalog.json test/command/suite/search/output/attributes/invalid.expected test/command/suite/search/output/attributes/invalid.test Modified files: lib/droonga/searcher.rb Modified: lib/droonga/searcher.rb (+15 -1) =================================================================== --- lib/droonga/searcher.rb 2014-04-08 17:51:38 +0900 (cac2e0f) +++ lib/droonga/searcher.rb 2014-04-08 18:05:43 +0900 (9c21134) @@ -54,6 +54,16 @@ module Droonga end end + class InvalidAttribute < ErrorMessages::BadRequest + attr_reader :attribute + def initialize(attribute) + detail = { + "attribute" => attribute, + } + super("Invalid attribute: <#{attribute}>", detail) + end + end + def initialize(context) @context = context end @@ -658,7 +668,11 @@ module Droonga else expression = Groonga::Expression.new(context: @request.context) variable = expression.define_variable(domain: domain) - expression.parse(source, syntax: :script) + begin + expression.parse(source, syntax: :script) + rescue Groonga::SyntaxError + raise InvalidAttribute.new(source) + end condition = expression.define_variable(name: "$condition", reference: true) condition.value =****@resul***** Added: test/command/suite/search/output/attributes/invalid.catalog.json (+13 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/search/output/attributes/invalid.catalog.json 2014-04-08 18:05:43 +0900 (295bb90) @@ -0,0 +1,13 @@ +{ + "datasets": { + "Droonga": { + "fact": "Memos", + "schema": { + "Memos": { + "type": "Hash", + "keyType": "ShortText" + } + } + } + } +} Added: test/command/suite/search/output/attributes/invalid.expected (+48 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/search/output/attributes/invalid.expected 2014-04-08 18:05:43 +0900 (8fc2c16) @@ -0,0 +1,48 @@ +[ + "droonga.message", + 0, + { + "inReplyTo": "request-id", + "statusCode": 400, + "type": "search.result", + "body": { + "name": "InvalidAttribute", + "message": "Invalid attribute: <,>", + "detail": { + "attribute": "," + } + }, + "errors": { + "sources0": { + "statusCode": 400, + "body": { + "name": "InvalidAttribute", + "message": "Invalid attribute: <,>", + "detail": { + "attribute": "," + } + } + }, + "sources1": { + "statusCode": 400, + "body": { + "name": "InvalidAttribute", + "message": "Invalid attribute: <,>", + "detail": { + "attribute": "," + } + } + }, + "sources2": { + "statusCode": 400, + "body": { + "name": "InvalidAttribute", + "message": "Invalid attribute: <,>", + "detail": { + "attribute": "," + } + } + } + } + } +] Added: test/command/suite/search/output/attributes/invalid.test (+28 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/search/output/attributes/invalid.test 2014-04-08 18:05:43 +0900 (2f1c2f2) @@ -0,0 +1,28 @@ +# -*- js -*- +#@require-catalog-version 2 +#@disable-logging +{ + "type": "add", + "dataset": "Droonga", + "body": { + "table": "Memos", + "key": "Droonga is fun" + } +} +#@enable-logging +{ + "type": "search", + "dataset": "Droonga", + "body": { + "queries": { + "memos": { + "source": "Memos", + "output": { + "elements": ["attributes"], + "attributes": [","], + "limit": 10 + } + } + } + } +} -------------- next part -------------- HTML����������������������������...Download