diff --git a/lib/json/stream/buffer.rb b/lib/json/stream/buffer.rb index cbefd8b..f9d9413 100644 --- a/lib/json/stream/buffer.rb +++ b/lib/json/stream/buffer.rb @@ -29,7 +29,7 @@ def initialize def <<(data) # Avoid state machine for complete UTF-8. if @buffer.empty? - data.force_encoding(Encoding::UTF_8) + data = (+data).force_encoding(Encoding::UTF_8) return data if data.valid_encoding? end diff --git a/lib/json/stream/parser.rb b/lib/json/stream/parser.rb index 33e7925..fbf51f5 100644 --- a/lib/json/stream/parser.rb +++ b/lib/json/stream/parser.rb @@ -102,8 +102,8 @@ def initialize(&block) # Track parse stack. @stack = [] - @unicode = "" - @buf = "" + @unicode = +"" + @buf = +"" @pos = -1 # Register any observers in the block. @@ -178,7 +178,7 @@ def <<(data) @state = :end_key notify(:key, @buf) end - @buf = "" + @buf = +"" when BACKSLASH @state = :start_escape when CONTROL @@ -270,7 +270,7 @@ def <<(data) @buf << ch else end_value(@buf.to_i) - @buf = "" + @buf = +"" @pos -= 1 redo end @@ -291,7 +291,7 @@ def <<(data) @buf << ch else end_value(@buf.to_f) - @buf = "" + @buf = +"" @pos -= 1 redo end @@ -310,7 +310,7 @@ def <<(data) else error('Expected 0-9 digit') unless @buf =~ DIGIT_END end_value(@buf.to_f) - @buf = "" + @buf = +"" @pos -= 1 redo end @@ -326,7 +326,7 @@ def <<(data) @buf << ch else end_value(@buf.to_i) - @buf = "" + @buf = +"" @pos -= 1 redo end @@ -503,7 +503,7 @@ def keyword(word, value, re, ch) if @buf.size == word.size if @buf == word - @buf = "" + @buf = +"" end_value(value) else error("Expected #{word} keyword")