From 7b6506a219d43ddc72919a23e119bb800d04a6e7 Mon Sep 17 00:00:00 2001 From: Kouhei Sutou Date: Tue, 31 Oct 2017 12:46:17 +0900 Subject: [PATCH] Add a error check for garbage after load --- lib/groonga/command/parser.rb | 5 +++++ test/test-parser.rb | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/lib/groonga/command/parser.rb b/lib/groonga/command/parser.rb index f1d1fe3..776f4d7 100644 --- a/lib/groonga/command/parser.rb +++ b/lib/groonga/command/parser.rb @@ -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? diff --git a/test/test-parser.rb b/test/test-parser.rb index 25726fe..8f74870 100644 --- a/test/test-parser.rb +++ b/test/test-parser.rb @@ -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