Skip to content

Commit

Permalink
[pLz5YbCW] add empty string check
Browse files Browse the repository at this point in the history
  • Loading branch information
nadja-muller committed Oct 3, 2023
1 parent 8b470ff commit ae0390e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
10 changes: 2 additions & 8 deletions core/src/main/java/apoc/merge/Merge.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,8 @@ private Result getNodeResult(List<String> labelNames, Map<String, Object> 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(":")) : "";
Expand Down
15 changes: 13 additions & 2 deletions core/src/test/java/apoc/merge/MergeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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."));
}
}

Expand All @@ -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."));
}
}

Expand Down

0 comments on commit ae0390e

Please sign in to comment.