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

Comments are formatted differently on mri and jruby #1962

Closed
jlahtinen opened this issue Jan 3, 2020 · 1 comment
Closed

Comments are formatted differently on mri and jruby #1962

jlahtinen opened this issue Jan 3, 2020 · 1 comment

Comments

@jlahtinen
Copy link

To Reproduce

#!/usr/bin/env ruby

require 'nokogiri'
require 'minitest/autorun'

# Test for reporting issue
class Test < MiniTest::Spec
  describe 'document#to_xml' do
    it 'formats comments' do
      expected_xml = <<~HEREDOC
        <!--test comment-->
        <root>test xml</root>
      HEREDOC

      doc = Nokogiri::XML::Builder.new do |xml|
        xml.comment 'test comment'
        xml.root 'test xml'
      end
      xml = doc.to_xml(save_with:
                       Nokogiri::XML::Node::SaveOptions::NO_DECLARATION)

      assert_equal expected_xml, xml
    end
  end
end

Expected behavior

with cruby and jruby

1 runs, 1 assertions, 0 failures, 0 errors, 0 skips

Actual behavior

with jruby

  1) Failure:
document#to_xml#test_0001_formats comments [./nokogiri-issue.rb:26]:
--- expected
+++ actual
@@ -1,3 +1 @@
-"<!--test comment-->
-<root>test xml</root>
-"
+"<!--test comment--><root>test xml</root>"

1 runs, 1 assertions, 1 failures, 0 errors, 0 skips

Additional context

# Nokogiri (1.10.7)
    ---
    warnings: []
    nokogiri: 1.10.7
    ruby:
      version: 2.6.5
      platform: x86_64-linux
      description: ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-linux]
      engine: ruby
    libxml:
      binding: extension
      source: packaged
      libxml2_path: "/home/jlahtinen/.rvm/gems/ruby-2.6.5/gems/nokogiri-1.10.7/ports/x86_64-pc-linux-gnu/libxml2/2.9.10"
      libxslt_path: "/home/jlahtinen/.rvm/gems/ruby-2.6.5/gems/nokogiri-1.10.7/ports/x86_64-pc-linux-gnu/libxslt/1.1.34"
      libxml2_patches:
      - 0001-Revert-Do-not-URI-escape-in-server-side-includes.patch
      - 0002-Remove-script-macro-support.patch
      - 0003-Update-entities-to-remove-handling-of-ssi.patch
      - 0004-libxml2.la-is-in-top_builddir.patch
      libxslt_patches: []
      compiled: 2.9.10
      loaded: 2.9.10
# Nokogiri (1.10.7)
    ---
    warnings: []
    nokogiri: 1.10.7
    ruby:
      version: 2.5.3
      platform: java
      description: jruby 9.2.8.0 (2.5.3) 2019-10-11 a1ac7ff OpenJDK 64-Bit Server VM 25.232-b09
        on 1.8.0_232-b09 +jit [linux-x86_64]
      engine: jruby
      jruby: 9.2.8.0
    xerces: Xerces-J 2.12.0
    nekohtml: NekoHTML 1.9.21
@flavorjones
Copy link
Member

Hi, @jlahtinen. Thanks for reporting this.

What you're seeing is a difference in how two different XML libraries parse and format documents. The JRuby implementation of Nokogiri uses Xerces, and the CRuby implementation uses libxml2. Nokogiri is a relatively thin wrapper on top of these libraries, and inherits all this behavior from them -- and so there's nothing we can easily do to change this behavior.

Sorry we can't do more here to help you.

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

2 participants