This is an automated email from the ASF dual-hosted git repository. rmaucher pushed a commit to branch 10.1.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit 962a4f4a9aba540e5528a18a6cd9b6c3dcc50e3c Author: opencode <[email protected]> AuthorDate: Tue Dec 1 21:18:34 2026 +0100 Preserve escaped semicolons in connection properties The parser replaced every semicolon with a newline before Properties.load, so the semicolon of an escaped \; was also replaced. Properties.load then saw a trailing backslash as a line continuation and silently dropped the literal semicolon from the value. Replace only semicolons preceded by an even number of backslashes with newlines, and leave escaped semicolons for Properties.load to decode. Add tests covering one, two, and three backslashes and the static parser path. mvn test passes: 1181 tests, 0 failures. --- .../apache/tomcat/jdbc/pool/PoolProperties.java | 32 ++++++++++++++++++++-- .../tomcat/jdbc/pool/PoolPropertiesBase.java | 28 +++++++++++++++++++ 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/PoolProperties.java b/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/PoolProperties.java index 478a31bff5..127a8347c5 100644 --- a/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/PoolProperties.java +++ b/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/PoolProperties.java @@ -2579,7 +2579,8 @@ public class PoolProperties implements PoolConfiguration, Cloneable, Serializabl /** - * Parses a property string into a Properties object. + * Parses a property string into a Properties object. Pairs are separated by semicolons; a semicolon that is part + * of a value may be escaped as {@code \;}, and the escape is preserved for the {@link Properties} reader. * * @param propText the property string with semicolon-separated key=value pairs * @param props the Properties object to populate, or null to create a new one @@ -2597,7 +2598,7 @@ public class PoolProperties implements PoolConfiguration, Cloneable, Serializabl // charset, silently corrupting any non-ASCII value on a // UTF-8-default JVM. A Reader carries the exact characters, so no // charset conversion takes place at all. - props.load(new StringReader(propText.replace(';', '\n'))); + props.load(new StringReader(separateConnectionProperties(propText))); } catch (IOException ioe) { throw new IllegalArgumentException(MessageFactory.get( "poolProperties.invalidConnectionProperties", ioe.getMessage()), ioe); @@ -2612,6 +2613,33 @@ public class PoolProperties implements PoolConfiguration, Cloneable, Serializabl return props; } + + /** + * Replaces the semicolons that separate the pairs of a connection-properties string with new lines, leaving an + * escaped semicolon ({@code \;}) intact for the {@link Properties} reader to decode. A semicolon is escaped when + * an odd number of backslashes immediately precede it, so the literal backslashes of a value such as {@code \\;} + * still let the semicolon separate the next pair. + * + * @param propText the connection-properties string, not {@code null} + * + * @return the string with unescaped semicolons turned into line breaks + */ + private static String separateConnectionProperties(String propText) { + StringBuilder separated = new StringBuilder(propText.length()); + boolean escaped = false; + for (int i = 0; i < propText.length(); i++) { + char c = propText.charAt(i); + if (c == '\\') { + escaped = !escaped; + separated.append(c); + } else { + separated.append(c == ';' && !escaped ? '\n' : c); + escaped = false; + } + } + return separated.toString(); + } + @Override public boolean isAlternateUsernameAllowed() { return alternateUsernameAllowed; diff --git a/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/pool/PoolPropertiesBase.java b/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/pool/PoolPropertiesBase.java index c1b3e5eba9..2dcaa5be41 100644 --- a/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/pool/PoolPropertiesBase.java +++ b/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/pool/PoolPropertiesBase.java @@ -1367,6 +1367,34 @@ abstract class PoolPropertiesBase { "the next pair must stay readable on the sanitised one-line dump, was: " + asString); } + @Test + void escapedSemicolonInConnectionPropertiesIsALiteralValue() { + PoolProperties properties = new PoolProperties(); + properties.setConnectionProperties("password=se\\;cret;foo=bar"); + Assertions.assertEquals("se;cret", properties.getDbProperties().getProperty("password"), + "an escaped semicolon must stay part of the value"); + Assertions.assertEquals("bar", properties.getDbProperties().getProperty("foo"), + "the pair after the escaped semicolon must still parse"); + + properties.setConnectionProperties("password=se\\\\;foo=bar"); + Assertions.assertEquals("se\\", properties.getDbProperties().getProperty("password"), + "two backslashes leave a literal backslash and let the semicolon separate"); + Assertions.assertEquals("bar", properties.getDbProperties().getProperty("foo"), + "the pair after the unescaped semicolon must parse"); + + properties.setConnectionProperties("password=se\\\\\\;cret;foo=bar"); + Assertions.assertEquals("se\\;cret", properties.getDbProperties().getProperty("password"), + "three backslashes leave a literal backslash and an escaped semicolon"); + Assertions.assertEquals("bar", properties.getDbProperties().getProperty("foo"), + "the pair after the escaped semicolon must still parse"); + + Properties parsed = PoolProperties.getProperties("password=se\\;cret;foo=bar", null); + Assertions.assertEquals("se;cret", parsed.getProperty("password"), + "the static parser must preserve the escaped semicolon too"); + Assertions.assertEquals("bar", parsed.getProperty("foo"), + "the static parser must still split the following pair"); + } + @Test void toStringMasksAnInterceptorPropertyInAnUnclosedPropertyList() { // The parse delivers nothing from a definition whose parenthesis --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
