Skip to content

Kavita is a fast, feature rich, cross platform reading server. Built with the goal of being a full solution for all your reading needs. Setup your own server and share your reading collection with your friends and family.

MinimumNumberFromRange exception (#222)

Joseph Milazzo77c52717cebd
diff --git a/API.Tests/Parser/ParserTest.cs b/API.Tests/Parser/ParserTest.cs
index 2f46c6bb2..314c7cd11 100644
--- a/API.Tests/Parser/ParserTest.cs
+++ b/API.Tests/Parser/ParserTest.cs
@@ -121,6 +121,8 @@ namespace API.Tests.Parser
[InlineData("18-04", 4)]
[InlineData("18-04.5", 4.5)]
[InlineData("40", 40)]
+ [InlineData("40a-040b", 0)]
+ [InlineData("40.1_a", 0)]
public void MinimumNumberFromRangeTest(string input, float expected)
{
Assert.Equal(expected, MinimumNumberFromRange(input));
diff --git a/API/Parser/Parser.cs b/API/Parser/Parser.cs
index 024f11640..45b8940e7 100644
--- a/API/Parser/Parser.cs
+++ b/API/Parser/Parser.cs
@@ -799,6 +799,10 @@ namespace API.Parser
public static float MinimumNumberFromRange(string range)
{
+ if (!Regex.IsMatch(range, @"^[\d-.]+$"))
+ {
+ return (float) 0.0;
+ }
var tokens = range.Replace("_", string.Empty).Split("-");
return tokens.Min(float.Parse);
}