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

Commit b0f5cb4

Browse files
authored
Merge pull request #280 from loveleif/4.2-use-semicolon
Ignore empty statements
2 parents 9dc4bb4 + 7cb3914 commit b0f5cb4

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

cypher-shell/src/integration-test/java/org/neo4j/shell/commands/CypherShellPlainIntegrationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public void cypherWithProfileWithMemory() throws CommandException
108108
//then
109109
String actual = linePrinter.output();
110110
System.out.println( actual );
111-
assertThat( actual, containsString( "Memory (Bytes): 0" ) );
111+
assertThat( actual, containsString( "Memory (Bytes): " ) );
112112
}
113113

114114
@Test

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public class CypherShell implements StatementExecuter, Connector, TransactionHan
4646
{
4747
// Final space to catch newline
4848
private static final Pattern cmdNamePattern = Pattern.compile( "^\\s*(?<name>[^\\s]+)\\b(?<args>.*)\\s*$" );
49+
private static final Pattern emptyStatementPattern = Pattern.compile( "^\\s*;$" );
4950
private final ParameterMap parameterMap;
5051
private final LinePrinter linePrinter;
5152
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
@Override
111122
public String lastNeo4jErrorCode()
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
@@ -293,4 +293,13 @@ public void setParameterDoesNotTriggerByBoltError() throws ParameterException, C
293293
Object result = shell.getParameterMap().setParameter( "bob", "99" );
294294
assertEquals( 99L, result );
295295
}
296+
297+
@Test
298+
public void ignoreEmptyStatement() throws CommandException
299+
{
300+
when( mockedBoltStateHandler.runCypher( anyString(), anyMap() ) ).thenThrow( new IllegalStateException( "Test failed" ) );
301+
OfflineTestShell shell = new OfflineTestShell( logger, mockedBoltStateHandler, mockedPrettyPrinter );
302+
303+
shell.execute( " \t;" );
304+
}
296305
}

0 commit comments

Comments
 (0)