Skip to content
This repository was archived by the owner on Apr 7, 2026. It is now read-only.

Commit 2817b91

Browse files
committed
fix test
1 parent a319a31 commit 2817b91

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

  • google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1

google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/KeyRecipe.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,22 @@ private static long[] parseUuid(String uuid) {
568568
} else if (uuid.endsWith("}")) {
569569
throw new IllegalArgumentException("Invalid UUID string: " + originalUuid);
570570
}
571+
if (uuid.length() != 36
572+
|| uuid.charAt(8) != '-'
573+
|| uuid.charAt(13) != '-'
574+
|| uuid.charAt(18) != '-'
575+
|| uuid.charAt(23) != '-') {
576+
throw new IllegalArgumentException("Invalid UUID string: " + originalUuid);
577+
}
578+
for (int i = 0; i < uuid.length(); i++) {
579+
if (i == 8 || i == 13 || i == 18 || i == 23) {
580+
continue;
581+
}
582+
char c = uuid.charAt(i);
583+
if (!isHexChar(c)) {
584+
throw new IllegalArgumentException("Invalid UUID string: " + originalUuid);
585+
}
586+
}
571587
try {
572588
UUID parsed = UUID.fromString(uuid);
573589
return new long[] {parsed.getMostSignificantBits(), parsed.getLeastSignificantBits()};
@@ -576,6 +592,10 @@ private static long[] parseUuid(String uuid) {
576592
}
577593
}
578594

595+
private static boolean isHexChar(char c) {
596+
return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F');
597+
}
598+
579599
private TargetRange encodeKeyInternal(
580600
BiFunction<Integer, String, Value> valueFinder, KeyType keyType) {
581601
UnsynchronizedByteArrayOutputStream ssKey = new UnsynchronizedByteArrayOutputStream();

0 commit comments

Comments
 (0)