Skip to content

Commit 1bb16a9

Browse files
committed
#37 Fix non-first attributes finding
1 parent 488c608 commit 1bb16a9

File tree

3 files changed

+34
-15
lines changed

3 files changed

+34
-15
lines changed

src/AngleSharp.XPath.Tests/HtmlDocumentNavigatorTests.cs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
using System.Xml;
2-
using AngleSharp.Xml.Parser;
1+
using AngleSharp.Dom;
32
using AngleSharp.Html.Parser;
3+
using AngleSharp.Xml.Parser;
44
using NUnit.Framework;
55
using System.Threading.Tasks;
6+
using System.Xml;
67
using System.Xml.XPath;
7-
using AngleSharp.Dom;
88

99
namespace AngleSharp.XPath.Tests
1010
{
@@ -173,5 +173,29 @@ public void MoveToParent_CallWhenCurrentNodeIsAttr_ShouldBeMovedToAttrOwnerEleme
173173
// Assert
174174
Assert.AreEqual(nav.Name, "root");
175175
}
176+
177+
[Test]
178+
public void SelectSingleNodeTest_AttributesOrder()
179+
{
180+
// Arrange
181+
const string html =
182+
@"<body>
183+
<div id='div1'>First</div>
184+
<div id='div2' class='mydiv'>Second</div>
185+
<div class='mydiv' id='div3'>Third</div>
186+
</body>";
187+
var parser = new HtmlParser();
188+
var document = parser.ParseDocument(html);
189+
190+
// Act
191+
var div1 = document.DocumentElement.SelectSingleNode("//div[@id='div1']");
192+
var div2 = document.DocumentElement.SelectSingleNode("//div[@id='div2']");
193+
var div3 = document.DocumentElement.SelectSingleNode("//div[@id='div3']");
194+
195+
// Assert
196+
Assert.That(div1, Is.Not.Null);
197+
Assert.That(div2, Is.Not.Null);
198+
Assert.That(div3, Is.Not.Null); // currently fails
199+
}
176200
}
177201
}

src/AngleSharp.XPath/AngleSharp.XPath.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<Version>2.0.0</Version>
4-
<AssemblyVersion>2.0.0</AssemblyVersion>
5-
<FileVersion>2.0.0</FileVersion>
3+
<Version>2.0.1</Version>
4+
<AssemblyVersion>2.0.1</AssemblyVersion>
5+
<FileVersion>2.0.1</FileVersion>
66
<Authors>Denis Ivanov</Authors>
77
<PackageId>AngleSharp.XPath</PackageId>
88
<AssemblyName>AngleSharp.XPath</AssemblyName>
@@ -20,7 +20,7 @@
2020
</PropertyGroup>
2121

2222
<ItemGroup>
23-
<PackageReference Include="AngleSharp" Version="0.17.0" />
23+
<PackageReference Include="AngleSharp" Version="0.17.1" />
2424
</ItemGroup>
2525

2626
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'net461' or '$(TargetFramework)' == 'net472' or '$(TargetFramework)' == 'net6.0' ">

src/AngleSharp.XPath/HtmlDocumentNavigator.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -283,11 +283,6 @@ public override bool MoveToNext()
283283
/// <inheritdoc />
284284
public override bool MoveToNextAttribute()
285285
{
286-
if (CurrentElement == null)
287-
{
288-
return false;
289-
}
290-
291286
if (!(CurrentNode is IAttr attr))
292287
{
293288
return false;
@@ -300,10 +295,10 @@ public override bool MoveToNextAttribute()
300295

301296
var attrIndex = attr.OwnerElement.Attributes.Index(attr);
302297

303-
if (attrIndex >= CurrentElement.Attributes.Length - 1)
304-
{
298+
if (attrIndex == attr.OwnerElement.Attributes.Length - 1)
299+
{
305300
return false;
306-
}
301+
}
307302

308303
_currentNode = attr.OwnerElement.Attributes[attrIndex + 1];
309304
return true;

0 commit comments

Comments
 (0)