R2D221 / WebView2.DOM

C# DOM bindings to be used with WebView2
MIT License
51 stars 10 forks source link

When calling the method ToArray of the HTMLOptionsCollection class a stackoverflow exception is thrown #15

Open Jeroen3000 opened 2 months ago

Jeroen3000 commented 2 months ago

Hi, nice library. Source code is a bit complex. Anyway, when calling the ToArray method on the HTMLOptionsCollection class it is using internally the CopyTo method, but his method is overridden and is calling ToArray again recursively. etc.. which leads to a stack overflow

I think a possible solution is to implement the CopyTo as follows:

_void ICollection.CopyTo(HTMLOptionElement[] array, int arrayIndex) { if (array == null) throw new ArgumentNullException(nameof(array)); if (arrayIndex < 0) throw new ArgumentOutOfRangeException(nameof(arrayIndex)); if (array.Length - arrayIndex < Count) throw new ArgumentException("Not enough elements after arrayIndex in the destination array.");

 for (int i = 0; i < Count; ++i)
     array[i + arrayIndex] = this[i];

}_