Skip to content

Commit

Permalink
AttributedStyle.toAnsi(): fixed StringIndexOutOfBoundsException
Browse files Browse the repository at this point in the history
  • Loading branch information
mattirn committed Dec 31, 2020
1 parent 5558924 commit cadefd5
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions terminal/src/main/java/org/jline/utils/AttributedStyle.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002-2018, the original author or authors.
* Copyright (c) 2002-2020, the original author or authors.
*
* This software is distributable under the BSD license. See the terms of the
* BSD license in the documentation provided with this software.
Expand Down Expand Up @@ -263,7 +263,7 @@ public String toAnsi() {
AttributedStringBuilder sb = new AttributedStringBuilder();
sb.styled(this, " ");
String s = sb.toAnsi(AttributedCharSequence.TRUE_COLORS, AttributedCharSequence.ForceMode.None);
return s.substring(2, s.indexOf('m'));
return s.length() > 1 ? s.substring(2, s.indexOf('m')) : s;
}

@Override
Expand Down

0 comments on commit cadefd5

Please sign in to comment.