strip control characters from checksums

This commit is contained in:
Mark Wolters 2024-04-11 20:14:52 -04:00 committed by Jonathan Shook
parent 26bb89f2be
commit 3ee54432d0

View File

@ -111,7 +111,7 @@ public class ResolverForNBIOCache implements ContentResolver {
Path checksumPath = checksumPath(cachedFilePath);
Files.writeString(checksumPath, localChecksumStr);
logger.debug(() -> "Generated local checksum and saved to cache at " + checksumPath);
String remoteChecksum = new String(checksum.getInputStream().readAllBytes());
String remoteChecksum = stripControlCharacters(new String(checksum.getInputStream().readAllBytes()));
if (localChecksumStr.equals(remoteChecksum)) {
return true;
} else {
@ -123,6 +123,10 @@ public class ResolverForNBIOCache implements ContentResolver {
}
}
private static String stripControlCharacters(String input) {
return input.replaceAll("[\\p{Cntrl}]+$", "");
}
/**
* This method is used to download a file from a remote URL and store it in a local cache.
* It first creates the cache directory if it doesn't exist.
@ -192,7 +196,7 @@ public class ResolverForNBIOCache implements ContentResolver {
}
try {
String localChecksum = Files.readString(getOrCreateChecksum(cachedFilePath));
String remoteChecksum = new String(checksum.getInputStream().readAllBytes());
String remoteChecksum = stripControlCharacters(new String(checksum.getInputStream().readAllBytes()));
if (localChecksum.equals(remoteChecksum)) {
return cachedFilePath;
}