Throw exception if Chapternumber is not in correct format

This commit is contained in:
2025-09-21 04:44:11 +02:00
parent 9a290cdf47
commit bf148cc10f

View File

@@ -27,14 +27,17 @@ public class Chapter : Identifiable, IComparable<Chapter>
public bool Downloaded { get; internal set; } public bool Downloaded { get; internal set; }
[NotMapped] public string FullArchiveFilePath => Path.Join(ParentManga.FullDirectoryPath, FileName); [NotMapped] public string FullArchiveFilePath => Path.Join(ParentManga.FullDirectoryPath, FileName);
private static readonly Regex ChapterNumberRegex = new(@"(?:\d+\.)*\d+", RegexOptions.Compiled);
public Chapter(Manga parentManga, string chapterNumber, public Chapter(Manga parentManga, string chapterNumber,
int? volumeNumber, string? title = null) int? volumeNumber, string? title = null)
: base(TokenGen.CreateToken(typeof(Chapter), parentManga.Key, chapterNumber)) : base(TokenGen.CreateToken(typeof(Chapter), parentManga.Key, chapterNumber))
{ {
if(ChapterNumberRegex.Match(chapterNumber) is not { Success: true } match || !match.Value.Equals(chapterNumber))
throw new ArgumentException($"Invalid chapter number: {chapterNumber}");
this.ChapterNumber = chapterNumber;
this.ParentManga = parentManga; this.ParentManga = parentManga;
this.MangaConnectorIds = []; this.MangaConnectorIds = [];
this.VolumeNumber = volumeNumber; this.VolumeNumber = volumeNumber;
this.ChapterNumber = chapterNumber;
this.Title = title; this.Title = title;
this.FileName = GetArchiveFilePath().CleanNameForWindows(); this.FileName = GetArchiveFilePath().CleanNameForWindows();
this.Downloaded = false; this.Downloaded = false;
@@ -47,6 +50,8 @@ public class Chapter : Identifiable, IComparable<Chapter>
internal Chapter(string key, int? volumeNumber, string chapterNumber, string? title, string fileName, bool downloaded) internal Chapter(string key, int? volumeNumber, string chapterNumber, string? title, string fileName, bool downloaded)
: base(key) : base(key)
{ {
if(ChapterNumberRegex.Match(chapterNumber) is not { Success: true } match || !match.Value.Equals(chapterNumber))
throw new ArgumentException($"Invalid chapter number: {chapterNumber}");
this.VolumeNumber = volumeNumber; this.VolumeNumber = volumeNumber;
this.ChapterNumber = chapterNumber; this.ChapterNumber = chapterNumber;
this.Title = title; this.Title = title;