Skip to content

Segfault when adding fragment in HTML::Builder and document has an xmlns attribute #3112

@bringel

Description

@bringel

Please describe the bug
I'm trying to build up a document to be added to an ePub file using Nokogiri::HTML::Builder. When I try to add the string of html inside the body doing doc << article[:text], the program crashes if I've added an xmlns attribute to root html node, but not if I leave that off. It's not super important to me that the namespace be there, but it is very odd

Help us reproduce what you're seeing
I'm adding the article text from this page. If I create my document like this:

Nokgiri::HTML::Builder do |doc|
  doc.html(xmlns: "http://www.w3.org/1999/xhtml") {
     ...
    doc.body {
      doc << article[:text]
    }
  }
end

then the program crashes, if I leave off the xmlns attribute, then it works fine.

Expected behavior

Environment

# Nokogiri (1.16.0)
    ---
    warnings: []
    nokogiri:
      version: 1.16.0
      cppflags:
      - "-I/Users/bringel/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/nokogiri-1.16.0-x86_64-darwin/ext/nokogiri"
      - "-I/Users/bringel/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/nokogiri-1.16.0-x86_64-darwin/ext/nokogiri/include"
      - "-I/Users/bringel/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/nokogiri-1.16.0-x86_64-darwin/ext/nokogiri/include/libxml2"
      ldflags: []
    ruby:
      version: 3.1.2
      platform: x86_64-darwin21
      gem_platform: x86_64-darwin-21
      description: ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-darwin21]
      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'
      - 0010-update-config.guess-and-config.sub-for-libxml2.patch
      - 0011-rip-out-libxml2-s-libc_single_threaded-support.patch
      memory_management: ruby
      iconv_enabled: true
      compiled: 2.12.3
      loaded: 2.12.3
    libxslt:
      source: packaged
      precompiled: true
      patches:
      - 0001-update-config.guess-and-config.sub-for-libxslt.patch
      datetime_enabled: true
      compiled: 1.1.39
      loaded: 1.1.39
    other_libraries:
      zlib: '1.3'
      libiconv: '1.17'
      libgumbo: 1.0.0-nokogiri

Additional context

ruby-2024-01-28-125803.txt

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions