Browse Source

Fix getStyledText() scrubbing underline and stop chars.

Closes #757
pull/758/head
Chris Smith 7 years ago
parent
commit
08f54bad9f

+ 1
- 2
src/main/java/com/dmdirc/ui/messages/StyledMessageUtils.java View File

@@ -108,8 +108,7 @@ public class StyledMessageUtils {
108 108
      * @return a copy of the input with control codes removed
109 109
      */
110 110
     private String stripInternalControlCodes(final String input) {
111
-        return input.replaceAll("[" + CODE_CHANNEL + CODE_HYPERLINK
112
-                + CODE_SMILIE + IRCControlCodes.STOP + IRCControlCodes.UNDERLINE + ']', "")
111
+        return input.replaceAll("[" + CODE_CHANNEL + CODE_HYPERLINK + CODE_SMILIE + ']', "")
113 112
                 .replaceAll("([" + CODE_TOOLTIP + CODE_NICKNAME + "]).*?\\1(.*?)\\1", "$2");
114 113
     }
115 114
 

+ 17
- 18
src/test/java/com/dmdirc/ui/messages/StyliserIndicesTest.java View File

@@ -24,17 +24,17 @@ package com.dmdirc.ui.messages;
24 24
 
25 25
 import java.util.Arrays;
26 26
 import java.util.List;
27
-
28 27
 import org.junit.Test;
29 28
 import org.junit.runner.RunWith;
30 29
 import org.junit.runners.Parameterized;
31 30
 
32
-import static org.junit.Assert.*;
31
+import static org.junit.Assert.assertEquals;
33 32
 
34 33
 @RunWith(Parameterized.class)
35 34
 public class StyliserIndicesTest {
36 35
 
37 36
     private String input, output;
37
+
38 38
     private int start, end;
39 39
 
40 40
     public StyliserIndicesTest(final String input, final int start, final int end, final String output) {
@@ -52,22 +52,21 @@ public class StyliserIndicesTest {
52 52
     @Parameterized.Parameters
53 53
     public static List<Object[]> data() {
54 54
         final Object[][] tests = {
55
-            // No style
56
-            {"Blah blah blah", 0, 1, "B"},
57
-            {"Blah blah blah", 0, 4, "Blah"},
58
-            {IRCControlCodes.BOLD + "Blah blah blah", 0, 4, IRCControlCodes.BOLD + "Blah"},
59
-            {IRCControlCodes.BOLD + "Bl" + IRCControlCodes.BOLD + "ah blah blah",
60
-                     0, 4, IRCControlCodes.BOLD + "Bl" + IRCControlCodes.BOLD + "ah"},
61
-            {"Blah" + IRCControlCodes.BOLD + " blah blah",
62
-                     0, 4, "Blah"},
63
-            {"Blah" + IRCControlCodes.COLOUR + "4,0RED blah blah",
64
-                     4, 7, IRCControlCodes.COLOUR + "4,0RED"},
65
-            {"Blah" + IRCControlCodes.COLOUR + "4,0RED blah blah",
66
-                     5, 7, "ED"},
67
-            {Styliser.CODE_TOOLTIP + "Annoying internal tooltip text"
68
-                     + Styliser.CODE_TOOLTIP + "Blah" + Styliser.CODE_TOOLTIP + "Blah",
69
-                     2, 6, "ahBl"},
70
-        };
55
+                // No style
56
+                {"Blah blah blah", 0, 1, "B"}, {"Blah blah blah", 0, 4, "Blah"},
57
+                {IRCControlCodes.BOLD + "Blah blah blah", 0, 4, IRCControlCodes.BOLD + "Blah"},
58
+                {IRCControlCodes.BOLD + "Bl" + IRCControlCodes.BOLD + "ah blah blah", 0, 4,
59
+                        IRCControlCodes.BOLD + "Bl" + IRCControlCodes.BOLD + "ah"},
60
+                {"Blah" + IRCControlCodes.BOLD + " blah blah", 0, 4, "Blah"},
61
+                {"Blah" + IRCControlCodes.UNDERLINE + " blah blah", 0, 6, "Blah" + IRCControlCodes.UNDERLINE + " b"},
62
+                {"Blah" + IRCControlCodes.STOP + " blah blah", 0, 6, "Blah" + IRCControlCodes.STOP + " b"},
63
+                {"Blah" + IRCControlCodes.COLOUR + "4,0RED blah blah", 4, 7, IRCControlCodes.COLOUR + "4,0RED"},
64
+                {"Blah" + IRCControlCodes.COLOUR + "4,0RED blah blah", 5, 7, "ED"},
65
+                {Styliser.CODE_TOOLTIP + "Annoying internal tooltip text" + Styliser.CODE_TOOLTIP + "Blah"
66
+                        + Styliser.CODE_TOOLTIP + "Blah", 2, 6, "ahBl"},
67
+                {Styliser.CODE_NICKNAME + "Annoying internal tooltip text" + Styliser.CODE_NICKNAME
68
+                        + IRCControlCodes.BOLD + "Blah" + IRCControlCodes.BOLD + Styliser.CODE_NICKNAME + "Blah", 2, 6,
69
+                        "ah" + IRCControlCodes.BOLD + "Bl"},};
71 70
 
72 71
         return Arrays.asList(tests);
73 72
     }

Loading…
Cancel
Save