File tree Expand file tree Collapse file tree 3 files changed +41
-3
lines changed Expand file tree Collapse file tree 3 files changed +41
-3
lines changed Original file line number Diff line number Diff line change 3
3
using AngleSharp . Html . Parser ;
4
4
using NUnit . Framework ;
5
5
using System . Threading . Tasks ;
6
+ using System . Xml . XPath ;
6
7
using AngleSharp . Dom ;
7
8
8
9
namespace AngleSharp . XPath . Tests
@@ -146,5 +147,31 @@ public void TestNameXPathFunctionOnHTMLDoc()
146
147
// Assert
147
148
Assert . AreEqual ( TagNames . Html , htmlNav . Evaluate ( "name()" ) ) ;
148
149
}
150
+
151
+ [ Test ]
152
+ public void MoveToParent_CallWhenCurrentNodeIsAttr_ShouldBeMovedToAttrOwnerElement ( )
153
+ {
154
+ // Arrange
155
+ var xml = @"<root att1='value 1' att2='value 2'><child>foo</child></root>" ;
156
+ var parser = new XmlParser ( ) ;
157
+ var doc = parser . ParseDocument ( xml ) ;
158
+ var nav = doc . CreateNavigator ( false ) ;
159
+ nav . MoveToChild ( "root" , "" ) ;
160
+
161
+ // Act
162
+
163
+ if ( nav . MoveToFirstAttribute ( ) )
164
+ {
165
+ do
166
+ {
167
+ Assert . AreEqual ( nav . NodeType , XPathNodeType . Attribute ) ;
168
+ }
169
+ while ( nav . MoveToNextAttribute ( ) ) ;
170
+ nav . MoveToParent ( ) ;
171
+ }
172
+
173
+ // Assert
174
+ Assert . AreEqual ( nav . Name , "root" ) ;
175
+ }
149
176
}
150
177
}
Original file line number Diff line number Diff line change 1
1
<Project Sdk =" Microsoft.NET.Sdk" >
2
2
<PropertyGroup >
3
- <Version >2.0.0-alpha-2 </Version >
3
+ <Version >2.0.0-alpha-3 </Version >
4
4
<AssemblyVersion >2.0.0</AssemblyVersion >
5
- <FileVersion >2.0.0-alpha-2 </FileVersion >
5
+ <FileVersion >2.0.0-alpha-3 </FileVersion >
6
6
<Authors >Denis Ivanov</Authors >
7
7
<PackageId >AngleSharp.XPath</PackageId >
8
8
<AssemblyName >AngleSharp.XPath</AssemblyName >
Original file line number Diff line number Diff line change @@ -293,11 +293,16 @@ public override bool MoveToNextAttribute()
293
293
return false ;
294
294
}
295
295
296
+ if ( attr . OwnerElement == null )
297
+ {
298
+ return false ;
299
+ }
300
+
296
301
var attrIndex = attr . OwnerElement . Attributes . Index ( attr ) ;
297
302
298
303
if ( attrIndex >= CurrentElement . Attributes . Length - 1 )
299
304
{
300
- return false ;
305
+ return false ;
301
306
}
302
307
303
308
_currentNode = attr . OwnerElement . Attributes [ attrIndex + 1 ] ;
@@ -313,6 +318,12 @@ public override bool MoveToNextNamespace(XPathNamespaceScope namespaceScope)
313
318
/// <inheritdoc />
314
319
public override bool MoveToParent ( )
315
320
{
321
+ if ( CurrentNode is IAttr attr )
322
+ {
323
+ _currentNode = attr . OwnerElement ;
324
+ return true ;
325
+ }
326
+
316
327
if ( _currentNode . Parent == null )
317
328
{
318
329
return false ;
You can’t perform that action at this time.
0 commit comments