This is an automated email from the ASF dual-hosted git repository.

bipinprasad pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/storm.git


The following commit(s) were added to refs/heads/master by this push:
     new c075001  STORM-3822 fix visualization when streamId contains colon 
(#3441)
c075001 is described below

commit c0750018d08dae822537e80ab3c894da8ba29532
Author: Ben Roling <[email protected]>
AuthorDate: Sun Apr 3 02:18:13 2022 -0500

    STORM-3822 fix visualization when streamId contains colon (#3441)
    
    * STORM-3822 fix visualization when streamId contains colon
    
    * Simplify implementation
    
    * Restore parity in null, empty handling
    
    Co-authored-by: Ben Roling <[email protected]>
---
 .../java/org/apache/storm/daemon/ui/UIHelpers.java    | 19 +++++++++----------
 .../org/apache/storm/daemon/ui/UIHelpersTest.java     | 16 ++++++++++++++++
 2 files changed, 25 insertions(+), 10 deletions(-)

diff --git 
a/storm-webapp/src/main/java/org/apache/storm/daemon/ui/UIHelpers.java 
b/storm-webapp/src/main/java/org/apache/storm/daemon/ui/UIHelpers.java
index eece882..28652dd 100644
--- a/storm-webapp/src/main/java/org/apache/storm/daemon/ui/UIHelpers.java
+++ b/storm-webapp/src/main/java/org/apache/storm/daemon/ui/UIHelpers.java
@@ -1746,19 +1746,18 @@ public class UIHelpers {
     }
 
     /**
-     * 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 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);
+        Matcher problemCharacterMatcher = 
Pattern.compile("(?![A-Za-z_\\-\\.]).").matcher(streamName);
+        if (streamName.length() > 0 && 
Character.isLetter(streamName.charAt(0))) {
+            return problemCharacterMatcher.replaceAll("_");
+        } else {
+            return "_s" + problemCharacterMatcher.replaceAll("_");
         }
-        return matcher2.replaceAll("_");
     }
 
     /**
diff --git 
a/storm-webapp/src/test/java/org/apache/storm/daemon/ui/UIHelpersTest.java 
b/storm-webapp/src/test/java/org/apache/storm/daemon/ui/UIHelpersTest.java
index 534b538..fdd531c 100644
--- a/storm-webapp/src/test/java/org/apache/storm/daemon/ui/UIHelpersTest.java
+++ b/storm-webapp/src/test/java/org/apache/storm/daemon/ui/UIHelpersTest.java
@@ -486,6 +486,22 @@ class UIHelpersTest {
     }
 
     /**
+     * Tests that santizeStreamName() does the expected manipulations
+     */
+    @Test
+    public void testSanitizeStreamName() {
+        // replaces the expected characters with underscores (everything 
except A-Z, a-z, dot, dash, and underscore)
+        assertEquals("my-stream_with.all_characterClasses____",
+                
UIHelpers.sanitizeStreamName("my-stream:with.all_characterClasses1/\\2"));
+
+        // has the expected effect when streamName begins with a non-alpha 
character
+        assertEquals("_s_foo", UIHelpers.sanitizeStreamName("3foo"));
+
+        // handles empty string, though that's not an expected stream name
+        assertEquals("_s", UIHelpers.sanitizeStreamName(""));
+    }
+
+    /**
      * Add an AggregateStats entry to the TopologyPageInfo instance.
      * @param boltId Id of the bolt to add the entry for.
      * @param aggregateStats Defines the entry.

Reply via email to