Skip to content

Commit eb6f9b4

Browse files
committed
Fix Did.from(URI) fragment rejection
1 parent 790b5bc commit eb6f9b4

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

src/main/java/com/apicatalog/did/Did.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ public static Did from(final URI uri) {
8686
if (!Did.SCHEME.equalsIgnoreCase(uri.getScheme())) {
8787
throw new IllegalArgumentException("The URI [" + uri + "] is not valid DID, must start with 'did:' prefix.");
8888
}
89+
90+
if (uri.getFragment() != null) {
91+
throw new IllegalArgumentException("The URI [" + uri + "] is not valid DID, must be in form 'did:method:method-specific-id'.");
92+
}
8993

9094
final String[] parts = uri.getSchemeSpecificPart().split(":", 2);
9195

src/test/java/com/apicatalog/did/DidTest.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,10 @@ void fromUri(String input, String method, String specificId) {
5959
@ParameterizedTest()
6060
@MethodSource({ "negativeVectors" })
6161
void fromUriNegative(String uri) {
62-
63-
final URI tmp = URI.create(uri);
64-
6562
try {
66-
Did.from(tmp);
63+
Did.from(URI.create(uri));
6764
fail();
68-
} catch (IllegalArgumentException e) {
65+
} catch (IllegalArgumentException | NullPointerException e) {
6966
/* expected */ }
7067
}
7168

0 commit comments

Comments
 (0)