|
37 | 37 | import java.io.InputStreamReader; |
38 | 38 | import java.io.OutputStream; |
39 | 39 | import java.io.UnsupportedEncodingException; |
| 40 | +import java.net.URLEncoder; |
40 | 41 | import java.nio.charset.StandardCharsets; |
41 | 42 | import java.util.Map; |
42 | 43 | import java.util.concurrent.CompletableFuture; |
@@ -338,35 +339,38 @@ public String path() { |
338 | 339 | * Previous query is discarded. |
339 | 340 | * @see #query() |
340 | 341 | */ |
341 | | - public HttpRequest path(String path) { |
| 342 | + public HttpRequest path(String path){ |
342 | 343 | // this must be the only place that sets the path |
343 | 344 |
|
344 | 345 | if (!path.startsWith(StringPool.SLASH)) { |
345 | 346 | path = StringPool.SLASH + path; |
346 | 347 | } |
347 | 348 |
|
348 | | - // remove fragment |
| 349 | + try { |
| 350 | + // remove fragment |
| 351 | + final int fragmentIndex = path.indexOf('#'); |
| 352 | + if (path.indexOf('#') != -1) { |
| 353 | + this.fragment = URLEncoder.encode(path.substring(fragmentIndex + 1), StandardCharsets.UTF_8.name()); |
| 354 | + path = path.substring(0, fragmentIndex); |
| 355 | + } |
349 | 356 |
|
350 | | - final int fragmentIndex = path.indexOf('#'); |
351 | | - if (path.indexOf('#') != -1) { |
352 | | - this.fragment = path.substring(fragmentIndex + 1); |
353 | | - path = path.substring(0, fragmentIndex); |
354 | | - } |
| 357 | + final int ndx = path.indexOf('?'); |
355 | 358 |
|
356 | | - final int ndx = path.indexOf('?'); |
| 359 | + if (ndx != -1) { |
| 360 | + final String queryString = path.substring(ndx + 1); |
357 | 361 |
|
358 | | - if (ndx != -1) { |
359 | | - final String queryString = path.substring(ndx + 1); |
| 362 | + path = URLEncoder.encode(path.substring(0, ndx), StandardCharsets.UTF_8.name()); |
360 | 363 |
|
361 | | - path = path.substring(0, ndx); |
| 364 | + query = HttpUtil.parseQuery(queryString, true); |
| 365 | + } else { |
| 366 | + query = HttpMultiMap.newCaseInsensitiveMap(); |
| 367 | + } |
362 | 368 |
|
363 | | - query = HttpUtil.parseQuery(queryString, true); |
364 | | - } else { |
365 | | - query = HttpMultiMap.newCaseInsensitiveMap(); |
| 369 | + this.path = URLEncoder.encode(path, StandardCharsets.UTF_8.name()); |
| 370 | + ; |
| 371 | + }catch (UnsupportedEncodingException e) { |
| 372 | + return null; |
366 | 373 | } |
367 | | - |
368 | | - this.path = path; |
369 | | - |
370 | 374 | return this; |
371 | 375 | } |
372 | 376 |
|
|
0 commit comments