Skip to content

Commit

Permalink
Fix bug with string index out of bounds (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
carl-textalk authored Feb 25, 2020
1 parent b0b3588 commit 36dac39
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/org/daisy/dotify/common/text/BreakPointHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ private BreakPoint newBreakpointFromPosition(int strPos, int breakPoint, boolean
} else if (state.charsStr.charAt(i)==ZERO_WIDTH_SPACE) { // ignore zero width space
head = state.charsStr.substring(0, i);
tailStart = i+1;
} else if (state.charsStr.charAt(i)==DASH && state.charsStr.length()>1 && state.charsStr.charAt(i-1)==SPACE) {
} else if (state.charsStr.charAt(i)==DASH && state.charsStr.length()>1 && i!=0 && state.charsStr.charAt(i-1)==SPACE) {
// if hyphen is preceded by space, back up one more
head = state.charsStr.substring(0, i);
tailStart = i;
Expand Down
7 changes: 7 additions & 0 deletions test/org/daisy/dotify/common/text/BreakPointHandlerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -330,4 +330,11 @@ public void testMarkReset() {
assertEquals("", bp.getTail());
}

@Test
public void testNextRowDoesNotCrashWhenBreakpointIsTheFirstCharacterAndRowStartsWithHyphen(){
BreakPointHandler bph = new BreakPointHandler( "-abcdef");
BreakPoint bp = bph.nextRow(3, false);
assertEquals("-", bp.getHead());
assertEquals("abcdef", bp.getTail());
}
}

0 comments on commit 36dac39

Please sign in to comment.