Skip to content

Commit

Permalink
Merge pull request #337 from metafacture/regexp-ignore-null
Browse files Browse the repository at this point in the history
Ignore null values in Regexp function.
  • Loading branch information
blackwinter committed Oct 28, 2020
2 parents b8f5ad5 + e2924b4 commit 84c0ac1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public final class Regexp extends AbstractFunction {
public void receive(final String name, final String value,
final NamedValueSource source, final int recordCount,
final int entityCount) {
if (null == value) {
return;
}
matcher.reset(value);
if (null == format) {
while (matcher.find()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,27 @@ public void shouldIgnoreEmptyMatchGroups() {
ordered.verify(receiver).endRecord();
ordered.verifyNoMoreInteractions();
}

@Test
public void shouldIgnoreNullValues() {
metamorph = InlineMorph.in(this)
.with("<rules>")
.with(" <data source='s'>")
.with(" <regexp match='a.*' />")
.with(" </data>")
.with("</rules>")
.createConnectedTo(receiver);

metamorph.startRecord("1");
metamorph.literal("s", "aaccdd");
metamorph.literal("s", null);
metamorph.endRecord();

final InOrder ordered = inOrder(receiver);
ordered.verify(receiver).startRecord("1");
ordered.verify(receiver).literal("s", "aaccdd");
ordered.verify(receiver).endRecord();
ordered.verifyNoMoreInteractions();
}

}

0 comments on commit 84c0ac1

Please sign in to comment.