Skip to content

Commit

Permalink
Support case insensitive UUIDs (#544)
Browse files Browse the repository at this point in the history
Closes #536
  • Loading branch information
chrisrohr authored Apr 13, 2021
1 parent c24e313 commit e622a01
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/kiwiproject/base/UUIDs.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class UUIDs {
private static final String NIL_UUID = "00000000-0000-0000-0000-000000000000";

private static final Pattern RFC4122_PATTERN =
Pattern.compile("^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}");
Pattern.compile("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}");

/**
* Creates a new type 4 (pseudo randomly generated) UUID, and then returns it as a string.
Expand Down
18 changes: 15 additions & 3 deletions src/test/java/org/kiwiproject/base/UUIDsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.params.provider.ValueSource;

import java.util.Locale;
import java.util.Random;
import java.util.UUID;
import java.util.function.Predicate;
Expand Down Expand Up @@ -67,6 +67,19 @@ void shouldBeTrue_ForValidType3UUIDs_UsingUUIDConstructor(SoftAssertions softly)
});
}

@ParameterizedTest
@ValueSource(strings = {
"015186F5-539d-4bcb-b3bc-34718931ef37",
"015186f5-539D-4bcb-b3bc-34718931ef37",
"015186f5-539d-4BCB-b3bc-34718931ef37",
"015186f5-539d-4bcb-B3BC-34718931ef37",
"015186f5-539d-4bcb-b3bc-34718931EF37",
"015186F5-539D-4BCB-B3BC-34718931EF37"
})
void shouldBeTrue_ForUppercaseUUIDs(String uuid, SoftAssertions softly) {
assertValidUUIDs(softly, () -> UUID.fromString(uuid));
}

@ParameterizedTest
@MethodSource("org.kiwiproject.base.UUIDsTest#invalidUUIDs")
void shouldBeFalse_ForInvalidUUIDs(String value) {
Expand Down Expand Up @@ -148,8 +161,7 @@ static Stream<String> invalidUUIDs() {
"!",
"abcd-56-efg",
UUIDs.randomUUIDString().substring(0, 35),
UUIDs.randomUUIDString().substring(1),
UUIDs.randomUUIDString().toUpperCase(Locale.ENGLISH)
UUIDs.randomUUIDString().substring(1)
);
}

Expand Down

0 comments on commit e622a01

Please sign in to comment.