ukdtom / ClaimIt

ClaimIt 4 Plex Media Server
Mozilla Public License 2.0
74 stars 19 forks source link

`ipAddress` string.Split() could use a comma :) #33

Closed mm98 closed 2 years ago

mm98 commented 2 years ago

I tried to use this tool earlier today. For some strange reason, on my Win11 the ipAddress entry was submitted with commas and not with periods, which made the app crash (separator must exist in ipAddress). It did show period in the UI. I had to download the source to add the following to make it work.

Added comma as a second separator on the string split.

int[] ipParts = ipAddress.Split(new String[] { ".", "," }, StringSplitOptions.RemoveEmptyEntries)
                                     .Select(s => int.Parse(s)).ToArray();

https://github.com/ukdtom/ClaimIt/blob/e9794997b15615d4d59de86a3942e553dec7228c/Windows/ClaimIt/Form1.cs#L278

cremor commented 2 years ago

The most likely problem is that the app uses culture specific number separators when parsing the ip address. Instead it should always use CultureInfo.InvariantCulture to parse it.

This is the exception:

System.FormatException: Die Eingabezeichenfolge hat das falsche Format.
   bei System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
   bei System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
   bei ClaimIt.Form1.<>c.<_IsPrivate>b__40_0(String s)
   bei System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
   bei System.Linq.Buffer`1..ctor(IEnumerable`1 source)
   bei System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   bei ClaimIt.Form1._IsPrivate(String ipAddress)
   bei ClaimIt.Form1.BtnClaimIt_Click(Object sender, EventArgs e)
ukdtom commented 2 years ago

Windows version has been replaced with this one https://github.com/ukdtom/ClaimPMS4Win/releases/latest