ohler55/ox — pull request #35 by mcarpenter (2013-01-25 11:21:08+00:00)
Title: #text on empty element + small Solaris fix

Hi,

I think I found a small bug with #text on empty elements. Minimal test case:

$ gem list ox

*** LOCAL GEMS ***

ox (1.8.3, 1.8.0)
$ irb
irb(main):001:0> RUBY_VERSION
=> "1.9.2"
irb(main):002:0> require 'ox'
=> true
irb(main):003:0> foo = Ox.parse('').locate('foo').first
=> #
irb(main):004:0> foo.text
NoMethodError: undefined method `each' for nil:NilClass
from /var/lib/gems/1.9.1/gems/ox-1.8.3/lib/ox/element.rb:82:in `text'
from (irb):4
from /usr/bin/irb:12:in `

'
irb(main):005:0>
$

The problem is that the `#text` method directly accesses the `@nodes` instance variable whereas instead using the accessor `#nodes` guards against the instance variable being `nil`.

The patched `#text` returns `nil` on empty elements which I think makes sense.

One other small fix included in `extconf.rb` when building on Solaris. The compiler whined due to missing prototype for `stpncpy(3)`. This this function does not exist in Solaris 10 (it is however in Solaris 11; Solaris 9 is nearly extinct so I didn't include this).

You may want to use more fussy compiler flags to catch this sort of issue in the future (weak binding did not cause hard compile error).

Thanks!