Skip to content

Commit

Permalink
Allow the supplementary details field to start with a colon
Browse files Browse the repository at this point in the history
  • Loading branch information
Niel de Wet committed Jan 7, 2022
1 parent 755ee28 commit 9506c99
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public GeneralField readField() throws FieldParseException {
contentBuilder.toString()
);
} catch (FieldParseException e) {
throw e;
throw e;
} catch (Exception e) {
throw new FieldParseException(e.getMessage(), getFieldLineNumber(), e);
}
Expand All @@ -111,7 +111,10 @@ private FieldLineType determineMessageLineType(String messageLine) {
return FieldLineType.SEPARATOR;
}
if (messageLine.startsWith(":")) {
return FieldLineType.FIELD;
Matcher tagMatcher = FIELD_STRUCTURE_PATTERN.matcher(messageLine);
if (tagMatcher.matches() && tagMatcher.group("tag") != null) {
return FieldLineType.FIELD;
}
}
return FieldLineType.FIELD_CONTINUATION;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public void parse_WHEN_parse_valid_file_RETURN_message() throws Exception {
":28C:00102\n" +
":60F:C000103USD672,\n" +
":61:0312091211D880,FTRFBPHP/081203/0003//59512112915002\n" +
"supplementary info\n" +
":86:multiline info\n" +
"-info\n" +
":61:0312091211D880,FTRFBPHP/081203/0003//59512112915002\n" +
Expand All @@ -58,6 +59,29 @@ public void parse_WHEN_parse_valid_file_RETURN_message() throws Exception {
softly.assertThat(MT940Page.getTransactionGroupList()).hasSize(3);
}

@Test
public void parse_WHEN_supplementary_details_start_with_colon_THEN_it_is_correctly_parsed() throws Exception {

// Given
String mt940MessageText = ":20:02618\n" +
":21:123456/DEV\n" +
":25:6-9412771\n" +
":28C:00102\n" +
":60F:C000103USD672,\n" +
":61:0312091211D880,FTRFBPHP/081203/0003//59512112915002\n" +
":colon is valid x char set\n" +
":62F:C000103USD987,\n" +
"-";

MT940PageReader classUnderTest = new MT940PageReader(new StringReader(mt940MessageText));

// When
List<MT940Page> pageList = TestUtils.collectUntilNull(classUnderTest::read);

// Then
assertThat(pageList).hasSize(1);
}

@Test
public void getContent_SHOULD_return_input_text() throws Exception {

Expand Down

0 comments on commit 9506c99

Please sign in to comment.