Kouhei Sutou
null+****@clear*****
Tue Oct 31 12:09:56 JST 2017
Kouhei Sutou 2017-10-31 12:09:56 +0900 (Tue, 31 Oct 2017) New Revision: f41279d35c120d6623882bf28ff9010e7f7e35c2 https://github.com/groonga/groonga-command-parser/commit/f41279d35c120d6623882bf28ff9010e7f7e35c2 Message: Fix infinite loop Modified files: lib/groonga/command/parser.rb test/test-parser.rb Modified: lib/groonga/command/parser.rb (+4 -1) =================================================================== --- lib/groonga/command/parser.rb 2017-10-30 16:58:08 +0900 (42dbe23) +++ lib/groonga/command/parser.rb 2017-10-31 12:09:56 +0900 (945222c) @@ -358,7 +358,10 @@ module Groonga end end @load_values_parser.on_consumed = lambda do |consumed| - @command.original_source << consumed if @loading + if @loading + @command.original_source << consumed + @buffer = @buffer[consumed.bytesize..-1] + end end @load_values_parser.on_end = lambda do |rest| loading = @loading Modified: test/test-parser.rb (+52 -1) =================================================================== --- test/test-parser.rb 2017-10-30 16:58:08 +0900 (07e9d89) +++ test/test-parser.rb 2017-10-31 12:09:56 +0900 (25726fe) @@ -341,7 +341,7 @@ load --table Users end end - def test_multiple + def test_multiple_bulk @parser << <<-COMMANDS load --table Users [ @@ -387,6 +387,57 @@ load --table Users assert_equal(expected_events, @events) end + def test_multiple_line + commands = <<-COMMANDS +load --table Users +[ +{"_key": "alice", "name": "Alice"} +] + +load --table Users +[ +{"_key": "bob", "name": "Bob"} +] + COMMANDS + commands.each_line do |line| + @parser << line + end + + expected_events = [] + + expected_events << [:load_start, <<-SOURCE.chomp] +load --table Users + SOURCE + value = {"_key" => "alice", "name" => "Alice"} + expected_events << [:load_value, <<-SOURCE, value] +load --table Users +[ + SOURCE + expected_events << [:load_complete, <<-SOURCE.chomp] +load --table Users +[ +{"_key": "alice", "name": "Alice"} +] + SOURCE + + expected_events << [:load_start, <<-SOURCE.chomp] +load --table Users + SOURCE + value = {"_key" => "bob", "name" => "Bob"} + expected_events << [:load_value, <<-SOURCE, value] +load --table Users +[ + SOURCE + expected_events << [:load_complete, <<-SOURCE.chomp] +load --table Users +[ +{"_key": "bob", "name": "Bob"} +] + SOURCE + + assert_equal(expected_events, @events) + end + class ErrorTest < self def test_location message = "record separate comma is missing" -------------- next part -------------- HTML����������������������������... URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20171031/8c21cc0c/attachment-0001.htm