Update ZipString to deal with reads that do not return all data

Refine the logic in `ZipString.hash` and `ZipString.compare` to deal
with the fact a read operation may not return all available bytes.

Fixes gh-38751
This commit is contained in:
Phillip Webb
2023-12-13 13:23:46 -08:00
parent afad358047
commit b4a4e91238
3 changed files with 41 additions and 22 deletions

View File

@@ -86,7 +86,10 @@ class ZipStringTests {
case DATA_BLOCK -> {
ByteArrayDataBlock dataBlock = new ByteArrayDataBlock(source.getBytes(StandardCharsets.UTF_8));
assertThat(ZipString.hash(null, dataBlock, 0, (int) dataBlock.size(), addEndSlash)).isEqualTo(expected);
}
case SINGLE_BYTE_READ_DATA_BLOCK -> {
ByteArrayDataBlock dataBlock = new ByteArrayDataBlock(source.getBytes(StandardCharsets.UTF_8), 1);
assertThat(ZipString.hash(null, dataBlock, 0, (int) dataBlock.size(), addEndSlash)).isEqualTo(expected);
}
}
}
@@ -187,7 +190,7 @@ class ZipStringTests {
enum HashSourceType {
STRING, CHAR_SEQUENCE, DATA_BLOCK
STRING, CHAR_SEQUENCE, DATA_BLOCK, SINGLE_BYTE_READ_DATA_BLOCK
}