Skip to content

Commit

Permalink
js2xml handling of nested CDATA sections
Browse files Browse the repository at this point in the history
  • Loading branch information
servel333 committed Jan 15, 2019
1 parent d27442a commit 28937f1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/js2xml.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function writeComment(comment, options) {
}

function writeCdata(cdata, options) {
return options.ignoreCdata ? '' : '<![CDATA[' + ('cdataFn' in options ? options.cdataFn(cdata, currentElementName, currentElement) : cdata) + ']]>';
return options.ignoreCdata ? '' : '<![CDATA[' + ('cdataFn' in options ? options.cdataFn(cdata, currentElementName, currentElement) : cdata.replace(']]>', ']]]]><![CDATA[>')) + ']]>';
}

function writeDoctype(doctype, options) {
Expand Down
17 changes: 17 additions & 0 deletions test/js2xml-issues.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,23 @@ describe('Testing js2xml.js:', function () {
});
});

describe('case by Nathan Perry', function() {
// see n/a
var js = {
container: {
cdata_section: {
_cdata: '<p><![CDATA[aaaa, one <bbbb>cccc</bbbb>]]></p>',
},
},
};
var xml =
'<container>\n' +
' <cdata_section><![CDATA[<p><![CDATA[aaaa, one <bbbb>cccc</bbbb>]]]]><![CDATA[></p>]]></cdata_section>\n' +
'</container>';
it ('should handle nested CDATA sections', function() {
expect(convert.js2xml(js, {compact: true, spaces: 2, fullTagEmptyElement: false})).toEqual(xml);
});
});

});

Expand Down

0 comments on commit 28937f1

Please sign in to comment.