From 6bbd09072b6a1be766cb2417ec52c0d74ddb5b42 Mon Sep 17 00:00:00 2001 From: Alessandro Benetton Date: Sat, 1 Feb 2025 21:52:34 +0100 Subject: [PATCH] [postgres-Server-V2] fix(Chapter): Use tryParse instead of parse when comparing chapters --- API/Schema/Chapter.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/API/Schema/Chapter.cs b/API/Schema/Chapter.cs index 46771c0..97cf2f9 100644 --- a/API/Schema/Chapter.cs +++ b/API/Schema/Chapter.cs @@ -80,8 +80,7 @@ public class Chapter : IComparable { string oldPath = GetArchiveFilePath(); ArchiveFileName = BuildArchiveFileName(); - if (Downloaded) return new MoveFileOrFolderJob(oldPath, GetArchiveFilePath()); - return null; + return Downloaded ? new MoveFileOrFolderJob(oldPath, GetArchiveFilePath()) : null; } /// @@ -101,9 +100,12 @@ public class Chapter : IComparable private static int CompareChapterNumbers(string ch1, string ch2) { - int[] ch1Arr = ch1.Split('.').Select(c => int.Parse(c)).ToArray(); - int[] ch2Arr = ch2.Split('.').Select(c => int.Parse(c)).ToArray(); - + int[] ch1Arr = ch1.Split('.').Select(c => int.TryParse(c, out int result) ? result : -1).ToArray(); + int[] ch2Arr = ch2.Split('.').Select(c => int.TryParse(c, out int result) ? result : -1).ToArray(); + + if (ch1Arr.Contains(-1) || ch2Arr.Contains(-1)) + throw new ArgumentException("Chapter number is not in correct format"); + int i = 0, j = 0; while (i < ch1Arr.Length && j < ch2Arr.Length)