Skip to content

Commit

Permalink
[WFCORE-3231] Logging subsystem: Fix SuffixValidator to allow 's' or 'S'
Browse files Browse the repository at this point in the history
symbols in text quoted using single quotes in suffix.
  • Loading branch information
ivassile committed Oct 20, 2017
1 parent af1c496 commit 037e8f2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
Expand Up @@ -53,10 +53,21 @@ public void validateParameter(String parameterName, ModelNode value) throws Oper
if (value.isDefined()) {
final String suffix = value.asString();
try {
if (denySeconds && (suffix.contains("s") || suffix.contains("S"))) {
throw createOperationFailure(LoggingLogger.ROOT_LOGGER.suffixContainsMillis(suffix));
}
new SimpleDateFormat(suffix);
if (denySeconds) {
for (int i = 0; i < suffix.length(); i++) {
char c = suffix.charAt(i);
if (c == '\'') {
c = suffix.charAt(++i);
while (c != '\'') {
c = suffix.charAt(++i);
}
}
if (c == 's' || c == 'S') {
throw createOperationFailure(LoggingLogger.ROOT_LOGGER.suffixContainsMillis(suffix));
}
}
}
} catch (IllegalArgumentException e) {
throw createOperationFailure(LoggingLogger.ROOT_LOGGER.invalidSuffix(suffix));
}
Expand Down
Expand Up @@ -42,11 +42,13 @@ public void testValidator() throws Exception {
// no-op
}
try {
validator.validateParameter("suffix", new ModelNode("this is a bad pattern"));
//invalid pattern with one single quote
validator.validateParameter("suffix", new ModelNode(".yyyy-MM-dd'custom suffix"));
Assert.assertTrue("The model should be invalid", false);
} catch (OperationFailedException e) {
// no-op
}
validator.validateParameter("suffix", new ModelNode(".yyyy-MM-dd"));
//valid pattern with custom suffix
validator.validateParameter("suffix", new ModelNode(".yyyy-MM-dd'custom suffix'"));
}
}

0 comments on commit 037e8f2

Please sign in to comment.