mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-07-09 03:04:19 -04:00
MinimumNumberFromRange exception (#222)
* More regex! Bonus is now a keyword for specials * Regex enhancement, Sort chapters on next/prev chapter to ensure they always in proper order, and don't set JWT on starup when in development mode. * Fixes KAVITA-H. Check to ensure non numeric characters are not in range string before attempting to parse a float out.
This commit is contained in:
parent
308e2b48a0
commit
77c52717ce
@ -121,6 +121,8 @@ namespace API.Tests.Parser
|
|||||||
[InlineData("18-04", 4)]
|
[InlineData("18-04", 4)]
|
||||||
[InlineData("18-04.5", 4.5)]
|
[InlineData("18-04.5", 4.5)]
|
||||||
[InlineData("40", 40)]
|
[InlineData("40", 40)]
|
||||||
|
[InlineData("40a-040b", 0)]
|
||||||
|
[InlineData("40.1_a", 0)]
|
||||||
public void MinimumNumberFromRangeTest(string input, float expected)
|
public void MinimumNumberFromRangeTest(string input, float expected)
|
||||||
{
|
{
|
||||||
Assert.Equal(expected, MinimumNumberFromRange(input));
|
Assert.Equal(expected, MinimumNumberFromRange(input));
|
||||||
|
@ -799,6 +799,10 @@ namespace API.Parser
|
|||||||
|
|
||||||
public static float MinimumNumberFromRange(string range)
|
public static float MinimumNumberFromRange(string range)
|
||||||
{
|
{
|
||||||
|
if (!Regex.IsMatch(range, @"^[\d-.]+$"))
|
||||||
|
{
|
||||||
|
return (float) 0.0;
|
||||||
|
}
|
||||||
var tokens = range.Replace("_", string.Empty).Split("-");
|
var tokens = range.Replace("_", string.Empty).Split("-");
|
||||||
return tokens.Min(float.Parse);
|
return tokens.Min(float.Parse);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user