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

[bug] native_write_to: no implicit conversion of nil into String #2752

Closed
larskanis opened this issue Jan 4, 2023 · 1 comment · Fixed by #2753
Closed

[bug] native_write_to: no implicit conversion of nil into String #2752

larskanis opened this issue Jan 4, 2023 · 1 comment · Fixed by #2753

Comments

@larskanis
Copy link
Member

Please describe the bug

XML::Node#write_to fails with no implicit conversion of nil into String

Happens on nokogiri-1.14.0-rc1 on Linux and Windows with binary gems, but not on nokogiri-1.13.10 or older versions.

Help us reproduce what you're seeing

doc=Nokogiri::XML("")
File.open("filename", "w") do |fd|
  doc.write_to(fd, :indent => 2)
end

With nokogiri-1.14.0-rc1:

/home/local/COMCARD-NT/kanis/.rvm/gems/ruby-3.1.3/gems/nokogiri-1.14.0.rc1-x86_64-linux/lib/nokogiri/xml/node.rb:1368:in `native_write_to': no implicit conversion of nil into String (TypeError)
	from /home/local/COMCARD-NT/kanis/.rvm/gems/ruby-3.1.3/gems/nokogiri-1.14.0.rc1-x86_64-linux/lib/nokogiri/xml/node.rb:1368:in `write_to'
        from /home/local/COMCARD-NT/kanis/.rvm/gems/ruby-3.1.3/gems/nokogiri-1.14.0.rc1-x86_64-linux/lib/nokogiri/html5/node.rb:37:in `write_to'
	from (irb):1:in `block in <top (required)>'
	from (irb):1:in `open'
	from (irb):1:in `<main>'
	from /home/local/COMCARD-NT/kanis/.rvm/rubies/ruby-3.1.3/lib/ruby/gems/3.1.0/gems/irb-1.4.1/exe/irb:11:in `<top (required)>'
	from /home/local/COMCARD-NT/kanis/.rvm/rubies/ruby-3.1.3/bin/irb:25:in `load'
	from /home/local/COMCARD-NT/kanis/.rvm/rubies/ruby-3.1.3/bin/irb:25:in `<main>'

Expected behavior

The script should write a file "filename" with content

<?xml version="1.0"?>

Environment

$ nokogiri -v
# Nokogiri (1.14.0.rc1)
    ---
    warnings: []
    nokogiri:
      version: 1.14.0.rc1
      cppflags:
      - "-I/home/local/COMCARD-NT/kanis/.rvm/gems/ruby-3.1.3/gems/nokogiri-1.14.0.rc1-x86_64-linux/ext/nokogiri"
      - "-I/home/local/COMCARD-NT/kanis/.rvm/gems/ruby-3.1.3/gems/nokogiri-1.14.0.rc1-x86_64-linux/ext/nokogiri/include"
      - "-I/home/local/COMCARD-NT/kanis/.rvm/gems/ruby-3.1.3/gems/nokogiri-1.14.0.rc1-x86_64-linux/ext/nokogiri/include/libxml2"
      ldflags: []
    ruby:
      version: 3.1.3
      platform: x86_64-linux
      gem_platform: x86_64-linux
      description: ruby 3.1.3p185 (2022-11-24 revision 1a6b16756e) [x86_64-linux]
      engine: ruby
    libxml:
      source: packaged
      precompiled: true
      patches:
      - 0001-Remove-script-macro-support.patch
      - 0002-Update-entities-to-remove-handling-of-ssi.patch
      - 0003-libxml2.la-is-in-top_builddir.patch
      - '0009-allow-wildcard-namespaces.patch'
      libxml2_path: "/home/local/COMCARD-NT/kanis/.rvm/gems/ruby-3.1.3/gems/nokogiri-1.14.0.rc1-x86_64-linux/ext/nokogiri"
      memory_management: ruby
      iconv_enabled: true
      compiled: 2.10.3
      loaded: 2.10.3
    libxslt:
      source: packaged
      precompiled: true
      patches:
      - 0001-update-automake-files-for-arm64.patch
      datetime_enabled: true
      compiled: 1.1.37
      loaded: 1.1.37
    other_libraries:
      zlib: 1.2.13
      libgumbo: 1.0.0-nokogiri

Additional context

@larskanis larskanis added the state/needs-triage Inbox for non-installation-related bug reports or help requests label Jan 4, 2023
@flavorjones
Copy link
Member

Thanks for reporting! I'll take a look as soon as I can.

larskanis added a commit to larskanis/nokogiri that referenced this issue Jan 4, 2023
A file-IO has no external_encoding by default, so that rb_to_encoding() fails with a TypeError.

This regression was introduces in commit 2e260f5.

Fixes sparklemotion#2752
flavorjones added a commit to larskanis/nokogiri that referenced this issue Jan 4, 2023
A file-IO has no external_encoding by default, so that rb_to_encoding() fails with a TypeError.

This regression was introduces in commit 2e260f5.

Fixes sparklemotion#2752

Co-authored-by: Mike Dalessio <mike.dalessio@gmail.com>
@flavorjones flavorjones added topic/encoding and removed state/needs-triage Inbox for non-installation-related bug reports or help requests labels Jan 4, 2023
@flavorjones flavorjones added this to the v1.14.0 milestone Jan 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants