Navigation Menu

Skip to content

Commit

Permalink
search: add invalid attribute value check
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Apr 8, 2014
1 parent 2f3869a commit 6b1ccff
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lib/droonga/searcher.rb
Expand Up @@ -54,6 +54,16 @@ def initialize(queries)
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
Expand Down Expand Up @@ -658,7 +668,11 @@ def normalize_target_attributes(attributes, domain = @result.records)
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 = @result.condition
Expand Down
13 changes: 13 additions & 0 deletions test/command/suite/search/output/attributes/invalid.catalog.json
@@ -0,0 +1,13 @@
{
"datasets": {
"Droonga": {
"fact": "Memos",
"schema": {
"Memos": {
"type": "Hash",
"keyType": "ShortText"
}
}
}
}
}
48 changes: 48 additions & 0 deletions test/command/suite/search/output/attributes/invalid.expected
@@ -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": ","
}
}
}
}
}
]
28 changes: 28 additions & 0 deletions test/command/suite/search/output/attributes/invalid.test
@@ -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
}
}
}
}
}

0 comments on commit 6b1ccff

Please sign in to comment.