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

Nokogiri::XML::Attribute on JRuby returns a nil namespace #647

Closed
benlangfeld opened this issue Mar 31, 2012 · 6 comments
Closed

Nokogiri::XML::Attribute on JRuby returns a nil namespace #647

benlangfeld opened this issue Mar 31, 2012 · 6 comments

Comments

@benlangfeld
Copy link
Contributor

Running this against HEAD:

require 'nokogiri'

describe Nokogiri::XML::Node do
  subject { Nokogiri::XML.parse('<foo xml:bar="http://bar.com"/>').root }

  describe '#attributes' do
    it 'should include namespaces' do
      ns = subject.attributes['bar'].namespace
      ns.should_not be_nil
      ns.should be_a Nokogiri::XML::Namespace
      ns.prefix.should be == 'xml'
      ns.href.should be == "http://www.w3.org/XML/1998/namespace"
    end
  end
end

I get the following output on 1.9.3:

{10:45}[ruby-1.9.3]~/Desktop ben% be rspec spec.rb
.

Finished in 0.00414 seconds
1 example, 0 failures

And this on JRuby 1.6.7:

{10:44}[jruby-1.6.7]~/Desktop ben% be rspec spec.rb
F

Failures:

  1) Nokogiri::XML::Node#attributes should include namespaces
     Failure/Error: ns.should_not be_nil
       expected: not nil
            got: nil
     # ./spec.rb:9:in `(root)'

Finished in 0.205 seconds
1 example, 1 failure

Failed examples:

rspec ./spec.rb:7 # Nokogiri::XML::Node#attributes should include namespaces
bundle exec rspec spec.rb  25.34s user 1.27s system 249% cpu 10.675 total
@benlangfeld
Copy link
Contributor Author

Note that 1.4.7 is good, while 1.5.0 and later (including 1.5.3.rc3) are bad.

@yokolet
Copy link
Member

yokolet commented Mar 31, 2012

It looks parsing attribue doesn't build DOM correctly.

libxml

#<Nokogiri::XML::Element:0x8053c91c name="foo" attributes=[#<Nokogiri::XML::Attr:0x8
053c8b8 name="bar" namespace=#<Nokogiri::XML::Namespace:0x8053c6d8 prefix="xml" href
="http://www.w3.org/XML/1998/namespace"> value="http://bar.com">]>

JRuby

#<Nokogiri::XML::Element:0x7d8 name="foo" attributes=[#<Nokogiri::XML::Attr:0x7d6 name="bar" value="http://bar.com">]>

@benlangfeld
Copy link
Contributor Author

Indeed that is the case.

@yokolet
Copy link
Member

yokolet commented Mar 31, 2012

I fixed this issue in rev. 493425f .
As far as I run the given test, I don't see any failure. Also, the parsed document has the default namespace as in below:

#<Nokogiri::XML::Element:0x7d4 name="foo" attributes=[#<Nokogiri::XML::Attr:0x7d2 name="bar" namespace=#<Nokogiri::XML::Namespace:0x7d0 prefix="xml" href="http://www.w3.org/XML/1998/namespace"> value="http://bar.com">]>

If you have a chance, would you try master?

@benlangfeld
Copy link
Contributor Author

I can confirm this fixes the issue. Thanks once again yokolet.

@yokolet
Copy link
Member

yokolet commented Mar 31, 2012

No problem.

I'm sorry pure Java version bothered you so many times. I hope not, but if you encounter new one, please file again.

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