Permalink
Browse files

Fix segfault on broken xpath (+ test case)

  • Loading branch information...
1 parent b69f528 commit ee353f47d898104ebaeef7dbdccfb17c8e741fe7 @jmandel jmandel committed Aug 31, 2012
Showing with 14 additions and 0 deletions.
  1. +5 −0 src/xml_xpath_context.cc
  2. +9 −0 test/searching.js
@@ -32,6 +32,11 @@ XmlXpathContext::evaluate(const xmlChar* xpath) {
if (xpathobj) {
switch (xpathobj->type) {
case XPATH_NODESET: {
+ if (xmlXPathNodeSetIsEmpty(xpathobj->nodesetval)) {
+ res = v8::Array::New(0);
+ break;
+ }
+
v8::Handle<v8::Array> nodes = v8::Array::New(xpathobj->nodesetval->nodeNr);
for (int i = 0; i != xpathobj->nodesetval->nodeNr; ++i) {
nodes->Set(i, XmlNode::New(xpathobj->nodesetval->nodeTab[i]));
View
@@ -14,6 +14,15 @@ module.exports.get = function(assert) {
assert.done();
};
+module.exports.get_missing = function(assert) {
+ var doc = libxml.Document();
+ var root = doc.node('root');
+
+ var missing = doc.get('missing/text()');
+ assert.equal(missing, undefined);
+ assert.done();
+};
+
module.exports.get_attr = function(assert) {
var doc = libxml.Document();
var root = doc.node('root');

0 comments on commit ee353f4

Please sign in to comment.