File tree Expand file tree Collapse file tree
main/java/com/apicatalog/did
test/java/com/apicatalog/did Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -137,25 +137,31 @@ public DidUrl asDidUrl() {
137137 public String toString () {
138138 final StringBuilder builder = new StringBuilder (super .toString ());
139139
140- if (Did . isNotBlank ( path ) ) {
141- if (path .charAt (0 ) != '/' ) {
140+ if (path != null ) {
141+ if (path .length () == 0 || path . charAt (0 ) != '/' ) {
142142 builder .append ('/' );
143143 }
144- builder .append (path );
144+ if (path .length () > 0 ) {
145+ builder .append (path );
146+ }
145147 }
146148
147- if (Did . isNotBlank ( query ) ) {
148- if (query .charAt (0 ) != '?' ) {
149+ if (query != null ) {
150+ if (query .length () == 0 || query . charAt (0 ) != '?' ) {
149151 builder .append ('?' );
150152 }
151- builder .append (query );
153+ if (query .length () > 0 ) {
154+ builder .append (query );
155+ }
152156 }
153157
154- if (Did . isNotBlank ( fragment ) ) {
155- if (fragment .charAt (0 ) != '#' ) {
158+ if (fragment != null ) {
159+ if (fragment .length () == 0 || fragment . charAt (0 ) != '#' ) {
156160 builder .append ('#' );
157161 }
158- builder .append (fragment );
162+ if (fragment .length () > 0 ) {
163+ builder .append (fragment );
164+ }
159165 }
160166
161167 return builder .toString ();
Original file line number Diff line number Diff line change @@ -71,7 +71,7 @@ void stringIsDid(String uri) {
7171 void uriIsDid (String uri ) {
7272 assertTrue (DidUrl .isDidUrl (URI .create (uri )));
7373 }
74-
74+
7575 @ DisplayName ("toString()" )
7676 @ ParameterizedTest (name = "{0}" )
7777 @ MethodSource ({ "validVectors" })
@@ -163,6 +163,22 @@ static Stream<String[]> validVectors() {
163163 null ,
164164 null ,
165165 ""
166+ },
167+ {
168+ "did:example:a/" ,
169+ "example" ,
170+ "a" ,
171+ "/" ,
172+ null ,
173+ null
174+ },
175+ {
176+ "did:example:a/?#" ,
177+ "example" ,
178+ "a" ,
179+ "/" ,
180+ "" ,
181+ ""
166182 }
167183
168184 });
You can’t perform that action at this time.
0 commit comments