refactor(metadata): update Comic ID validation to use a compiled regex pattern (#1441)
This commit is contained in:
@@ -29,6 +29,7 @@ import java.nio.file.StandardCopyOption;
|
|||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
import java.util.zip.ZipOutputStream;
|
import java.util.zip.ZipOutputStream;
|
||||||
@@ -41,6 +42,7 @@ public class CbxMetadataWriter implements MetadataWriter {
|
|||||||
|
|
||||||
// Cache JAXBContext for performance
|
// Cache JAXBContext for performance
|
||||||
private static final JAXBContext JAXB_CONTEXT;
|
private static final JAXBContext JAXB_CONTEXT;
|
||||||
|
private static final Pattern COMIC_ID_PATTERN = Pattern.compile("\\d+-\\d+");
|
||||||
|
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
@@ -230,7 +232,7 @@ public class CbxMetadataWriter implements MetadataWriter {
|
|||||||
primaryUrl = "https://comicvine.gamespot.com/volume/" + cvId + "/";
|
primaryUrl = "https://comicvine.gamespot.com/volume/" + cvId + "/";
|
||||||
} else if (cvId.startsWith("4000-")) {
|
} else if (cvId.startsWith("4000-")) {
|
||||||
primaryUrl = "https://comicvine.gamespot.com/issue/" + cvId + "/";
|
primaryUrl = "https://comicvine.gamespot.com/issue/" + cvId + "/";
|
||||||
} else if (cvId.matches("\\d+-\\d+")) {
|
} else if (COMIC_ID_PATTERN.matcher(cvId).matches()) {
|
||||||
// Already prefixed with some other Comicvine namespace; preserve as-is.
|
// Already prefixed with some other Comicvine namespace; preserve as-is.
|
||||||
primaryUrl = "https://comicvine.gamespot.com/issue/" + cvId + "/";
|
primaryUrl = "https://comicvine.gamespot.com/issue/" + cvId + "/";
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user