Issue #11361 - UriCompliance.checkUriCompliance improvements (#11444)

* Issue #11361 - UriCompliance.checkUriCompliance improvements
This commit is contained in:
Joakim Erdfelt 2024-02-27 04:32:07 -08:00 committed by GitHub
parent d3f19bb947
commit 866f44584c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 18 additions and 5 deletions

View File

@ -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;
}