Skip to content

Commit

Permalink
Add a error check for garbage after load
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Oct 31, 2017
1 parent b8abf42 commit 7b6506a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/groonga/command/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,11 @@ def parse_uri_path(relative_uri)
def parse_command_line(command_line)
splitter = CommandLineSplitter.new(command_line)
name, *arguments = splitter.split
if name.nil?
raise Error.new("invalid command name",
command_line,
"")
end
pair_arguments = {}
ordered_arguments = []
until arguments.empty?
Expand Down
15 changes: 15 additions & 0 deletions test/test-parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,21 @@ def test_garbage_before_json
JSON
end
end

def test_garbage_after_json
message = "invalid command name"
before = "\""
after = ""
error = Groonga::Command::Parser::Error.new(message, before, after)
assert_raise(error) do
@parser << <<-JSON
load --table Users
[
{"_key": "alice", "name": "Alice"}
]"
JSON
end
end
end
end

Expand Down

0 comments on commit 7b6506a

Please sign in to comment.