@@ -259,11 +259,10 @@ public static URI buildUri(String scheme, String host, int port, String path, St
259
259
// workaround for https://bugs.openjdk.java.net/browse/JDK-8037396
260
260
uriString = uriString .replace ("[" , "%5B" ).replace ("]" , "%5D" );
261
261
262
- // replace double-slash with /%2f (workaround for apache client)
263
- if (path != null && path .length () > 2 && path .charAt (0 ) == '/' && path .charAt (1 ) == '/' ) {
264
- int doubleSlashIndex = uriString .indexOf ("//" );
265
- if (scheme != null ) doubleSlashIndex = uriString .indexOf ("//" , doubleSlashIndex + 2 );
266
- uriString = uriString .substring (0 , doubleSlashIndex ) + "/%2F" + uriString .substring (doubleSlashIndex + 2 );
262
+ // replace double-slash with /%2f (otherwise apache client will normalize it to one slash)
263
+ if (path .contains ("//" )) {
264
+ if (scheme != null ) uriString = uriString .substring (0 , 8 ) + uriString .substring (8 ).replaceAll ("//" , "/%2F" );
265
+ else uriString = uriString .replaceAll ("//" , "/%2F" );
267
266
}
268
267
269
268
// Special case to handle "+" characters that URI doesn't handle well.
@@ -286,9 +285,9 @@ public static URI buildUri(String scheme, String host, int port, String path, St
286
285
* this method works as if by invoking that method and then
287
286
* <a href="#encode">encoding</a> the result. </p>
288
287
*
289
- * @return The string form of this URI, encoded as needed
290
- * so that it only contains characters in the US-ASCII
291
- * charset
288
+ * @return The string form of this URI, encoded as needed
289
+ * so that it only contains characters in the US-ASCII
290
+ * charset
292
291
*/
293
292
public static String toASCIIString (URI u ) {
294
293
String s = defineString (u );
@@ -354,7 +353,7 @@ private static String encode(String s) {
354
353
return s ;
355
354
356
355
// First check whether we actually need to encode
357
- for (int i = 0 ;; ) {
356
+ for (int i = 0 ; ; ) {
358
357
if (s .charAt (i ) >= '\u0080' )
359
358
break ;
360
359
if (++i >= n )
@@ -372,9 +371,9 @@ private static String encode(String s) {
372
371
while (bb .hasRemaining ()) {
373
372
int b = bb .get () & 0xff ;
374
373
if (b >= 0x80 )
375
- appendEscape (sb , (byte )b );
374
+ appendEscape (sb , (byte ) b );
376
375
else
377
- sb .append ((char )b );
376
+ sb .append ((char ) b );
378
377
}
379
378
return sb .toString ();
380
379
}
@@ -398,6 +397,7 @@ public static URI replaceHost(URI uri, String host) throws URISyntaxException {
398
397
public static URI replacePath (URI uri , String path ) throws URISyntaxException {
399
398
return buildUri (uri .getScheme (), uri .getHost (), uri .getPort (), path , uri .getRawQuery (), uri .getRawFragment ());
400
399
}
400
+
401
401
private static DateFormat getHeaderFormat () {
402
402
DateFormat format = headerFormat .get ();
403
403
if (format == null ) {
@@ -409,11 +409,11 @@ private static DateFormat getHeaderFormat() {
409
409
}
410
410
411
411
public static String join (String separator , Iterable <String > items ) {
412
- if (separator == null ) throw new IllegalArgumentException ("separator argument is null" );
413
- if (items == null ) throw new IllegalArgumentException ("items argument is null" );
412
+ if (separator == null ) throw new IllegalArgumentException ("separator argument is null" );
413
+ if (items == null ) throw new IllegalArgumentException ("items argument is null" );
414
414
StringBuilder sb = new StringBuilder ();
415
- for (String item : items ) {
416
- if (sb .length () > 0 ) sb .append (separator );
415
+ for (String item : items ) {
416
+ if (sb .length () > 0 ) sb .append (separator );
417
417
sb .append (item );
418
418
}
419
419
return sb .toString ();
0 commit comments