Skip to content

Commit 6ac7304

Browse files
committed
Merge tag 'v0.18.0' into mt
0.18.0
2 parents f83fe4f + a117c59 commit 6ac7304

File tree

7 files changed

+63
-10
lines changed

7 files changed

+63
-10
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ node_js:
1010
- iojs-2
1111
- iojs-3
1212
- 4
13-
- 5
13+
- 6
1414

1515
addons:
1616
apt:

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
target=./build/Release/libxmljs.node
2+
target=./build/Release/xmljs.node
33

44
all: $(target)
55

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
[![Build Status](https://secure.travis-ci.org/gagern/libxmljs.svg?branch=master)](http://travis-ci.org/gagern/libxmljs)
33

44
This project is a fork of [libxmljs](https://github.com/libxmljs/libxmljs).
5-
The current version 0.17.2 is based on libxmljs 0.17.1 and libxml 2.9.4.
5+
The current version 0.18.0 is based on libxmljs 0.18.0 and libxml 2.9.4.
66

77
Libxmljs was originally designed with single-threaded operations in mind.
88
There are no asynchroneous operations for things like parsing XML documents.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"Martin von Gagern <[email protected]>"
88
],
99
"description": "multi-threaded libxml bindings for v8 javascript engine",
10-
"version": "0.17.2",
10+
"version": "0.18.0",
1111
"scripts": {
1212
"test": "node --expose_gc node_modules/nodeunit/bin/nodeunit test"
1313
},
@@ -25,7 +25,7 @@
2525
},
2626
"dependencies": {
2727
"bindings": "^1.2.1",
28-
"nan": "^2.0.7"
28+
"nan": "^2.3.2"
2929
},
3030
"devDependencies": {
3131
"nodeunit": "^0.9.0"

src/xml_document.cc

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ NAN_METHOD(XmlDocument::ToString)
235235
if (xmlBufferLength(buf) > 0)
236236
ret = Nan::New<v8::String>((char*)xmlBufferContent(buf), xmlBufferLength(buf)).ToLocalChecked();
237237
xmlBufferFree(buf);
238-
238+
239239
return info.GetReturnValue().Set(ret);
240240
}
241241

@@ -317,7 +317,7 @@ xmlParserOption getParserOptions(v8::Local<v8::Object> props) {
317317
ret |= getParserOption(props, "cdata", XML_PARSE_NOCDATA, false); // 16384: merge CDATA as text nodes
318318

319319
ret |= getParserOption(props, "noxincnode", XML_PARSE_NOXINCNODE); // 32768: do not generate XINCLUDE START/END nodes
320-
ret |= getParserOption(props, "xinclude", XML_PARSE_NOXINCNODE, false); // 32768: do not generate XINCLUDE START/END nodes
320+
ret |= getParserOption(props, "xincnode", XML_PARSE_NOXINCNODE, false); // 32768: do not generate XINCLUDE START/END nodes
321321

322322
ret |= getParserOption(props, "compact", XML_PARSE_COMPACT); // 65536: compact small text nodes; no modification of the tree allowed afterwards (will possibly crash if you try to modify the tree)
323323
/*ret |= getParserOption(props, "compact", HTML_PARSE_COMPACT , false); // 65536: compact small text nodes*/
@@ -400,24 +400,49 @@ NAN_METHOD(XmlDocument::FromHtml)
400400
return info.GetReturnValue().Set(doc_handle);
401401
}
402402

403+
// FIXME: this method is almost identical to FromHtml above.
404+
// The two should be refactored to use a common function for most
405+
// of the work
403406
NAN_METHOD(XmlDocument::FromXml)
404407
{
405408
Nan::HandleScope scope;
406409
XmlSyntaxErrorsSync errors; // RAII sentinel
407410

408-
xmlParserOption opts = getParserOptions(info[1]->ToObject());
411+
v8::Local<v8::Object> options = info[1]->ToObject();
412+
v8::Local<v8::Value> baseUrlOpt = options->Get(
413+
Nan::New<v8::String>("baseUrl").ToLocalChecked());
414+
v8::Local<v8::Value> encodingOpt = options->Get(
415+
Nan::New<v8::String>("encoding").ToLocalChecked());
416+
v8::Local<v8::Value> excludeImpliedElementsOpt = options->Get(
417+
Nan::New<v8::String>("excludeImpliedElements").ToLocalChecked());
418+
419+
// the base URL that will be used for this document
420+
v8::String::Utf8Value baseUrl_(baseUrlOpt->ToString());
421+
const char * baseUrl = *baseUrl_;
422+
if (!baseUrlOpt->IsString()) {
423+
baseUrl = NULL;
424+
}
425+
426+
// the encoding to be used for this document
427+
// (leave NULL for libxml to autodetect)
428+
v8::String::Utf8Value encoding_(encodingOpt->ToString());
429+
const char * encoding = *encoding_;
430+
if (!encodingOpt->IsString()) {
431+
encoding = NULL;
432+
}
409433

434+
int opts = (int) getParserOptions(options);
410435
xmlDocPtr doc;
411436
if (!node::Buffer::HasInstance(info[0])) {
412437
// Parse a string
413438
v8::String::Utf8Value str(info[0]->ToString());
414-
doc = xmlReadMemory(*str, str.length(), NULL, "UTF-8", opts);
439+
doc = xmlReadMemory(*str, str.length(), baseUrl, "UTF-8", opts);
415440
}
416441
else {
417442
// Parse a buffer
418443
v8::Local<v8::Object> buf = info[0]->ToObject();
419444
doc = xmlReadMemory(node::Buffer::Data(buf), node::Buffer::Length(buf),
420-
NULL, NULL, opts);
445+
baseUrl, encoding, opts);
421446
}
422447

423448
if (!doc) {

test/fixtures/baseurl.dtd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<!ELEMENT example EMPTY>
2+
<!ATTLIST example msg CDATA "IMPLIED">
3+
<!ENTITY happy "Happy gardens forever!">

test/xml_parser.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,31 @@ module.exports.recoverable_parse = function(assert) {
5555
assert.done();
5656
};
5757

58+
module.exports.baseurl_xml = function(assert) {
59+
var str = '<!DOCTYPE example SYSTEM "baseurl.dtd">\n' +
60+
'<example msg="&happy;"/>\n';
61+
62+
// First verify it fails when we don't give baseUrl
63+
var doc = libxml.Document.fromXml(str, {
64+
dtdvalid: true,
65+
nonet: true,
66+
});
67+
assert.ok(doc.errors.length > 0);
68+
69+
// Now it should work
70+
var doc = libxml.Document.fromXml(str, {
71+
dtdvalid: true,
72+
nonet: true,
73+
baseUrl: __dirname + '/fixtures/example.xml',
74+
});
75+
assert.ok(!doc.errors || doc.errors.length == 0);
76+
77+
assert.done();
78+
};
79+
80+
81+
82+
5883
module.exports.fatal_error = function(assert) {
5984
var filename = __dirname + '/fixtures/errors/comment.xml';
6085
var str = fs.readFileSync(filename, 'utf8');

0 commit comments

Comments
 (0)