You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When trying to remove an attribute instance that's NOT in a HtmlAttributeCollection through the explicit interface implementation for ICollection<HtmlAttribute>.Remove(HtmlAttribute), it is expected that the method returns false.
However, as implemented in HAP 1.11.41 (implementing a fix for #463), it throws an exception instead of returning false.
Returns true if item was successfully removed from the ICollection<T>; otherwise, false. This method also returns false if item is not found in the original ICollection<T>.
2. Exception
System.IndexOutOfRangeException: Index was outside the bounds of the array.
at HtmlAgilityPack.HtmlAttributeCollection.Remove(HtmlAttribute attribute) in C:\Repos\HtmlAgilityPack\HtmlAgilityPack.Shared\HtmlAttributeCollection.cs:line 343
at HtmlAgilityPack.HtmlAttributeCollection.System.Collections.Generic.ICollection<HtmlAgilityPack.HtmlAttribute>.Remove(HtmlAttribute item) in C:\Repos\HtmlAgilityPack\HtmlAgilityPack.Shared\HtmlAttributeCollection.cs:line 233
at HtmlAttributeCollection_RemoveAndClearNotUpdatingHashItems.Program.Main(String[] args)
varhtml=@"<div class=""foobar"" name=""doctor_doctor"">Hello world!</div>";varhtmlDoc=newHtmlDocument();htmlDoc.LoadHtml(html);vardivNode=htmlDoc.DocumentNode.SelectSingleNode("//div");varattr=divNode.Attributes["class"];ICollection<HtmlAttribute>attributeCollectionAsICollection=(ICollection<HtmlAttribute>)divNode.Attributes;//// Remove an attribute instance that is in the Attributes collection// Expected return value: true//varres1=attributeCollectionAsICollection.Remove(attr);Console.WriteLine($"Return value after successful removal: {res1} (should be true)");//// Now trying to remove an attribute instance that is not in the Attributes collection (anymore)// Expected return value: false//varres2=attributeCollectionAsICollection.Remove(attr);Console.WriteLine($"Return value after successful removal: {res2} (should be false)");
4. Any further technical details
HAP version: 1.11.41
.NET 6.0
The text was updated successfully, but these errors were encountered:
1. Description
When trying to remove an attribute instance that's NOT in a HtmlAttributeCollection through the explicit interface implementation for
ICollection<HtmlAttribute>.Remove(HtmlAttribute)
, it is expected that the method returns false.However, as implemented in HAP 1.11.41 (implementing a fix for #463), it throws an exception instead of returning false.
The
ICollection<HtmlAttribute>.Remove(HtmlAttribute)
implementation inHtmlAttributeCollection
thus violates the ICollection<T>.Remove(T item) interface contract. The contract mandates (https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.icollection-1.remove?system-collections-generic-icollection-1-remove(-0)):2. Exception
3. Fiddle or Project
dotnetfiddle: https://dotnetfiddle.net/lKA3kg
Click to expand the source code
4. Any further technical details
The text was updated successfully, but these errors were encountered: