Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

1.x: Fixed parsing of a tag as the first thing inside script #55

Closed
wants to merge 2 commits into from

2 participants

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 17, 2012
  1. Added .gitignore

    authored
Commits on Sep 14, 2012
  1. @papandreou
This page is out of date. Refresh to see the latest.
View
2  .gitignore
@@ -0,0 +1,2 @@
+.DS_Store
+
View
12 lib/htmlparser.js
@@ -240,10 +240,14 @@ function Parser (handler, options) {
//All data from here to script close is now a text element
element.type = ElementType.Text;
//If the previous element is text, append the current text to it
- if (this._elements.length && this._elements[this._elements.length - 1].type == ElementType.Text) {
- var prevElement = this._elements[this._elements.length - 1];
- prevElement.raw = prevElement.data = prevElement.raw + this._prevTagSep + element.raw;
- element.raw = element.data = ""; //This causes the current element to not be added to the element list
+ if (this._elements.length) {
+ if (this._elements[this._elements.length - 1].type == ElementType.Text) {
+ var prevElement = this._elements[this._elements.length - 1];
+ prevElement.raw = prevElement.data = prevElement.raw + this._prevTagSep + element.raw;
+ element.raw = element.data = ""; //This causes the current element to not be added to the element list
+ } else if (element.raw !== '') {
+ element.raw = element.data = '<' + element.raw;
+ }
}
}
}
View
56 tests/23-tag-as-the-first-thing-inside-script.js
@@ -0,0 +1,56 @@
+(function () {
+
+function RunningInNode () {
+ return(
+ (typeof require) == "function"
+ &&
+ (typeof exports) == "object"
+ &&
+ (typeof module) == "object"
+ &&
+ (typeof __filename) == "string"
+ &&
+ (typeof __dirname) == "string"
+ );
+}
+
+if (!RunningInNode()) {
+ if (!this.Tautologistics)
+ this.Tautologistics = {};
+ if (!this.Tautologistics.NodeHtmlParser)
+ this.Tautologistics.NodeHtmlParser = {};
+ if (!this.Tautologistics.NodeHtmlParser.Tests)
+ this.Tautologistics.NodeHtmlParser.Tests = [];
+ exports = {};
+ this.Tautologistics.NodeHtmlParser.Tests.push(exports);
+}
+
+exports.name = "Tag as the first thing inside <script>";
+exports.options = {
+ handler: {}
+ , parser: {}
+};
+exports.html = "<head><script type=\"text/html\"><div></div></script></head>";
+exports.expected =
+[ { raw: 'head'
+ , data: 'head'
+ , type: 'tag'
+ , name: 'head'
+ , children:
+ [ { raw: 'script type="text/html"'
+ , data: 'script type="text/html"'
+ , type: 'script'
+ , name: 'script'
+ , attribs: { type: 'text/html' }
+ , children:
+ [ { raw: '<div></div>'
+ , data: '<div></div>'
+ , type: 'text'
+ }
+ ]
+ }
+ ]
+ }
+];
+
+})();
Something went wrong with that request. Please try again.