Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WFCORE-3231] Logging subsystem: Fix SuffixValidator to allow 's' or 'S' symbols in text quoted using single quotes in suffix. #2840

Merged
merged 1 commit into from Oct 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both this and L61 can throw an IndexOutOfBoundsException.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added unit tests. I first validate the suffix on L56 and then check for 's' in order to prevent checking invalid formats like "m'suffix" (one single quote) which in this case will throw StringIndexOutOfBoundsException.

}
}
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'"));
}
}