Skip to content

Commit

Permalink
Merge pull request #84 from nieldw/fix/very_large_text_block
Browse files Browse the repository at this point in the history
Fix StackOverflowError in extra-long Text Block by using the possessive quantifier to avoid backtracking
  • Loading branch information
qoomon committed Dec 9, 2020
2 parents 0f0b24f + a1ff9fa commit 62ca00c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class TextBlock implements SwiftBlock {

public static final String BLOCK_ID_4 = "4";

public static final Pattern FIELD_PATTERN = Pattern.compile("([^\\n]+)?\\n((?>:?.*\\n)*-)");
public static final Pattern FIELD_PATTERN = Pattern.compile("([^\\n]+)?\\n((?>:?.*\\n)*+-)");

private final Optional<String> infoLine;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@
*/
public class TextBlockTest {

@Test
public void of_WHEN_valid_block_with_info_line_is_passed_RETURN_new_block() throws Exception {

// Given
GeneralBlock generalBlock = new GeneralBlock(TextBlock.BLOCK_ID_4, "info\nabc\n-");

// When
TextBlock block = TextBlock.of(generalBlock);

// Then
assertThat(block).isNotNull();
assertThat(block.getInfoLine()).hasValue("info");
assertThat(block.getText()).isEqualTo("abc\n-");
}

@Test
public void of_WHEN_valid_block_is_passed_RETURN_new_block() throws Exception {

Expand Down

0 comments on commit 62ca00c

Please sign in to comment.