Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Demonstration for behavior difference between Nokogiri-C and Nokogiri-J for empty attributes in 1.5.6.
require 'rubygems'
gem 'nokogiri', ENV['NOKOGIRI_VERSION'] || '1.5.6'
require 'nokogiri'
n = Nokogiri::XML('<foo empty="" whitespace=" "/>')
puts " Ruby: #{RUBY_DESCRIPTION}"
puts "Nokogiri: #{Nokogiri::VERSION}"
puts
puts " Empty attribute value: #{n.root['empty'].inspect}"
puts "Whitespace-only attribute value: #{n.root['whitespace'].inspect}"

1.5.5 on MRI:

    Ruby: ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-darwin11.4.2]
Nokogiri: 1.5.5

          Empty attribute value: ""
Whitespace-only attribute value: "  "

1.5.6 on MRI:

    Ruby: ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-darwin11.4.2]
Nokogiri: 1.5.6

          Empty attribute value: ""
Whitespace-only attribute value: "  "

1.5.5 under JRuby (same as MRI):

    Ruby: jruby 1.7.1 (1.9.3p327) 2012-12-03 30a153b on Java HotSpot(TM) 64-Bit Server VM 1.6.0_29-b11-402-11E2068 [darwin-x86_64]
Nokogiri: 1.5.5

          Empty attribute value: ""
Whitespace-only attribute value: "  "

1.5.6 under JRuby (regressed):

    Ruby: jruby 1.7.1 (1.9.3p327) 2012-12-03 30a153b on Java HotSpot(TM) 64-Bit Server VM 1.6.0_29-b11-402-11E2068 [darwin-x86_64]
Nokogiri: 1.5.6

          Empty attribute value: nil
Whitespace-only attribute value: "  "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.