From 8894597e7e69c2c87460ba84d0c57792f72cc78e Mon Sep 17 00:00:00 2001 From: jeb228 Date: Fri, 28 Jan 2011 16:08:56 +0000 Subject: [PATCH] NIHVIVO-1942 when loading the deploy.properties file, strip any trailing whitespace from the properties. --- .../mannlib/vitro/webapp/ConfigurationProperties.java | 8 +++++++- .../mannlib/vitro/webapp/ConfigurationPropertiesTest.java | 2 +- .../mannlib/vitro/webapp/test_config_default.properties | 3 +++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/ConfigurationProperties.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/ConfigurationProperties.java index 18628f4c6..68f127165 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/ConfigurationProperties.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/ConfigurationProperties.java @@ -35,6 +35,9 @@ import org.apache.commons.logging.LogFactory; * to a value like /usr/local/vitro/stuff/deploy.properties for a * file, or like deploy.properties for a resource in the classpath. * + * When the properties file is loaded, the values are trimmed to remove leading + * or trailing white space, since such white space is almost always an error. + * * @author jeb228 */ public class ConfigurationProperties { @@ -144,7 +147,10 @@ public class ConfigurationProperties { Map newMap = new HashMap(); for (Enumeration keys = props.keys(); keys.hasMoreElements();) { String key = (String) keys.nextElement(); - newMap.put(key, props.getProperty(key)); + String value = props.getProperty(key); + // While we're copying, remove leading and trailing white space. + String trimmed = value.trim(); + newMap.put(key, trimmed); } log.info("Configuration properties are: " + newMap); diff --git a/webapp/test/edu/cornell/mannlib/vitro/webapp/ConfigurationPropertiesTest.java b/webapp/test/edu/cornell/mannlib/vitro/webapp/ConfigurationPropertiesTest.java index b049fbc4d..0e0f93be8 100644 --- a/webapp/test/edu/cornell/mannlib/vitro/webapp/ConfigurationPropertiesTest.java +++ b/webapp/test/edu/cornell/mannlib/vitro/webapp/ConfigurationPropertiesTest.java @@ -47,7 +47,7 @@ public class ConfigurationPropertiesTest extends AbstractTestClass { * The mappings that we might find from the property files. */ private static final String[][] MAP_VALUES_DEFAULT = new String[][] { { - "whichfile", "test_config_default" } }; + "whichfile", "test_config_default" }, {"trimmed", "whitespace_test"} }; private static final String[][] MAP_VALUES_CONFIGURED = new String[][] { { "whichfile", "test_config" } }; diff --git a/webapp/test/edu/cornell/mannlib/vitro/webapp/test_config_default.properties b/webapp/test/edu/cornell/mannlib/vitro/webapp/test_config_default.properties index 17b581024..c89a1868a 100644 --- a/webapp/test/edu/cornell/mannlib/vitro/webapp/test_config_default.properties +++ b/webapp/test/edu/cornell/mannlib/vitro/webapp/test_config_default.properties @@ -2,3 +2,6 @@ # This is a data file for ConfigurationPropertiesTest. # whichfile = test_config_default + +# This ends with a blank, in order to test the removal of whitespace +trimmed = whitespace_test\u0020