@@ -117,7 +117,12 @@ public static boolean isDidUrl(final String uri) {
117117 @ Override
118118 public URI toUri () {
119119 try {
120- return new URI (SCHEME , method + ":" + specificId , path , query , fragment );
120+ return new URI (SCHEME ,
121+ appendPathQuery (new StringBuilder ()
122+ .append (method )
123+ .append (':' )
124+ .append (specificId )).toString (),
125+ fragment );
121126 } catch (URISyntaxException e ) {
122127 throw new IllegalStateException (e );
123128 }
@@ -137,6 +142,21 @@ public DidUrl asDidUrl() {
137142 public String toString () {
138143 final StringBuilder builder = new StringBuilder (super .toString ());
139144
145+ appendPathQuery (builder );
146+
147+ if (fragment != null ) {
148+ if (fragment .length () == 0 || fragment .charAt (0 ) != '#' ) {
149+ builder .append ('#' );
150+ }
151+ if (fragment .length () > 0 ) {
152+ builder .append (fragment );
153+ }
154+ }
155+
156+ return builder .toString ();
157+ }
158+
159+ protected StringBuilder appendPathQuery (final StringBuilder builder ) {
140160 if (path != null ) {
141161 if (path .length () == 0 || path .charAt (0 ) != '/' ) {
142162 builder .append ('/' );
@@ -151,20 +171,10 @@ public String toString() {
151171 builder .append ('?' );
152172 }
153173 if (query .length () > 0 ) {
154- builder .append (query );
155- }
156- }
157-
158- if (fragment != null ) {
159- if (fragment .length () == 0 || fragment .charAt (0 ) != '#' ) {
160- builder .append ('#' );
161- }
162- if (fragment .length () > 0 ) {
163- builder .append (fragment );
174+ builder .append (query );
164175 }
165176 }
166-
167- return builder .toString ();
177+ return builder ;
168178 }
169179
170180 @ Override
0 commit comments