From 8e3b8e948b735bdba8bb290213315aa74888bd16 Mon Sep 17 00:00:00 2001 From: Pavel Horal Date: Thu, 9 Mar 2017 12:15:49 +0100 Subject: [PATCH 1/2] Fix incorrect handling of CDATA content. See #15. --- pretty-data.js | 5 ++--- test/test_xml.js | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/pretty-data.js b/pretty-data.js index 6e53132..81ddd51 100644 --- a/pretty-data.js +++ b/pretty-data.js @@ -65,8 +65,7 @@ function pp() { pp.prototype.xml = function(text) { - var ar = text.replace(/>\s{0,}<") - .replace(/ // if(ar[ix].search(/<\?/) > -1) { - str += this.shift[deep]+ar[ix]; + str = !inComment ? str += this.shift[deep]+ar[ix] : str += ar[ix]; } else // xmlns // if( ar[ix].search(/xmlns\:/) > -1 || ar[ix].search(/xmlns\=/) > -1) { diff --git a/test/test_xml.js b/test/test_xml.js index 7ac1322..0dc51a5 100644 --- a/test/test_xml.js +++ b/test/test_xml.js @@ -1,5 +1,5 @@ -var xml = ' bbb ]]>', +var xml = ' bbb ]]>', pp_xml = require('../pretty-data').pd.xml(xml), pp_xmlmin_com = require('../pretty-data').pd.xmlmin(xml,true), pp_xmlmin = require('../pretty-data').pd.xmlmin(xml); From 6fe8833f0def401d703390674ee77bfafd76891a Mon Sep 17 00:00:00 2001 From: Pavel Horal Date: Thu, 9 Mar 2017 12:39:52 +0100 Subject: [PATCH 2/2] Remove excessive whitespace behind the element. See #15. --- pretty-data.js | 4 ++++ test/test_xml.js | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/pretty-data.js b/pretty-data.js index 81ddd51..81244ff 100644 --- a/pretty-data.js +++ b/pretty-data.js @@ -124,6 +124,10 @@ pp.prototype.xml = function(text) { else { str += ar[ix]; } + // remove excessive spaces + if (!inComment) { + str = str.replace(/\s+$/, ''); + } } return (str[0] == '\n') ? str.slice(1) : str; diff --git a/test/test_xml.js b/test/test_xml.js index 0dc51a5..dfc7eb2 100644 --- a/test/test_xml.js +++ b/test/test_xml.js @@ -1,5 +1,5 @@ -var xml = ' bbb ]]>', +var xml = ' \n bbb \n ]]>', pp_xml = require('../pretty-data').pd.xml(xml), pp_xmlmin_com = require('../pretty-data').pd.xmlmin(xml,true), pp_xmlmin = require('../pretty-data').pd.xmlmin(xml);