Bladeren bron

Add defensive checks to Styliser.

Issue DMDirc/Plugins#47
pull/63/head
Chris Smith 9 jaren geleden
bovenliggende
commit
168c1c5e71
1 gewijzigde bestanden met toevoegingen van 8 en 0 verwijderingen
  1. 8
    0
      src/com/dmdirc/ui/messages/Styliser.java

+ 8
- 0
src/com/dmdirc/ui/messages/Styliser.java Bestand weergeven

41
 import javax.swing.text.StyleConstants;
41
 import javax.swing.text.StyleConstants;
42
 import javax.swing.text.StyledDocument;
42
 import javax.swing.text.StyledDocument;
43
 
43
 
44
+import static com.google.common.base.Preconditions.checkArgument;
45
+
44
 /**
46
 /**
45
  * The styliser applies IRC styles to text. Styles are indicated by various control codes which are
47
  * The styliser applies IRC styles to text. Styles are indicated by various control codes which are
46
  * a de-facto IRC standard.
48
  * a de-facto IRC standard.
255
      * @since 0.6.3
257
      * @since 0.6.3
256
      */
258
      */
257
     public static String getStyledText(final String styled, final int from, final int to) {
259
     public static String getStyledText(final String styled, final int from, final int to) {
260
+        checkArgument(from < to, "'from' must be less than 'to'");
261
+        checkArgument(from >= 0, "'from' must be non-negative");
262
+
258
         final String unstyled = stipControlCodes(styled);
263
         final String unstyled = stipControlCodes(styled);
264
+
265
+        checkArgument(to < unstyled.length(), "'to' must be less than the unstyled length");
266
+
259
         final String startBit = unstyled.substring(0, from);
267
         final String startBit = unstyled.substring(0, from);
260
         final String middleBit = unstyled.substring(from, to);
268
         final String middleBit = unstyled.substring(from, to);
261
         final String sanitised = stipInternalControlCodes(styled);
269
         final String sanitised = stipInternalControlCodes(styled);

Laden…
Annuleren
Opslaan