refactor(regex): replace string manipulation with regex patterns for improved clarity and performance (#869)

This commit is contained in:
brios
2026-04-30 06:28:42 +00:00
committed by GitHub
parent 72cd021d0a
commit b22fa38642
13 changed files with 59 additions and 23 deletions
@@ -23,6 +23,7 @@ import java.time.LocalDate;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Pattern;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipOutputStream;
@@ -33,6 +34,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
@EnabledIf("org.booklore.service.ArchiveService#isAvailable")
class CbxComicInfoComplianceTest {
private static final Pattern EMPTY_LINES_PATTERN = Pattern.compile("(?s).*\\n\\s*\\n\\s*<.*");
private CbxMetadataWriter writer;
private Path tempDir;
@@ -117,7 +119,7 @@ class CbxComicInfoComplianceTest {
assertOrder(xmlContent, "Web", "PageCount");
// 2. Verify Formatting
assertFalse(xmlContent.matches("(?s).*\\n\\s*\\n\\s*<.*"), "Should not have empty lines between elements");
assertFalse(EMPTY_LINES_PATTERN.matcher(xmlContent).matches(), "Should not have empty lines between elements");
// 3. Verify HTML Stripping in Summary
assertTrue(xmlContent.contains("<Summary>On his own and out of options, Hughie resorts to extreme measures...</Summary>"));