From 866f44584c80839d20f41ae4eb2c93680d7a0d5e Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Tue, 27 Feb 2024 04:32:07 -0800 Subject: [PATCH] Issue #11361 - UriCompliance.checkUriCompliance improvements (#11444) * Issue #11361 - UriCompliance.checkUriCompliance improvements --- .../org/eclipse/jetty/http/UriCompliance.java | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/UriCompliance.java b/jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/UriCompliance.java index fffb1cd8bdc..e1d16ed11e8 100644 --- a/jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/UriCompliance.java +++ b/jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/UriCompliance.java @@ -357,12 +357,25 @@ public final class UriCompliance implements ComplianceViolation.Mode public static String checkUriCompliance(UriCompliance compliance, HttpURI uri, ComplianceViolation.Listener listener) { - for (UriCompliance.Violation violation : UriCompliance.Violation.values()) + if (uri.hasViolations()) { - if (uri.hasViolation(violation) && (compliance == null || !compliance.allows(violation))) - return violation.getDescription(); - else if (listener != null) - listener.onComplianceViolation(new ComplianceViolation.Event(compliance, violation, uri.toString())); + StringBuilder violations = null; + for (UriCompliance.Violation violation : uri.getViolations()) + { + if (compliance == null || !compliance.allows(violation)) + { + if (listener != null) + listener.onComplianceViolation(new ComplianceViolation.Event(compliance, violation, uri.toString())); + + if (violations == null) + violations = new StringBuilder(); + else + violations.append(", "); + violations.append(violation.getDescription()); + } + } + if (violations != null) + return violations.toString(); } return null; }