Skip to content

Commit

Permalink
Fix #38 and bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
inikulin committed Jan 21, 2015
1 parent 5ba65f9 commit 46d4214
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 13 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 1.3.1
* Fix: text node in `<template>` serialization problem with custom tree adapter (GH #38)

## 1.3.0
* Add: Serializer `encodeHtmlEntities` option.

Expand Down
9 changes: 6 additions & 3 deletions lib/serialization/serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,12 @@ Serializer.prototype._serializeAttributes = function (node) {
};

Serializer.prototype._serializeTextNode = function (node) {
var parent = this.treeAdapter.getParentNode(node),
parentTn = parent && this.treeAdapter.getTagName(parent),
content = this.treeAdapter.getTextNodeContent(node);
var content = this.treeAdapter.getTextNodeContent(node),
parent = this.treeAdapter.getParentNode(node),
parentTn = void 0;

if(parent && this.treeAdapter.isElementNode(parent))
parentTn = this.treeAdapter.getTagName(parent);

if (parentTn === $.STYLE || parentTn === $.SCRIPT || parentTn === $.XMP || parentTn === $.IFRAME ||
parentTn === $.NOEMBED || parentTn === $.NOFRAMES || parentTn === $.PLAINTEXT || parentTn === $.NOSCRIPT) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "parse5",
"description": "WHATWG HTML5 specification-compliant, fast and ready for production HTML parsing/serialization toolset for Node.",
"version": "1.3.0",
"version": "1.3.1",
"author": "Ivan Nikulin <[email protected]> (https://github.com/inikulin)",
"contributors": [
"Sebastian Mayr <[email protected]> (http://blog.smayr.name)",
Expand Down
39 changes: 30 additions & 9 deletions test/fixtures/serializer_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,27 @@ exports['Backward compatibility - parse5.TreeSerializer'] = function () {
assert.strictEqual(Serializer, parse5.TreeSerializer);
};

exports['Regression - Get text node\'s parent tagName only if it\'s an Element node (GH-38)'] = {
test: function () {
var parser = new Parser(),
serializer = new Serializer(),
document = parser.parse('<template>yo<div></div>42</template>'),
originalGetTagName = this.originalGetTagName = parse5.TreeAdapters.default.getTagName;

parse5.TreeAdapters.default.getTagName = function (element) {
assert.ok(element.tagName);

return originalGetTagName(element);
};

serializer.serialize(document);
},

after: function () {
parse5.TreeAdapters.default.getTagName = this.originalGetTagName;
}
};

exports['Regression - SYSTEM-only doctype serialization'] = function () {
var html = '<!DOCTYPE html SYSTEM "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' +
'<html><head></head><body></body></html>',
Expand All @@ -23,17 +44,17 @@ exports['Regression - SYSTEM-only doctype serialization'] = function () {

exports['Regression - Escaping of doctypes with quotes in them'] = function () {
var htmlStrs = [
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ' +
'"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' +
'<html><head></head><body></body></html>',
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ' +
'"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' +
'<html><head></head><body></body></html>',

'<!DOCTYPE html PUBLIC \'-//W3C//"DTD" XHTML 1.0 Transitional//EN\' ' +
'"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' +
'<html><head></head><body></body></html>',
'<!DOCTYPE html PUBLIC \'-//W3C//"DTD" XHTML 1.0 Transitional//EN\' ' +
'"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' +
'<html><head></head><body></body></html>',

'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ' +
'\'http://www.w3.org/TR/xhtml1/DTD/"xhtml1-transitional.dtd"\'>' +
'<html><head></head><body></body></html>'
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ' +
'\'http://www.w3.org/TR/xhtml1/DTD/"xhtml1-transitional.dtd"\'>' +
'<html><head></head><body></body></html>'
],
parser = new Parser(),
serializer = new Serializer();
Expand Down

0 comments on commit 46d4214

Please sign in to comment.