Skip to content

Commit

Permalink
fix bug by adding nocdata option to parsing of stylesheet by libxmljs
Browse files Browse the repository at this point in the history
see issue: #3

And solution found here:
https://rt.cpan.org/Public/Bug/Display.html?id=29572
  • Loading branch information
albanm committed Dec 16, 2014
1 parent 2f08c1a commit 5ec4a47
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 25 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ It is possible to work with libxmljs documents instead of strings:
var lixslt = require('libxslt');
var libxmljs = require('libxmljs');

var stylesheetObj = libxmljs.parseXml(stylesheetString);
var stylesheetObj = libxmljs.parseXml(stylesheetString, { nocdata: true });
var stylesheet = libxslt.parse(stylesheetObj);

var document = libxmljs.parseXml(documentString);
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ exports.parse = function(source, callback) {
// stylesheet can be given as a string or a pre-parsed xml document
if (typeof source === 'string') {
try {
source = libxmljs.parseXml(source);
source = libxmljs.parseXml(source, { nocdata: true });
} catch (err) {
if (callback) return callback(err);
throw err;
Expand Down
25 changes: 9 additions & 16 deletions test/libxslt.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,21 +154,14 @@ describe('node-libxslt', function() {
});
});
});
});

describe('node-libxslt disable-output-escaping issue', function() {
it('should apply a stylesheet to a xml file', function() {
var xmlToTest = fs.readFileSync('test/resources/disable-output-escaping.xml');
var xsltXmlToTest = fs.readFileSync('test/resources/disable-output-escaping.xsl');
var expectedOutput = fs.readFileSync('test/resources/disable-output-escaping.output').toString();
var xmlDoc = libxmljs.parseXml(xmlToTest);
var xsltXmlDoc = libxmljs.parseXml(xsltXmlToTest);
var xsltDoc = libxslt.parse(xsltXmlDoc);

var resultXml = xsltDoc.apply(xmlDoc);
var resultString = resultXml.toString();

resultString.should.be.type('string');
resultString.should.match(expectedOutput);
});
describe('disable-output-escaping attribute', function() {
it('should be interpreted by a stylesheet', function() {
var stylesheetStr = fs.readFileSync('test/resources/disable-output-escaping.xsl', 'utf8');
var stylesheetEsc = libxslt.parse(stylesheetStr);
var result = stylesheetEsc.apply('<root/>');
result.should.match(/<foo\/>/);
result.should.match(/&lt;bar\/&gt;/);
});
});
});
3 changes: 0 additions & 3 deletions test/resources/disable-output-escaping.output

This file was deleted.

3 changes: 0 additions & 3 deletions test/resources/disable-output-escaping.xml

This file was deleted.

1 change: 0 additions & 1 deletion test/resources/disable-output-escaping.xsl
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="root">
<xsl:value-of select="content" disable-output-escaping="yes"/>
<xsl:text disable-output-escaping="yes"><![CDATA[<foo/>]]></xsl:text>
<xsl:text disable-output-escaping="no"><![CDATA[<bar/>]]></xsl:text>
</xsl:template>
Expand Down

0 comments on commit 5ec4a47

Please sign in to comment.