|
27 | 27 |
|
28 | 28 | import jodd.net.HttpMethod; |
29 | 29 | import jodd.net.MimeTypes; |
| 30 | +import jodd.net.URLCoder; |
30 | 31 | import jodd.util.Base64; |
31 | 32 | import jodd.util.StringPool; |
32 | 33 | import jodd.util.StringUtil; |
|
37 | 38 | import java.io.InputStreamReader; |
38 | 39 | import java.io.OutputStream; |
39 | 40 | import java.io.UnsupportedEncodingException; |
40 | | -import java.net.URLEncoder; |
41 | 41 | import java.nio.charset.StandardCharsets; |
42 | 42 | import java.util.Map; |
43 | 43 | import java.util.concurrent.CompletableFuture; |
@@ -337,40 +337,37 @@ public String path() { |
337 | 337 | * Adds a slash if path doesn't start with one. |
338 | 338 | * Query will be stripped out from the path. |
339 | 339 | * Previous query is discarded. |
| 340 | + * |
340 | 341 | * @see #query() |
341 | 342 | */ |
342 | | - public HttpRequest path(String path){ |
| 343 | + public HttpRequest path(String path) { |
343 | 344 | // this must be the only place that sets the path |
344 | 345 |
|
345 | 346 | if (!path.startsWith(StringPool.SLASH)) { |
346 | 347 | path = StringPool.SLASH + path; |
347 | 348 | } |
348 | 349 |
|
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 | | - } |
356 | | - |
357 | | - final int ndx = path.indexOf('?'); |
| 350 | + // remove fragment |
| 351 | + final int fragmentIndex = path.indexOf('#'); |
| 352 | + if (path.indexOf('#') != -1) { |
| 353 | + this.fragment = URLCoder.encodePath(path.substring(fragmentIndex + 1), StandardCharsets.UTF_8); |
| 354 | + path = path.substring(0, fragmentIndex); |
| 355 | + } |
358 | 356 |
|
359 | | - if (ndx != -1) { |
360 | | - final String queryString = path.substring(ndx + 1); |
| 357 | + final int ndx = path.indexOf('?'); |
361 | 358 |
|
362 | | - path = URLEncoder.encode(path.substring(0, ndx), StandardCharsets.UTF_8.name()); |
| 359 | + if (ndx != -1) { |
| 360 | + final String queryString = path.substring(ndx + 1); |
363 | 361 |
|
364 | | - query = HttpUtil.parseQuery(queryString, true); |
365 | | - } else { |
366 | | - query = HttpMultiMap.newCaseInsensitiveMap(); |
367 | | - } |
| 362 | + path = URLCoder.encodePath(path.substring(0, ndx), StandardCharsets.UTF_8); |
368 | 363 |
|
369 | | - this.path = URLEncoder.encode(path, StandardCharsets.UTF_8.name()); |
370 | | - ; |
371 | | - }catch (UnsupportedEncodingException e) { |
372 | | - return null; |
| 364 | + query = HttpUtil.parseQuery(queryString, true); |
| 365 | + } else { |
| 366 | + query = HttpMultiMap.newCaseInsensitiveMap(); |
373 | 367 | } |
| 368 | + |
| 369 | + this.path = URLCoder.encodePath(path, StandardCharsets.UTF_8); |
| 370 | + |
374 | 371 | return this; |
375 | 372 | } |
376 | 373 |
|
|
0 commit comments