From bfa0515e82f5cbd2e25d007b889decde407fe81e Mon Sep 17 00:00:00 2001 From: reinkrul Date: Tue, 25 Jul 2023 10:10:14 +0200 Subject: [PATCH] WithoutURL must also copy DecodedID (#78) --- did/did.go | 5 +++-- did/did_test.go | 17 ++++++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/did/did.go b/did/did.go index 4624d4a..b24f849 100644 --- a/did/did.go +++ b/did/did.go @@ -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, } } diff --git a/did/did_test.go b/did/did_test.go index 1548370..6dc692f 100644 --- a/did/did_test.go +++ b/did/did_test.go @@ -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)) + }) }