From e2924b42826fbb00bffd04a7ab1ef5e1832cdbb9 Mon Sep 17 00:00:00 2001 From: Jens Wille Date: Wed, 28 Oct 2020 11:59:44 +0100 Subject: [PATCH] Ignore null values in Regexp function. --- .../metamorph/functions/Regexp.java | 3 +++ .../metamorph/functions/RegexpTest.java | 23 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/metamorph/src/main/java/org/metafacture/metamorph/functions/Regexp.java b/metamorph/src/main/java/org/metafacture/metamorph/functions/Regexp.java index 5c84409cd..a2c192093 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/functions/Regexp.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/functions/Regexp.java @@ -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()) { diff --git a/metamorph/src/test/java/org/metafacture/metamorph/functions/RegexpTest.java b/metamorph/src/test/java/org/metafacture/metamorph/functions/RegexpTest.java index 136b002c6..f1643ff83 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/functions/RegexpTest.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/functions/RegexpTest.java @@ -95,4 +95,27 @@ public void shouldIgnoreEmptyMatchGroups() { ordered.verify(receiver).endRecord(); ordered.verifyNoMoreInteractions(); } + + @Test + public void shouldIgnoreNullValues() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with("") + .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(); + } + }