This is an automated email from the ASF dual-hosted git repository. lihan pushed a commit to branch 9.0.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/9.0.x by this push: new 8908c58089 Ensure brackets are closed in PoolProperties.toString 8908c58089 is described below commit 8908c5808987a071a0afb6da8ebff506bb1424e0 Author: Magnus Reftel <magnus.ref...@skatteetaten.no> AuthorDate: Mon Apr 24 12:41:51 2023 +0200 Ensure brackets are closed in PoolProperties.toString --- .../apache/tomcat/jdbc/pool/PoolProperties.java | 1 + .../tomcat/jdbc/pool/PoolPropertiesTest.java | 39 ++++++++++++++++++++++ 2 files changed, 40 insertions(+) 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 e9c9c09b69..3aff37fa53 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 @@ -848,6 +848,7 @@ public class PoolProperties implements PoolConfiguration, Cloneable, Serializabl break; } } + buf.append(']'); }catch (Exception x) { //shouldn't happen log.debug("toString() call failed", x); diff --git a/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/pool/PoolPropertiesTest.java b/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/pool/PoolPropertiesTest.java new file mode 100644 index 0000000000..b475d64f23 --- /dev/null +++ b/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/pool/PoolPropertiesTest.java @@ -0,0 +1,39 @@ +package org.apache.tomcat.jdbc.pool; + + +import org.junit.Assert; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.List; + +public class PoolPropertiesTest { + private static final String DEFAULT_USER = "username_def"; + private static final String DEFAULT_PASSWD = "password_def"; + @Test + public void toStringOutputShouldHaveBalancedBrackets() { + PoolProperties properties = new PoolProperties(); + properties.setUsername(DEFAULT_USER); + properties.setPassword(DEFAULT_PASSWD); + properties.setAlternateUsernameAllowed(true); + properties.setInitialSize(0); + properties.setRemoveAbandoned(false); + properties.setTimeBetweenEvictionRunsMillis(-1); + + String asString = properties.toString(); + + List<Character> stack = new ArrayList<>(); + for (char c : asString.toCharArray()) { + switch (c) { + case '{': + case '(': + case '[': stack.add(c); break; + case '}': Assert.assertEquals('{', stack.remove(stack.size() - 1).charValue()); break; + case ')': Assert.assertEquals('(', stack.remove(stack.size() - 1).charValue()); break; + case ']': Assert.assertEquals('[', stack.remove(stack.size() - 1).charValue()); break; + default: break; + } + } + Assert.assertEquals("All brackets should have been closed", 0, stack.size()); + } +} --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org