weshatheleopard / rubyXL

Ruby lib for reading/writing/modifying .xlsx and .xlsm files
MIT License
1.27k stars 253 forks source link

"Nokogiri::XML::SyntaxError (1:1: FATAL: Document is empty)" on parsing the buffer more than once #439

Open Nakilon opened 1 year ago

Nakilon commented 1 year ago
$ bundle exec irb -rrubyXL
irb> t = File.binread "temp.xlsx"
=> "PK\x03\x04\x14...
irb> RubyXL::Parser.parse_buffer t
=> #<RubyXL::Workbook:...
irb> RubyXL::Parser.parse_buffer t
Traceback (most recent call last):
...
        4: from .../rubyXL-3.4.25/lib/rubyXL/objects/ooxml_object.rb:116:in `parse'
        3: from .../nokogiri-1.12.5-x86_64-darwin/lib/nokogiri/xml.rb:36:in `parse'
        2: from .../nokogiri-1.12.5-x86_64-darwin/lib/nokogiri/xml/document.rb:72:in `parse'
        1: from .../nokogiri-1.12.5-x86_64-darwin/lib/nokogiri/xml/document.rb:72:in `read_io'
Nokogiri::XML::SyntaxError (1:1: FATAL: Document is empty)
$ ruby -v
ruby 2.5.9p229 (2021-04-05 revision 67939) [x86_64-darwin20]
$ bundle exec gem list rubyXL
rubyXL (3.4.25)
khiav223577 commented 1 year ago

I got the same error when parse file get different error message with different nokogiri version

nokogiri-1.14.3

Nokogiri::XML::SyntaxError:
       1:1: FATAL: Document is empty

nokogiri-1.15.4

Nokogiri::XML::SyntaxError:
       1:1: FATAL: Growing input buffer

I added --enable-frozen-string-literal to RUBYOPT, remove it will fix the problem. It looks like rubyXL doesn't support frozen-string-literal