Browse Source

Fix stripping nickname control codes.

Closes #751
pull/752/head
Chris Smith 7 years ago
parent
commit
5161aa8861

+ 4
- 5
src/main/java/com/dmdirc/ui/messages/StyledMessageUtils.java View File

46
      */
46
      */
47
     public String stripControlCodes(final String input) {
47
     public String stripControlCodes(final String input) {
48
         return input.replaceAll("[" + IRCControlCodes.BOLD + CODE_CHANNEL + IRCControlCodes.FIXED
48
         return input.replaceAll("[" + IRCControlCodes.BOLD + CODE_CHANNEL + IRCControlCodes.FIXED
49
-                + CODE_HYPERLINK + IRCControlCodes.ITALIC + IRCControlCodes.NEGATE + CODE_NICKNAME
49
+                + CODE_HYPERLINK + IRCControlCodes.ITALIC + IRCControlCodes.NEGATE
50
                 + CODE_SMILIE + IRCControlCodes.STOP + IRCControlCodes.UNDERLINE + "]|"
50
                 + CODE_SMILIE + IRCControlCodes.STOP + IRCControlCodes.UNDERLINE + "]|"
51
                 + IRCControlCodes.COLOUR_HEX + "([A-Za-z0-9]{6}(,[A-Za-z0-9]{6})?)?|"
51
                 + IRCControlCodes.COLOUR_HEX + "([A-Za-z0-9]{6}(,[A-Za-z0-9]{6})?)?|"
52
                 + IRCControlCodes.COLOUR + "([0-9]{1,2}(,[0-9]{1,2})?)?", "")
52
                 + IRCControlCodes.COLOUR + "([0-9]{1,2}(,[0-9]{1,2})?)?", "")
53
-                .replaceAll(CODE_TOOLTIP + ".*?" + CODE_TOOLTIP + "(.*?)" + CODE_TOOLTIP, "$1");
53
+                .replaceAll("([" + CODE_TOOLTIP + CODE_NICKNAME + "]).*?\\1(.*?)\\1", "$2");
54
     }
54
     }
55
 
55
 
56
     /**
56
     /**
108
      * @return a copy of the input with control codes removed
108
      * @return a copy of the input with control codes removed
109
      */
109
      */
110
     private String stripInternalControlCodes(final String input) {
110
     private String stripInternalControlCodes(final String input) {
111
-        return input.replaceAll("[" + CODE_CHANNEL + CODE_HYPERLINK + CODE_NICKNAME
111
+        return input.replaceAll("[" + CODE_CHANNEL + CODE_HYPERLINK
112
                 + CODE_SMILIE + IRCControlCodes.STOP + IRCControlCodes.UNDERLINE + ']', "")
112
                 + CODE_SMILIE + IRCControlCodes.STOP + IRCControlCodes.UNDERLINE + ']', "")
113
-                .replaceAll(CODE_TOOLTIP + ".*?" + CODE_TOOLTIP + "(.*?)"
114
-                        + CODE_TOOLTIP, "$1");
113
+                .replaceAll("([" + CODE_TOOLTIP + CODE_NICKNAME + "]).*?\\1(.*?)\\1", "$2");
115
     }
114
     }
116
 
115
 
117
 }
116
 }

+ 8
- 0
src/test/java/com/dmdirc/ui/messages/StyledMessageUtilsTest.java View File

55
         assertEquals(expResult, result);
55
         assertEquals(expResult, result);
56
     }
56
     }
57
 
57
 
58
+    @Test
59
+    public void testStripControlCodesNicknames() {
60
+        final String input = "Link to \020Someone's long name\020\002Someone\002\020...";
61
+        final String expResult = "Link to Someone...";
62
+        final String result = styleUtils.stripControlCodes(input);
63
+        assertEquals(expResult, result);
64
+    }
65
+
58
 }
66
 }

Loading…
Cancel
Save