Navigation Menu

Skip to content

Commit

Permalink
Fix infinite loop
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Oct 31, 2017
1 parent b63c051 commit f41279d
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lib/groonga/command/parser.rb
Expand Up @@ -358,7 +358,10 @@ def initialize_load_values_parser
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
Expand Down
53 changes: 52 additions & 1 deletion test/test-parser.rb
Expand Up @@ -341,7 +341,7 @@ def test_brace
end
end

def test_multiple
def test_multiple_bulk
@parser << <<-COMMANDS
load --table Users
[
Expand Down Expand Up @@ -387,6 +387,57 @@ def test_multiple
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"
Expand Down

0 comments on commit f41279d

Please sign in to comment.