Skip to content

Commit

Permalink
WithoutURL must also copy DecodedID (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
reinkrul authored Jul 25, 2023
1 parent 3f17c03 commit bfa0515
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
5 changes: 3 additions & 2 deletions did/did.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,9 @@ func (d DID) URI() ssi.URI {
// WithoutURL returns a copy of the DID without URL parts (fragment, query, path).
func (d DID) WithoutURL() DID {
return DID{
Method: d.Method,
ID: d.ID,
Method: d.Method,
ID: d.ID,
DecodedID: d.DecodedID,
}
}

Expand Down
17 changes: 12 additions & 5 deletions did/did_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,9 +460,16 @@ func TestError(t *testing.T) {
}

func TestDID_WithoutURL(t *testing.T) {
id := MustParseDIDURL("did:example:123/path?key=value#fragment").WithoutURL()
assert.Equal(t, "did:example:123", id.String())
assert.Empty(t, id.Path)
assert.Empty(t, id.Fragment)
assert.Empty(t, id.Query)
t.Run("with encoded ID", func(t *testing.T) {
id := MustParseDIDURL("did:example:123%20/path?key=value#fragment").WithoutURL()
assert.Equal(t, "did:example:123%20", id.String())
assert.Equal(t, "123 ", id.DecodedID)
assert.Empty(t, id.Path)
assert.Empty(t, id.Fragment)
assert.Empty(t, id.Query)
})
t.Run("equalness", func(t *testing.T) {
id := MustParseDIDURL("did:example:123/path?key=value#fragment").WithoutURL()
assert.True(t, MustParseDID("did:example:123").Equals(id))
})
}

0 comments on commit bfa0515

Please sign in to comment.