Skip to content

Commit 7e66df2

Browse files
committed
fix incorrect parsing of script element
1 parent e71ccf0 commit 7e66df2

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

HtmlParser.Tests/ParserTests.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System;
33
using System.Collections.Generic;
44
using System.Linq;
5+
using System.Security.Cryptography.X509Certificates;
56
using System.Text;
67

78
namespace NMyVision.HtmlParserTests
@@ -78,5 +79,29 @@ public void MultipleRunsTest()
7879
Assert.IsTrue(el.HasChildren());
7980

8081
}
82+
83+
[TestMethod()]
84+
public void LargeHtml()
85+
{
86+
var html = @"<html lang=""en"">
87+
<head>
88+
<title>Pug</title>
89+
<script type=""text/javascript""> if (foo) bar(1 + 5) </script>
90+
</head>
91+
<body>
92+
<h1>Pug - node template engine</h1>
93+
<div id=""container"" class=""col"">
94+
<p>You are amazing</p>
95+
<p>Pug is a terse and simple templating language.</p>
96+
</div>
97+
</body>
98+
</html>";
99+
100+
var el = new HtmlParser().Parse(html).First();
101+
102+
Assert.AreEqual( html, el.OuterHTML );
103+
104+
105+
}
81106
}
82107
}

HtmlParser/NMyVision.HtmlParser.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
1212
<RepositoryType></RepositoryType>
1313
<RepositoryUrl>https://github.com/NMyVision/HtmlParser</RepositoryUrl>
14-
<Version>1.0.4</Version>
14+
<Version>1.0.5</Version>
1515

1616

1717
<!-- Optional: Publish the repository URL in the built .nupkg (in the NuSpec <Repository> element) -->

HtmlParser/Parser.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,11 @@ private IEnumerable<HtmlNode> InternalParse(HtmlNode parent = null)
110110
}
111111
else if (node.Tag.Equals("script", StringComparison.OrdinalIgnoreCase))
112112
{
113-
Dequeue();
113+
Dequeue(); // >
114114
node.Content = GetUpTo("</script");
115115
node.EndTag = "script";
116+
Dequeue(9); // </script>
117+
node.SetEndIndex(index, Source);
116118
list.Add(node);
117119
}
118120
}

0 commit comments

Comments
 (0)