From b094034868f621f0dea4368e3951fbab0e7052c9 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Fri, 23 Feb 2024 10:20:15 -0600 Subject: [PATCH 1/2] 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 fffb1cd8bdc7..c346945cec42 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 @@ private static Set copyOf(Set violations) 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 : UriCompliance.Violation.values()) + { + if (uri.hasViolation(violation) && (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; } From e55634abb6c3505b956cb8f807b5964ba1fe1f0f Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Mon, 26 Feb 2024 09:45:37 -0600 Subject: [PATCH 2/2] Changes from review --- .../src/main/java/org/eclipse/jetty/http/UriCompliance.java | 4 ++-- 1 file changed, 2 insertions(+), 2 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 c346945cec42..e1d16ed11e85 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 @@ -360,9 +360,9 @@ public static String checkUriCompliance(UriCompliance compliance, HttpURI uri, C if (uri.hasViolations()) { StringBuilder violations = null; - for (UriCompliance.Violation violation : UriCompliance.Violation.values()) + for (UriCompliance.Violation violation : uri.getViolations()) { - if (uri.hasViolation(violation) && (compliance == null || !compliance.allows(violation))) + if (compliance == null || !compliance.allows(violation)) { if (listener != null) listener.onComplianceViolation(new ComplianceViolation.Event(compliance, violation, uri.toString()));