Basically I ask for a node with Xpath as follows:
cp:ruleset/cp:rule/cp:conditions/cp:identity/namespace::*
It *only* crahses if I try to printf the returned nodeset:
doc_xml = parse(doc)
nodeset = doc_xml.xpath(xpath, ns)
puts "nodeset = \n#{nodeset.to_s}" <--- CRASH
I know that "namespace::*" is not a Xpath feature, but it shouldn't
crash due to it :)
Using Ruby 1.9.1p129 it also crashes:
/usr/local/lib/ruby1.9/gems/1.9.1/gems/nokogiri-1.4.0/lib/nokogiri/xml/node_set.rb:238:
[BUG] Segmentation fault
ruby 1.9.1p129 (2009-05-12 revision 23412) [i686-linux]
-- control frame ----------
c:0041 p:0011 s:0180 b:0179 l:00003c d:000178 BLOCK
/usr/local/lib/ruby1.9/gems/1.9.1/gems/nokogiri-1.4.0/lib/nokogiri/xml/node_set.rb:238
c:0040 p:---- s:0176 b:0176 l:000175 d:000175 FINISH
c:0039 p:---- s:0174 b:0174 l:0005e0 d:000173 IFUNC :[]
c:0038 p:0015 s:0172 b:0171 l:000161 d:000170 BLOCK
/usr/local/lib/ruby1.9/gems/1.9.1/gems/nokogiri-1.4.0/lib/nokogiri/xml/node_set.rb:207
c:0037 p:---- s:0168 b:0168 l:000167 d:000167 FINISH
c:0036 p:---- s:0166 b:0166 l:000165 d:000165 CFUNC :upto
c:0035 p:0022 s:0162 b:0162 l:000161 d:000161 METHOD
/usr/local/lib/ruby1.9/gems/1.9.1/gems/nokogiri-1.4.0/lib/nokogiri/xml/node_set.rb:206
c:0034 p:---- s:0158 b:0158 l:000157 d:000157 FINISH
c:0033 p:---- s:0156 b:0156 l:0005e0 d:0005e0 CFUNC :map
c:0032 p:0011 s:0153 b:0153 l:00003c d:00003c METHOD
/usr/local/lib/ruby1.9/gems/1.9.1/gems/nokogiri-1.4.0/lib/nokogiri/xml/node_set.rb:238
-- Ruby level backtrace information-----------------------------------------
/usr/local/lib/ruby1.9/gems/1.9.1/gems/nokogiri-1.4.0/lib/nokogiri/xml/node_set.rb:238:in
`block in to_s'
/usr/local/lib/ruby1.9/gems/1.9.1/gems/nokogiri-1.4.0/lib/nokogiri/xml/node_set.rb:207:in
`block in each'
/usr/local/lib/ruby1.9/gems/1.9.1/gems/nokogiri-1.4.0/lib/nokogiri/xml/node_set.rb:206:in
`upto'
/usr/local/lib/ruby1.9/gems/1.9.1/gems/nokogiri-1.4.0/lib/nokogiri/xml/node_set.rb:206:in
`each'
/usr/local/lib/ruby1.9/gems/1.9.1/gems/nokogiri-1.4.0/lib/nokogiri/xml/node_set.rb:238:in
`map'
/usr/local/lib/ruby1.9/gems/1.9.1/gems/nokogiri-1.4.0/lib/nokogiri/xml/node_set.rb:238:in
`to_s'
--
Iñaki Baz Castillo
<i...@aliax.net>
Interesting. Do you have sample XML we can use to reproduce the problem?
--
Aaron Patterson
http://tenderlovemaking.com/
Yes, I'll try to get it and post it during these days.
A working example (for 1.8 and 1.9):
nokogiri_02.rb:
----------------------------------------------------------------
#!/usr/bin/env ruby
require "rubygems"
require "nokogiri"
XML_PARSE_OPTIONS = \
Nokogiri::XML::ParseOptions::NONET + \
Nokogiri::XML::ParseOptions::NOERROR
NS = {"pr"=>"urn:ietf:params:xml:ns:pres-rules",
"cp"=>"urn:ietf:params:xml:ns:common-policy"}
PRES_RULES = <<-EOF
<?xml version='1.0' encoding='UTF-8'?>
<cp:ruleset xmlns:pr="#{NS["pr"]}" xmlns:cp="#{NS["cp"]}">
<cp:rule id="pres_whitelist">
<cp:conditions>
<cp:identity>
<cp:one id="a"/>
<cp:one id="b"/>
</cp:identity>
</cp:conditions>
<cp:actions>
<pr:sub-handling>allow</pr:sub-handling>
</cp:actions>
</cp:rule>
<cp:rule id="pres_blacklist">
<cp:conditions>
<cp:identity>
<cp:one id="m"/>
</cp:identity>
</cp:conditions>
<cp:actions>
<pr:sub-handling>block</pr:sub-handling>
</cp:actions>
</cp:rule>
</cp:ruleset>
EOF
PATH =
'/cp:ruleset/cp:rule[@id="pres_whitelist"]/cp:conditions/cp:identity/cp:one/namespace::*'
xml = ::Nokogiri::XML::Document.parse(PRES_RULES, nil, nil, XML_PARSE_OPTIONS)
node = xml.xpath(PATH, NS)
puts "Now it will crash..."
puts node # <--- It crashes HERE !!!
puts "No, it didn't crash"
----------------------------------------------------------------
Note that the PATH expression is invalid since the last node "namespace::*"
has no XML namespace prefix:
PATH =
'/cp:ruleset/cp:rule[@id="pres_whitelist"]/cp:conditions/cp:identity/cp:one/namespace::*'
In Ruby 1.8.7 if just crashes if it's "namespace::*", if you try *any* other
final node name it will just raise "Nokogiri::XML::XPath::SyntaxError". So
this means that "namespace::*" could be an official Xpath feature (not just
used in XCAP as I though) but Nokogiri crashes when handling it:
------------------------------------
$ ruby1.8 ./nokogiri_02.rb
Now it will crash...
./nokogiri_02.rb:46: [BUG] Segmentation fault
ruby 1.8.7 (2008-08-11 patchlevel 72) [x86_64-linux]
Canceled
------------------------------------
Note that it has crashed when running "puts node".
But in Ruby 1.9 it crashes in any case if the NS prefix doesn't exist in the
final node, which seems a worse bug. In fact it also crashes with the
following PATH:
PATH =
'/cp:ruleset/cp:rule[@id="pres_whitelist"]/cp:conditions/cp:identity/cp:one/lala:lolo'
--------------------------------------------
$ ./nokogiri_02.rb
/usr/local/lib/ruby1.9/gems/1.9.1/gems/nokogiri-1.4.0/lib/nokogiri/xml/node.rb:142:in
`evaluate': Undefined namespace prefix (Nokogiri::XML::XPath::SyntaxError)
from
/usr/local/lib/ruby1.9/gems/1.9.1/gems/nokogiri-1.4.0/lib/nokogiri/xml/node.rb:142:in
`block in xpath'
from
/usr/local/lib/ruby1.9/gems/1.9.1/gems/nokogiri-1.4.0/lib/nokogiri/xml/node.rb:139:in
`map'
from
/usr/local/lib/ruby1.9/gems/1.9.1/gems/nokogiri-1.4.0/lib/nokogiri/xml/node.rb:139:in
`xpath'
from ./nokogiri_02.rb:43:in `<main>'
<main>:219: [BUG] Segmentation fault
ruby 1.9.1p129 (2009-05-12 revision 23412) [x86_64-linux]
-- control frame ----------
c:0001 p:0000 s:0002 b:0002 l:0022d8 d:0022d8 TOP <main>:219
---------------------------
-- Ruby level backtrace information-----------------------------------------
-- C level backtrace information -------------------------------------------
0x4e8e3b ruby1.9(rb_vm_bugreport+0x3b) [0x4e8e3b]
0x517080 ruby1.9 [0x517080]
0x5171f1 ruby1.9(rb_bug+0xb1) [0x5171f1]
0x493bbf ruby1.9 [0x493bbf]
0x7fdad005f080 /lib/libpthread.so.0 [0x7fdad005f080]
0x44335e ruby1.9(rb_obj_is_kind_of+0x12e) [0x44335e]
0x41aacf ruby1.9(ruby_cleanup+0x1cf) [0x41aacf]
0x41abaa ruby1.9(ruby_run_node+0x3a) [0x41abaa]
0x417f5d ruby1.9(main+0x4d) [0x417f5d]
0x7fdacf4335a6 /lib/libc.so.6(__libc_start_main+0xe6) [0x7fdacf4335a6]
0x417e49 ruby1.9 [0x417e49]
--------------------------------------------
Note that it has crashed when running "node = xml.xpath(PATH, NS)".
So there are two different issues here:
1) Fetching node namespaces (xpath = ....../namespace::*) is not implemented
(it crashes) in Nokogiri but it's implemented in libxml2. Nokogiri crashes
when doing "puts node".
Note however that I couldn't find a specifications about this feature, but
just in XCAP RFC 4825:
http://tools.ietf.org/html/rfc4825#section-7.10
So, I'm not sure if it exists for Xpath or not. However Nokogiri with ruby 1.8
just crashes with "/namespace::*" (and not with "/lalala::*/").
2) Using Ruby1.9 Nokogiri crashes if a non existing prefix is used in XPath.
Thanks for the report! I'll look in to this and see what I can do.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "nokogiri-talk" group.
To post to this group, send email to nokogi...@googlegroups.com
To unsubscribe from this group, send email to nokogiri-tal...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/nokogiri-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
You received this message because you are subscribed to the Google Groups "nokogiri-talk" group.
To post to this group, send email to nokogi...@googlegroups.com.For more options, visit this group at http://groups.google.com/group/nokogiri-talk?hl=.
To unsubscribe from this group, send email to nokogiri-tal...@googlegroups.com.
commit b94ce7c2cd42bfc5df86bf4c760f40208e801290which are in master. Look at the log and you will see them there.
Author: Mike Dalessio <mi...@csa.net>
Date: Mon Nov 16 11:45:28 2009 -0500
FFI: making node set namespace decl tests pass
commit 8111e7bc40f28caeb2adbcfe098e2ff11b95c08f
Author: Mike Dalessio <mi...@csa.net>
Date: Mon Nov 16 11:43:25 2009 -0500
C: making node set namespace decl tests pass
commit 760ea12779a35862d8569e944e601fa0f13f2a84
Author: Mike Dalessio <mi...@csa.net>
Date: Mon Nov 16 11:42:57 2009 -0500
introducing failing tests for node sets containing namespace declarations.
--
You received this message because you are subscribed to the Google Groups "nokogiri-talk" group.
To post to this group, send email to nokogi...@googlegroups.com.
To unsubscribe from this group, send email to nokogiri-tal...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nokogiri-talk?hl=.
--
You received this message because you are subscribed to the Google Groups "nokogiri-talk" group.
To post to this group, send email to nokogi...@googlegroups.com.
To unsubscribe from this group, send email to nokogiri-tal...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nokogiri-talk?hl=.