sparklemotion / nokogiri

Nokogiri (鋸) makes it easy and painless to work with XML and HTML from Ruby.
https://nokogiri.org/
MIT License
6.16k stars 904 forks source link

Runtime error when calling to_html #1440

Closed larcara closed 7 years ago

larcara commented 8 years ago

Hi have a problem similar issue #1281 ,but i can reproduce the error whit this snippet:

require 'nokogiri'
html_fragment=<<-eos
  <img width="16" height="16"  src="/icons/graycol.gif" border="0" alt="Inactive hide details for &quot;User&quot; ---19/05/2015 12:55:29---Provvediamo subito nell&#8217;integrare">
eos
doc = Nokogiri::HTML(html_fragment,nil,"ISO-8859-1")
doc.to_html

using

jruby 1.7.19 (1.9.3p551) 2015-01-29 20786bd on OpenJDK 64-Bit Server VM 1.7.0_95-b00 +jit [linux-amd64]

i obtain this error:

RuntimeError: Input length = 1 native_write_to at nokogiri/XmlNode.java:1217 write_to at /usr/local/rvm/gems/jruby-1.7.19/gems/nokogiri-1.6.6.2-java/lib/nokogiri/xml/node.rb:686 serialize at /usr/local/rvm/gems/jruby-1.7.19/gems/nokogiri-1.6.6.2-java/lib/nokogiri/xml/node.rb:618 serialize at /usr/local/rvm/gems/jruby-1.7.19/gems/nokogiri-1.6.6.2-java/lib/nokogiri/html/document.rb:144 to_format at /usr/local/rvm/gems/jruby-1.7.19/gems/nokogiri-1.6.6.2-java/lib/nokogiri/xml/node.rb:774 to_html at /usr/local/rvm/gems/jruby-1.7.19/gems/nokogiri-1.6.6.2-java/lib/nokogiri/xml/node.rb:630

flavorjones commented 8 years ago

I've reproduced this on my Linux machine using Nokogiri 1.6.7.2:

nokoRuntimeError: Input length = 1
  native_write_to at nokogiri/XmlNode.java:1255
         write_to at /home/flavorjones/.rvm/gems/jruby-9.0.4.0/gems/nokogiri-1.6.8.rc3-java/lib/nokogiri/xml/node.rb:698
        serialize at /home/flavorjones/.rvm/gems/jruby-9.0.4.0/gems/nokogiri-1.6.8.rc3-java/lib/nokogiri/xml/node.rb:630
        serialize at /home/flavorjones/.rvm/gems/jruby-9.0.4.0/gems/nokogiri-1.6.8.rc3-java/lib/nokogiri/html/document.rb:144
        to_format at /home/flavorjones/.rvm/gems/jruby-9.0.4.0/gems/nokogiri-1.6.8.rc3-java/lib/nokogiri/xml/node.rb:786
          to_html at /home/flavorjones/.rvm/gems/jruby-9.0.4.0/gems/nokogiri-1.6.8.rc3-java/lib/nokogiri/xml/node.rb:642
            <top> at /home/flavorjones/foo.rb:10

System snapshot:

$ nokogiri -v
# Nokogiri (1.6.7.2)
    ---
    warnings: []
    nokogiri: 1.6.7.2
    ruby:
      version: 2.2.2
      platform: java
      description: jruby 9.0.4.0 (2.2.2) 2015-11-12 b9fb7aa OpenJDK 64-Bit Server VM 24.95-b01 on 1.7.0_95-b00 [linux-amd64]
      engine: jruby
      jruby: 9.0.4.0
    xerces: Xerces-J 2.9.0
    nekohtml: NekoHTML 1.9.12

And same result with 1.6.8.rc3:

# Nokogiri (1.6.8.rc3)
    ---
    warnings: []
    nokogiri: 1.6.8.rc3
    ruby:
      version: 2.2.2
      platform: java
      description: jruby 9.0.4.0 (2.2.2) 2015-11-12 b9fb7aa OpenJDK 64-Bit Server VM 24.95-b01 on 1.7.0_95-b00 [linux-amd64]
      engine: jruby
      jruby: 9.0.4.0
    xerces: Xerces-J 2.11.0
    nekohtml: NekoHTML 1.9.21
olleolleolle commented 8 years ago

The reproduce still holds, on JRuby 9.1.5.0 on nokogiri 1.6.8.1:

$ ruby t.rb
RuntimeError: Input length = 1
  native_write_to at nokogiri/XmlNode.java:1274
         write_to at /Users/olle/.rvm/gems/jruby-9.1.5.0/gems/nokogiri-1.6.8.1-java/lib/nokogiri/xml/node.rb:698
        serialize at /Users/olle/.rvm/gems/jruby-9.1.5.0/gems/nokogiri-1.6.8.1-java/lib/nokogiri/xml/node.rb:630
        serialize at /Users/olle/.rvm/gems/jruby-9.1.5.0/gems/nokogiri-1.6.8.1-java/lib/nokogiri/html/document.rb:144
        to_format at /Users/olle/.rvm/gems/jruby-9.1.5.0/gems/nokogiri-1.6.8.1-java/lib/nokogiri/xml/node.rb:786
          to_html at /Users/olle/.rvm/gems/jruby-9.1.5.0/gems/nokogiri-1.6.8.1-java/lib/nokogiri/xml/node.rb:642
           <main> at t.rb:6
 $ nokogiri -v
# Nokogiri (1.6.8.1)
    ---
    warnings: []
    nokogiri: 1.6.8.1
    ruby:
      version: 2.3.1
      platform: java
      description: jruby 9.1.5.0 (2.3.1) 2016-09-07 036ce39 Java HotSpot(TM) 64-Bit Server VM 25.92-b14 on 1.8.0_92-b14 +jit [darwin-x86_64]
      engine: jruby
      jruby: 9.1.5.0
    xerces: Xerces-J 2.11.0
    nekohtml: NekoHTML 1.9.21
flavorjones commented 7 years ago

@kares has submitted a fix for this in #1597

flavorjones commented 7 years ago

Fixed in master, will be in v1.7.1.