From 28edc7726f71dd29a3f2da246e47f2a0e6ec01c9 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Mon, 26 May 2014 00:33:20 +0200 Subject: [PATCH] Rewind IO input upon resetting the lexer. --- lib/oga/xml/lexer.rb | 2 ++ spec/oga/xml/lexer/io_spec.rb | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/lib/oga/xml/lexer.rb b/lib/oga/xml/lexer.rb index e3a3ac3..a4ffdcd 100644 --- a/lib/oga/xml/lexer.rb +++ b/lib/oga/xml/lexer.rb @@ -91,6 +91,8 @@ module Oga @line = 1 @elements = [] + @data.rewind if io_input? + reset_native end diff --git a/spec/oga/xml/lexer/io_spec.rb b/spec/oga/xml/lexer/io_spec.rb index d3a1a97..35c41b1 100644 --- a/spec/oga/xml/lexer/io_spec.rb +++ b/spec/oga/xml/lexer/io_spec.rb @@ -15,5 +15,12 @@ describe Oga::XML::Lexer do [:T_ELEM_END, nil, 2] ] end + + example 'rewind input when resetting the lexer' do + lexer = described_class.new(StringIO.new(('foo'))) + + lexer.lex.empty?.should == false + lexer.lex.empty?.should == false + end end end