You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@storm.apache.org by GitBox <gi...@apache.org> on 2022/03/30 22:10:33 UTC

[GitHub] [storm] ben-roling commented on a change in pull request #3441: STORM-3822 fix visualization when streamId contains colon

ben-roling commented on a change in pull request #3441:
URL: https://github.com/apache/storm/pull/3441#discussion_r839007483



##########
File path: storm-webapp/src/main/java/org/apache/storm/daemon/ui/UIHelpers.java
##########
@@ -1746,19 +1746,26 @@ private static Double nullToZero(Double value) {
     }
 
     /**
-     * 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 streamName
-     * @return sanitizeStreamName
+     * @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);
+        Pattern startsWithLetterPattern = Pattern.compile("^[A-Za-z]");
+        Pattern problemCharacterPattern = Pattern.compile("(?![A-Za-z_\\-\\.]).");
+
+        Matcher startsWithLetterMatcher = startsWithLetterPattern.matcher(streamName);
+        Matcher problemCharacterMatcher;
+        if (startsWithLetterMatcher.find()) {
+            problemCharacterMatcher = problemCharacterPattern.matcher(streamName);
+        } else {
+            // if the streamName starts with non-letter character, prepend "\s".  The backslash will then
+            // get replaced by an underscore, resulting in the prefix of "_s" in the final sanitized name
+            problemCharacterMatcher = problemCharacterPattern.matcher("\\s" + streamName);

Review comment:
       I've added the simplification as you suggest.  Perhaps I should have done that straight away.
   
   https://github.com/apache/storm/pull/3441/commits/b7f04e7e6d9d0b05d449795279fd8c250cd92abf




-- 
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: dev-unsubscribe@storm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org