Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtime error when calling to_html #1440

Closed
larcara opened this issue Mar 3, 2016 · 4 comments
Closed

Runtime error when calling to_html #1440

larcara opened this issue Mar 3, 2016 · 4 comments
Milestone

Comments

@larcara
Copy link

larcara commented Mar 3, 2016

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
Copy link
Member

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
Copy link
Contributor

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

kares added a commit to kares/nokogiri that referenced this issue Jan 31, 2017
also faster due re-using a thread-cached encoder (resolves sparklemotion#1440)
kares added a commit to kares/nokogiri that referenced this issue Feb 10, 2017
also faster due re-using a thread-cached encoder (resolves sparklemotion#1440)
@flavorjones
Copy link
Member

@kares has submitted a fix for this in #1597

@flavorjones flavorjones added this to the 1.7.1 milestone Feb 10, 2017
@flavorjones
Copy link
Member

Fixed in master, will be in v1.7.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants