Skip to content

Commit

Permalink
Issue #1899 - Update after review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Troy Biesterfeld <tbieste@us.ibm.com>
  • Loading branch information
tbieste committed May 11, 2021
1 parent f9084f8 commit ccdf7e8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1534,12 +1534,14 @@ protected void parseArgs(String[] args) {
public void loadPropertyFile(String filename) {
try (InputStream is = new FileInputStream(filename)) {
properties.load(is);
// Trim leading and trailing whitespace from property values
// Trim leading and trailing whitespace from property values (except password)
for (Entry<Object, Object> entry : properties.entrySet()) {
String trimmedValue = entry.getValue().toString().trim();
if (!trimmedValue.equals(entry.getValue().toString())) {
logger.warning("Whitespace trimmed from value of property '" + entry.getKey() + "'");
entry.setValue(trimmedValue);
if (!"password".equals(entry.getKey())) {
String trimmedValue = entry.getValue().toString().trim();
if (!trimmedValue.equals(entry.getValue().toString())) {
logger.warning("Whitespace trimmed from value of property '" + entry.getKey() + "'");
entry.setValue(trimmedValue);
}
}
}
} catch (IOException x) {
Expand All @@ -1555,12 +1557,16 @@ public void loadPropertyFile(String filename) {
public void addProperty(String pair) {
String[] kv = pair.split("=");
if (kv.length == 2) {
// Trim leading and trailing whitespace from property value
String trimmedValue = kv[1].trim();
if (!trimmedValue.equals(kv[1])) {
logger.warning("Whitespace trimmed from value of property '" + kv[0] + "'");
// Trim leading and trailing whitespace from property value (except password)
if (!"password".equals(kv[0])) {
String trimmedValue = kv[1].trim();
if (!trimmedValue.equals(kv[1])) {
logger.warning("Whitespace trimmed from value of property '" + kv[0] + "'");
}
properties.put(kv[0], trimmedValue);
} else {
properties.put(kv[0], kv[1]);
}
properties.put(kv[0], trimmedValue);
} else {
throw new IllegalArgumentException("Property must be defined as key=value, not: " + pair);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
import java.util.logging.Level;
Expand Down Expand Up @@ -237,6 +238,16 @@ protected void parseArgs(String[] args) {
public void loadPropertyFile(String filename) {
try (InputStream is = new FileInputStream(filename)) {
properties.load(is);
// Trim leading and trailing whitespace from property values (except password)
for (Entry<Object, Object> entry : properties.entrySet()) {
if (!"password".equals(entry.getKey())) {
String trimmedValue = entry.getValue().toString().trim();
if (!trimmedValue.equals(entry.getValue().toString())) {
logger.warning("Whitespace trimmed from value of property '" + entry.getKey() + "'");
entry.setValue(trimmedValue);
}
}
}
} catch (IOException x) {
throw new IllegalArgumentException(x);
}
Expand All @@ -250,7 +261,16 @@ public void loadPropertyFile(String filename) {
public void addProperty(String pair) {
String[] kv = pair.split("=");
if (kv.length == 2) {
properties.put(kv[0], kv[1]);
// Trim leading and trailing whitespace from property value (except password)
if (!"password".equals(kv[0])) {
String trimmedValue = kv[1].trim();
if (!trimmedValue.equals(kv[1])) {
logger.warning("Whitespace trimmed from value of property '" + kv[0] + "'");
}
properties.put(kv[0], trimmedValue);
} else {
properties.put(kv[0], kv[1]);
}
} else {
throw new IllegalArgumentException("Property must be defined as key=value, not: " + pair);
}
Expand Down

0 comments on commit ccdf7e8

Please sign in to comment.