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

Prefixed element inconsistency between CRuby and JRuby #712

Closed
benlangfeld opened this issue Jun 25, 2012 · 4 comments
Closed

Prefixed element inconsistency between CRuby and JRuby #712

benlangfeld opened this issue Jun 25, 2012 · 4 comments

Comments

@benlangfeld
Copy link
Contributor

Affected ruby versions

  • JRuby
  • Ruby 1.9.3 (probably more)

Affected nokogiri versions

  • 1.5.x (including 1.5.5)

Test case

require 'nokogiri'

Foo = Class.new Nokogiri::XML::Node

shared_examples_for 'prefixed attributes' do
  let(:doc) { Nokogiri::XML::Document.new }

  subject { described_class.new 'foo', doc }

  it "should write attributes with prefixes and read them back" do
    subject[:'xml:lang'] = 'en-GB'
    subject[:'xml:lang'].should be == 'en-GB'
    subject[:'lang'].should be nil
  end
end

describe Nokogiri::XML::Node do
  it_should_behave_like 'prefixed attributes'
end

describe Foo do
  it_should_behave_like 'prefixed attributes'
end

Result

{11:11}[ruby-1.9.3]~/Desktop/nokogiri ben% be rspec spec/nokogiri_spec.rb
FF

Failures:

  1) Nokogiri::XML::Node it should behave like prefixed attributes should write attributes with prefixes and read them back
     Failure/Error: subject[:'xml:lang'].should be == 'en-GB'
       expected: == "en-GB"
            got:    nil
     Shared Example Group: "prefixed attributes" called from ./spec/nokogiri_spec.rb:18
     # ./spec/nokogiri_spec.rb:12:in `block (2 levels) in <top (required)>'

  2) Foo it should behave like prefixed attributes should write attributes with prefixes and read them back
     Failure/Error: subject[:'xml:lang'].should be == 'en-GB'
       expected: == "en-GB"
            got:    nil
     Shared Example Group: "prefixed attributes" called from ./spec/nokogiri_spec.rb:22
     # ./spec/nokogiri_spec.rb:12:in `block (2 levels) in <top (required)>'

Finished in 0.00519 seconds
2 examples, 2 failures

Failed examples:

rspec ./spec/nokogiri_spec.rb:10 # Nokogiri::XML::Node it should behave like prefixed attributes should write attributes with prefixes and read them back
rspec ./spec/nokogiri_spec.rb:10 # Foo it should behave like prefixed attributes should write attributes with prefixes and read them back

{11:11}[jruby-1.6.7.2]~/Desktop/nokogiri ben% be rspec spec/nokogiri_spec.rb
..

Finished in 0.241 seconds
2 examples, 0 failures
bundle exec rspec spec/nokogiri_spec.rb  26.21s user 1.06s system 258% cpu 10.569 total

I believe JRuby is behaving correctly here, and the C version is the one at fault.

benlangfeld added a commit to adhearsion/nokogiri that referenced this issue Jul 4, 2012
@benlangfeld
Copy link
Contributor Author

I'd like to garner some sort of consensus on the approach here before I attempt to make a fix. @flavorjones, @tenderlove: Would you agree that the behavior of JRuby is the correct one here?

@benlangfeld
Copy link
Contributor Author

I note that in this case, Ox follows the same semantics as Nokogiri on JRuby.

yokolet added a commit that referenced this issue Jul 8, 2012
…cessors

Merges failing test case for issue #712 and #695.

Thanks!
@benlangfeld
Copy link
Contributor Author

Things that behave like #['lang']:

  • libxml-ruby

Things that behave like #['xml:lang']:

  • Ox
  • Hpricot
  • XPath

In my mind, that brings it hands down in favour of qualifying namespace prefixes in attribute accessors. I shall prepare a patch.

@benlangfeld
Copy link
Contributor Author

Patch at #726 ready to be merged. Can someone take a look?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants