Skip to content

Commit c8b229b

Browse files
RocikDenis Ivanov
authored andcommitted
Fix querying preceding node with doctype in the html source
1 parent fffa8c4 commit c8b229b

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/AngleSharp.XPath.Tests/HtmlDocumentNavigatorTests.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace AngleSharp.XPath.Tests
88
public class HtmlDocumentNavigatorTests
99
{
1010
[Test, Retry(5)]
11-
public async Task SelectSinleNodeTest()
11+
public async Task SelectSingleNodeTest()
1212
{
1313
// Arrange
1414
const string address = "https://stackoverflow.com/questions/39471800/is-anglesharps-htmlparser-threadsafe";
@@ -41,5 +41,25 @@ public void SelectNodes_SelectList_ShouldReturnList()
4141
// Assert
4242
Assert.That(nodes, Has.Count.EqualTo(3));
4343
}
44+
45+
[Test]
46+
public void SelectPrecedingNodeInDocumentWithDoctype_ShouldReturnNode()
47+
{
48+
// Arrange
49+
const string html =
50+
@"<!DOCTYPE html>
51+
<body>
52+
<span></span>
53+
<div></div>
54+
</body>";
55+
var parser = new HtmlParser();
56+
var document = parser.ParseDocument(html);
57+
58+
// Act
59+
var node = document.DocumentElement.SelectSingleNode("//div/preceding::span");
60+
61+
// Assert
62+
Assert.That(node, Is.Not.Null);
63+
}
4464
}
4565
}

src/AngleSharp.XPath/HtmlDocumentNavigator.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ public override XPathNodeType NodeType
9191

9292
case Dom.NodeType.Document:
9393
return XPathNodeType.Element;
94+
95+
case Dom.NodeType.DocumentType:
96+
return XPathNodeType.Element;
9497

9598
case Dom.NodeType.Element:
9699
if (_attrIndex != -1)
@@ -110,7 +113,6 @@ public override XPathNodeType NodeType
110113
case Dom.NodeType.EntityReference:
111114
case Dom.NodeType.Notation:
112115
case Dom.NodeType.DocumentFragment:
113-
case Dom.NodeType.DocumentType:
114116
default:
115117
throw new NotImplementedException();
116118
}

0 commit comments

Comments
 (0)