Skip to content
This repository was archived by the owner on Jul 6, 2023. It is now read-only.

Commit 4da8146

Browse files
committed
Ignore empty statements.
1 parent 53304b5 commit 4da8146

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

cypher-shell/src/main/java/org/neo4j/shell/CypherShell.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public class CypherShell implements StatementExecuter, Connector, TransactionHan
5151
{
5252
// Final space to catch newline
5353
protected static final Pattern cmdNamePattern = Pattern.compile( "^\\s*(?<name>[^\\s]+)\\b(?<args>.*)\\s*$" );
54+
private static final Pattern emptyStatementPattern = Pattern.compile( "^\\s*;$" );
5455
protected final Map<String, ParamValue> queryParams = new HashMap<>();
5556
private final LinePrinter linePrinter;
5657
private final BoltStateHandler boltStateHandler;
@@ -90,6 +91,11 @@ protected static String stripTrailingSemicolons( @Nonnull String text )
9091
@Override
9192
public void execute( @Nonnull final String cmdString ) throws ExitException, CommandException
9293
{
94+
if ( isEmptyStatement( cmdString ) )
95+
{
96+
return;
97+
}
98+
9399
// See if it's a shell command
94100
final Optional<CommandExecutable> cmd = getCommandExecutable( cmdString );
95101
if ( cmd.isPresent() )
@@ -107,6 +113,11 @@ public void execute( @Nonnull final String cmdString ) throws ExitException, Com
107113
executeCypher( cmdString );
108114
}
109115

116+
private static boolean isEmptyStatement( final String statement )
117+
{
118+
return emptyStatementPattern.matcher( statement ).matches();
119+
}
120+
110121
/**
111122
* Executes a piece of text as if it were Cypher. By default, all of the cypher is executed in single statement (with an implicit transaction).
112123
*

cypher-shell/src/test/java/org/neo4j/shell/CypherShellTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,4 +330,13 @@ public void setParameterDoesNotTriggerByBoltError() throws CommandException
330330
Object result = shell.setParameter( "bob", "99" );
331331
assertEquals( 99L, result );
332332
}
333+
334+
@Test
335+
public void ignoreEmptyStatement() throws CommandException
336+
{
337+
when( mockedBoltStateHandler.runCypher( anyString(), anyMap() ) ).thenThrow( new IllegalStateException( "Test failed" ) );
338+
OfflineTestShell shell = new OfflineTestShell( logger, mockedBoltStateHandler, mockedPrettyPrinter );
339+
340+
shell.execute( " \t;" );
341+
}
333342
}

0 commit comments

Comments
 (0)