From ae0390ef4ab63fcfc103536ecfeec22a211e1403 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nadja=20M=C3=BCller?= Date: Tue, 3 Oct 2023 17:51:55 +0200 Subject: [PATCH] [pLz5YbCW] add empty string check --- core/src/main/java/apoc/merge/Merge.java | 10 ++-------- core/src/test/java/apoc/merge/MergeTest.java | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/core/src/main/java/apoc/merge/Merge.java b/core/src/main/java/apoc/merge/Merge.java index 8477dd56c..255869af3 100644 --- a/core/src/main/java/apoc/merge/Merge.java +++ b/core/src/main/java/apoc/merge/Merge.java @@ -86,14 +86,8 @@ private Result getNodeResult(List labelNames, Map identP throw new IllegalArgumentException("you need to supply at least one identifying property for a merge"); } - if (labelNames != null && - (labelNames.contains(null) || (labelNames.size() == 1 && labelNames.get(0).isEmpty()))) { - throw new IllegalArgumentException("The list of label names contained a null value. If you wish to merge a node without a label, pass an empty list instead."); - } - - // labelNames = [""] - if (labelNames != null && labelNames.size() == 1 && labelNames.get(0).isEmpty()) { - throw new IllegalArgumentException("The list of label cannot be empty. If you wish to merge a node without a label, pass an empty list instead."); + if (labelNames != null && (labelNames.contains(null) || labelNames.contains(""))) { + throw new IllegalArgumentException("The list of label names may not contain any null or empty String values. If you wish to merge a node without a label, pass an empty list instead."); } String labels = labelNames != null ? ":" + labelNames.stream().map(Util::quote).collect(Collectors.joining(":")) : ""; diff --git a/core/src/test/java/apoc/merge/MergeTest.java b/core/src/test/java/apoc/merge/MergeTest.java index 681eb9e51..18802a6b5 100644 --- a/core/src/test/java/apoc/merge/MergeTest.java +++ b/core/src/test/java/apoc/merge/MergeTest.java @@ -132,7 +132,7 @@ public void testMergeNodeWithNullLabelsShouldFail() { row -> assertTrue(row.get("node") instanceof Node)); fail(); } catch (QueryExecutionException e) { - assertTrue(e.getMessage().contains("The list of label names contained a null value. If you wish to merge a node without a label, pass an empty list instead.")); + assertTrue(e.getMessage().contains("The list of label names may not contain any null or empty String values. If you wish to merge a node without a label, pass an empty list instead.")); } } @@ -143,7 +143,18 @@ public void testMergeNodeWithEmptyLabelListShouldFail() { row -> assertTrue(row.get("node") instanceof Node)); fail(); } catch (QueryExecutionException e) { - assertTrue(e.getMessage().contains("The list of label cannot be empty. If you wish to merge a node without a label, pass an empty list instead.")); + assertTrue(e.getMessage().contains("The list of label names may not contain any null or empty String values. If you wish to merge a node without a label, pass an empty list instead.")); + } + } + + @Test + public void testMergeNodeContainingEmptyLabelShouldFail() { + try { + testCall(db, "CALL apoc.merge.node([''], {name:'John'}) YIELD node RETURN node", + row -> assertTrue(row.get("node") instanceof Node)); + fail(); + } catch (QueryExecutionException e) { + assertTrue(e.getMessage().contains("The list of label names may not contain any null or empty String values. If you wish to merge a node without a label, pass an empty list instead.")); } }