Skip to content

Commit

Permalink
fixes #1262: apoc.cypher.runFile fails when there is a empty transact…
Browse files Browse the repository at this point in the history
…ion (#1349)
  • Loading branch information
conker84 authored and mneedham committed Nov 18, 2019
1 parent 48cab79 commit 0f7cbd6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/main/java/apoc/cypher/Cypher.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@ private Object executeStatement(BlockingQueue<RowResult> queue, String stmt, Map
private String removeShellControlCommands(String stmt) {
Matcher matcher = shellControl.matcher(stmt.trim());
if (matcher.find()) {
stmt = matcher.replaceAll("");
// an empty file get transformed into ":begin\n:commit" and that statement is not matched by the pattern
// because ":begin\n:commit".replaceAll("") => "\n:commit" with the recursion we avoid the problem
return removeShellControlCommands(matcher.replaceAll(""));
}
return stmt;
}
Expand Down
6 changes: 6 additions & 0 deletions src/test/java/apoc/cypher/CypherTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -457,4 +457,10 @@ public void testCaseDoElseCondition() throws Exception {
assertEquals("C", ((Map) r.get("value")).get("cName"));
});
}

@Test
public void testRunFileWithEmptyFile() throws Exception {
testResult(db, "CALL apoc.cypher.runFile('src/test/resources/empty.cypher')",
r -> assertFalse("should be empty", r.hasNext()));
}
}
2 changes: 2 additions & 0 deletions src/test/resources/empty.cypher
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
:begin
:commit

0 comments on commit 0f7cbd6

Please # to comment.