|
36 | 36 | import java.util.function.Function;
|
37 | 37 | import java.util.function.Predicate;
|
38 | 38 |
|
| 39 | +import org.eclipse.jetty.http.BadMessageException; |
39 | 40 | import org.eclipse.jetty.http.ComplianceViolation;
|
40 | 41 | import org.eclipse.jetty.http.HttpCookie;
|
41 | 42 | import org.eclipse.jetty.http.HttpFields;
|
@@ -559,27 +560,38 @@ static Fields extractQueryParameters(Request request)
|
559 | 560 |
|
560 | 561 | static Fields extractQueryParameters(Request request, Charset charset)
|
561 | 562 | {
|
562 |
| - String query = request.getHttpURI().getQuery(); |
563 |
| - if (StringUtil.isBlank(query)) |
564 |
| - return Fields.EMPTY; |
565 |
| - Fields fields = new Fields(true); |
566 |
| - |
567 |
| - if (charset == null || StandardCharsets.UTF_8.equals(charset)) |
| 563 | + UriCompliance uriCompliance = null; |
| 564 | + try |
568 | 565 | {
|
569 |
| - UriCompliance uriCompliance = request.getConnectionMetaData().getHttpConfiguration().getUriCompliance(); |
570 |
| - boolean allowBadUtf8 = uriCompliance.allows(UriCompliance.Violation.BAD_UTF8_ENCODING); |
571 |
| - if (!UrlEncoded.decodeUtf8To(query, 0, query.length(), fields::add, allowBadUtf8)) |
| 566 | + String query = request.getHttpURI().getQuery(); |
| 567 | + if (StringUtil.isBlank(query)) |
| 568 | + return Fields.EMPTY; |
| 569 | + Fields fields = new Fields(true); |
| 570 | + |
| 571 | + if (charset == null || StandardCharsets.UTF_8.equals(charset)) |
| 572 | + { |
| 573 | + uriCompliance = request.getConnectionMetaData().getHttpConfiguration().getUriCompliance(); |
| 574 | + boolean allowTruncatedUtf8 = uriCompliance.allows(UriCompliance.Violation.TRUNCATED_UTF8_ENCODING); |
| 575 | + boolean allowBadUtf8 = uriCompliance.allows(UriCompliance.Violation.BAD_UTF8_ENCODING); |
| 576 | + if (!UrlEncoded.decodeUtf8To(query, 0, query.length(), fields::add, allowTruncatedUtf8, allowBadUtf8)) |
| 577 | + { |
| 578 | + HttpChannel httpChannel = HttpChannel.from(request); |
| 579 | + if (httpChannel != null && httpChannel.getComplianceViolationListener() != null) |
| 580 | + httpChannel.getComplianceViolationListener().onComplianceViolation(new ComplianceViolation.Event(uriCompliance, UriCompliance.Violation.BAD_UTF8_ENCODING, "query=" + query)); |
| 581 | + } |
| 582 | + } |
| 583 | + else |
572 | 584 | {
|
573 |
| - HttpChannel httpChannel = HttpChannel.from(request); |
574 |
| - if (httpChannel != null && httpChannel.getComplianceViolationListener() != null) |
575 |
| - httpChannel.getComplianceViolationListener().onComplianceViolation(new ComplianceViolation.Event(uriCompliance, UriCompliance.Violation.BAD_UTF8_ENCODING, "query=" + query)); |
| 585 | + UrlEncoded.decodeTo(query, fields::add, charset); |
576 | 586 | }
|
| 587 | + return fields; |
577 | 588 | }
|
578 |
| - else |
| 589 | + catch (Throwable t) |
579 | 590 | {
|
580 |
| - UrlEncoded.decodeTo(query, fields::add, charset); |
| 591 | +// if (uriCompliance == UriCompliance.LEGACY) |
| 592 | +// throw t; |
| 593 | + throw new BadMessageException("Bad query", t); |
581 | 594 | }
|
582 |
| - return fields; |
583 | 595 | }
|
584 | 596 |
|
585 | 597 | static Fields getParameters(Request request) throws Exception
|
|
0 commit comments