ben-roling commented on a change in pull request #3441:
URL: https://github.com/apache/storm/pull/3441#discussion_r839009169
##########
File path: storm-webapp/src/main/java/org/apache/storm/daemon/ui/UIHelpers.java
##########
@@ -1746,19 +1746,21 @@ private static Double nullToZero(Double value) {
}
/**
- * sanitizeStreamName.
- * @param streamName streamName
- * @return sanitizeStreamName
+ * Sanitizes streamName for use as an identifier in the visualization.
Replaces all characters except A-Z, a-z,
+ * '.', '-', and '_' with '_'. If streamName does not start with A-Z or
a-z, adds '_s' prefix.
+ * @param streamName non-null, non-empty streamName
+ * @return sanitized stream name
*/
public static String sanitizeStreamName(String streamName) {
- Pattern pattern = Pattern.compile("(?![A-Za-z_\\-:\\.]).");
- Pattern pattern2 = Pattern.compile("^[A-Za-z]");
- Matcher matcher = pattern2.matcher(streamName);
- Matcher matcher2 = pattern.matcher("\\s" + streamName);
- if (matcher.find()) {
- matcher2 = pattern.matcher(streamName);
- }
- return matcher2.replaceAll("_");
+ if (streamName == null || streamName.isEmpty()) {
Review comment:
It doesn't seem the streamName would ever be null or empty but I added
this precondition checking to fail faster if it ever was. Without it the
exception could occur at `Character.isLetter(streamName.charAt(0)`. I can
delete this and let that happen instead if there is a preference.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]