Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix segfault on broken xpath (+ test case) #160

Merged
merged 1 commit into from

3 participants

@jmandel

Fixes polotek/libxmljs#159

  • check for valid XML node set before creating result array
  • test case
@travisbot

This pull request passes (merged ee353f4 into b69f528).

@defunctzombie defunctzombie merged commit 894cad0 into polotek:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 31, 2012
  1. @jmandel
This page is out of date. Refresh to see the latest.
Showing with 14 additions and 0 deletions.
  1. +5 −0 src/xml_xpath_context.cc
  2. +9 −0 test/searching.js
View
5 src/xml_xpath_context.cc
@@ -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
9 test/searching.js
@@ -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');
Something went wrong with that request. Please try again.