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

`encode': no implicit conversion of nil into String (TypeError) #2784

Closed
deril opened this issue Feb 1, 2023 · 7 comments · Fixed by #2789
Closed

`encode': no implicit conversion of nil into String (TypeError) #2784

deril opened this issue Feb 1, 2023 · 7 comments · Fixed by #2789

Comments

@deril
Copy link

deril commented Feb 1, 2023

Please describe the bug

Nokogiri raises an error while trying to encode an empty string to nil encoding

Help us reproduce what you're seeing

#! /usr/bin/env ruby

require 'nokogiri'
require 'minitest/autorun'

class Test < MiniTest::Spec
  describe "Node#css" do
    it "should find a div using chained classes" do
      xml = "<root/>"
      
      doc = Nokogiri::XML(xml)
      node = doc.css(".node")
      
      assert_equal "", node.to_html
    end
  end
end

Expected behavior

nokogiri doesn't fail on converting to_html empty node set

Environment

# Nokogiri (1.14.1)
    ---
    warnings: []
    nokogiri:
      version: 1.14.1
      cppflags:
      - "-I/Users/deril/.frum/versions/3.1.3/lib/ruby/gems/3.1.0/gems/nokogiri-1.14.1-arm64-darwin/ext/nokogiri"
      - "-I/Users/deril/.frum/versions/3.1.3/lib/ruby/gems/3.1.0/gems/nokogiri-1.14.1-arm64-darwin/ext/nokogiri/include"
      - "-I/Users/deril/.frum/versions/3.1.3/lib/ruby/gems/3.1.0/gems/nokogiri-1.14.1-arm64-darwin/ext/nokogiri/include/libxml2"
      ldflags: []
    ruby:
      version: 3.1.3
      platform: arm64-darwin22
      gem_platform: arm64-darwin-22
      description: ruby 3.1.3p185 (2022-11-24 revision 1a6b16756e) [arm64-darwin22]
      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: "/Users/deril/.frum/versions/3.1.3/lib/ruby/gems/3.1.0/gems/nokogiri-1.14.1-arm64-darwin/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
      libiconv: '1.17'
      libgumbo: 1.0.0-nokogiri```
@deril deril added the state/needs-triage Inbox for non-installation-related bug reports or help requests label Feb 1, 2023
@flavorjones
Copy link
Member

@deril Thanks for reporting! I'll take a look.

@flavorjones
Copy link
Member

git bisect reveals the offending commit is a582143 from #2649 which first appeared in v1.14.0.

@flavorjones
Copy link
Member

This seems like it's straightforward to fix, but I want to take the time to explore edge cases a bit. Give me a few days!

@flavorjones flavorjones added topic/encoding and removed state/needs-triage Inbox for non-installation-related bug reports or help requests labels Feb 1, 2023
@flavorjones flavorjones added this to the v1.14.x patch releases milestone Feb 1, 2023
@flavorjones
Copy link
Member

#2789 is going through CI now. If that's green, I'll backport to v1.14.x and make a release this week.

@flavorjones
Copy link
Member

Backport is #2791.

@flavorjones
Copy link
Member

I'll probably ship v1.14.2 tomorrow with the fix for this. Thanks for your patience.

@flavorjones
Copy link
Member

v1.14.2 shipped yesterday!

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