From cd5c4c021e2761ccac45cb1a50c8128929f2357e Mon Sep 17 00:00:00 2001 From: Evan Johnson Date: Fri, 12 Aug 2016 17:29:56 -0500 Subject: [PATCH 1/2] Add Feature: strictXML Add options for working with strict XML parsers such as jspx which can mangle code and cause browsers to improperly format it to the user. --- README.md | 37 ++++++++++++++++++- lib/refManager.js | 30 +++++++++++++-- test/test.js | 13 +++++++ test/testfiles/16-expected.html | 7 ---- test/testfiles/16-win-expected.html | 7 ---- test/testfiles/16-win.html | 10 ----- test/testfiles/16.html | 10 ----- test/testfiles/28-strictCssXML-expected.html | 5 +++ test/testfiles/28-strictCssXML.html | 8 ++++ .../29-strictScriptXML-expected.html | 6 +++ test/testfiles/29-strictScriptXML.html | 9 +++++ 11 files changed, 103 insertions(+), 39 deletions(-) delete mode 100644 test/testfiles/16-expected.html delete mode 100644 test/testfiles/16-win-expected.html delete mode 100644 test/testfiles/16-win.html delete mode 100644 test/testfiles/16.html create mode 100644 test/testfiles/28-strictCssXML-expected.html create mode 100644 test/testfiles/28-strictCssXML.html create mode 100644 test/testfiles/29-strictScriptXML-expected.html create mode 100644 test/testfiles/29-strictScriptXML.html diff --git a/README.md b/README.md index 0264fc3..da73631 100644 --- a/README.md +++ b/README.md @@ -190,6 +190,41 @@ Results in: ``` +#### options.strictCssXML + +Type: `Boolean` +Defaul: `false` + +Adds `/` self closure to the `link` tag to make it strict XML compliant to prevent some XML parsers from failing to properly parse and validate the document. + +```html + + + + +``` + +```html + +``` + +#### options.strictScriptXML + +Type: `Boolean` +Defaul: `false` + +Adds `//` block to the script tag to prevent some XML parsers from changing the empty tag (``) into a self-closed tag (` + + +``` + +```html + +``` ## Contributing @@ -197,4 +232,4 @@ See the [CONTRIBUTING Guidelines](https://github.com/jonkemp/useref/blob/master/ ## License -MIT © [Jonathan Kemp](http://jonkemp.com) +MIT © [Jonathan Kemp](http://jonkemp.com) \ No newline at end of file diff --git a/lib/refManager.js b/lib/refManager.js index d723ef2..b0d6fef 100644 --- a/lib/refManager.js +++ b/lib/refManager.js @@ -12,6 +12,10 @@ module.exports = { bb.type = props.type; bb.attbs = props.attbs; bb.alternateSearchPaths = props.alternateSearchPaths; + bb.strictCssXML = + options && options.strictCssXML; + bb.strictScriptXML = + options && options.strictScriptXML; }, transformCSSRefs: function (block, target, attbs) { @@ -21,12 +25,21 @@ module.exports = { // TODO: Determine if 'href' attribute is present. var regcss = /|\))/gmi; + // end closing tag for the link element + var closingTag = '>'; + // Check to see if there are any css references at all. if (block.search(regcss) !== -1) { + if (bb && bb.strictCssXML) { + // make end closing tag self closing + // if strict XML type needed + closingTag = '/>'; + } + if (attbs) { - ref = ''; + ref = ''; + ref = '|\))<[^<]*)*(?:<\/script>|\))/gmi; + // general closing for a script tag + var closingTag = ''; + // Check to see if there are any js references at all. if (block.search(regscript) !== -1) { + if (bb && bb.strictScriptXML) { + // append cdata block to script element + // if strict XML type needed + closingTag = '//' + closingTag; + } + if (attbs) { - ref = ''; + ref = ''; + ref = ' + + \ No newline at end of file diff --git a/test/testfiles/29-strictScriptXML.html b/test/testfiles/29-strictScriptXML.html new file mode 100644 index 0000000..9fe298e --- /dev/null +++ b/test/testfiles/29-strictScriptXML.html @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file From 8b5b7336abb106283985ca9cd4ac520e807977fb Mon Sep 17 00:00:00 2001 From: Evan Johnson Date: Fri, 12 Aug 2016 17:51:27 -0500 Subject: [PATCH 2/2] Added Files: Test 16 The files weren't included in my project for an unknown reason. Added them back. --- test/testfiles/16-expected.html | 7 +++++++ test/testfiles/16-win-expected.html | 7 +++++++ test/testfiles/16-win.html | 10 ++++++++++ test/testfiles/16.html | 10 ++++++++++ 4 files changed, 34 insertions(+) create mode 100644 test/testfiles/16-expected.html create mode 100644 test/testfiles/16-win-expected.html create mode 100644 test/testfiles/16-win.html create mode 100644 test/testfiles/16.html diff --git a/test/testfiles/16-expected.html b/test/testfiles/16-expected.html new file mode 100644 index 0000000..5b010f0 --- /dev/null +++ b/test/testfiles/16-expected.html @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/test/testfiles/16-win-expected.html b/test/testfiles/16-win-expected.html new file mode 100644 index 0000000..5b010f0 --- /dev/null +++ b/test/testfiles/16-win-expected.html @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/test/testfiles/16-win.html b/test/testfiles/16-win.html new file mode 100644 index 0000000..8e32ea5 --- /dev/null +++ b/test/testfiles/16-win.html @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file diff --git a/test/testfiles/16.html b/test/testfiles/16.html new file mode 100644 index 0000000..8e32ea5 --- /dev/null +++ b/test/testfiles/16.html @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file