garydgregory commented on code in PR #581: URL: https://github.com/apache/httpcomponents-client/pull/581#discussion_r1769461453
########## httpclient5/src/main/java/org/apache/hc/client5/http/ssl/SSLConnectionSocketFactory.java: ########## @@ -456,4 +461,33 @@ void verifySession( } } + /** + * Converts an X500Principal to a cleaned string by escaping control characters. + * <p> + * This method processes the RFC2253 format of the X500Principal and escapes + * any ISO control characters to avoid issues in logging or other outputs. + * Control characters are replaced with their escaped hexadecimal representation. + * </p> + * + * <p><strong>Note:</strong> For testing purposes, this method is package-private + * to allow access within the same package. This allows tests to verify the correct + * behavior of the escaping process.</p> + * + * @param principal the X500Principal to escape + * @return the escaped string representation of the X500Principal + */ + @Internal + String toEscapedString(final X500Principal principal) { + final String principalValue = principal.getName(X500Principal.RFC2253); + final StringBuilder sanitizedPrincipal = new StringBuilder(principalValue.length()); + for (final char c : principalValue.toCharArray()) { + if (Character.isISOControl(c)) { + sanitizedPrincipal.append("\\x").append(String.format("%02x", (int) c)); Review Comment: I just remembered that we already do this kind of cleaning/escaping in `org.apache.hc.core5.testing.nio.LoggingIOSession.logData(ByteBuffer, String)`. There may be an opportunity for some refactoring so that we use the same semantics for printing raw data. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org For additional commands, e-mail: dev-h...@hc.apache.org