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

Commit bb2f0c8

Browse files
authored
Merge pull request #257 from pontusmelke/4.2-url-error
Support host:port without scheme
2 parents 48b93f9 + 9429735 commit bb2f0c8

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

cypher-shell/src/main/java/org/neo4j/shell/cli/CliArgHelper.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.neo4j.shell.ParameterMap;
2626

2727
import static java.lang.String.format;
28+
import static org.neo4j.shell.cli.CliArgs.DEFAULT_SCHEME;
2829
import static org.neo4j.shell.cli.FailBehavior.FAIL_AT_END;
2930
import static org.neo4j.shell.cli.FailBehavior.FAIL_FAST;
3031

@@ -152,6 +153,12 @@ static URI parseURI( ArgumentParser parser, String address )
152153
{
153154
try
154155
{
156+
String[] schemeSplit = address.split( "://" );
157+
if ( schemeSplit.length == 1 )
158+
{
159+
// URI can't parse addresses without scheme, prepend fake "bolt://" to reuse the parsing facility
160+
address = DEFAULT_SCHEME + "://" + address;
161+
}
155162
return new URI( address );
156163
}
157164
catch ( URISyntaxException e )

cypher-shell/src/test/java/org/neo4j/shell/cli/CliArgHelperTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,15 @@ public void defaultAddress()
165165
assertEquals( CliArgs.DEFAULT_PORT, cliArgs.getPort() );
166166
}
167167

168+
public void parseWithoutProtocol() {
169+
CliArgs cliArgs = CliArgHelper.parse("--address", "localhost:10000");
170+
assertNotNull(cliArgs);
171+
assertNotNull(cliArgs);
172+
assertEquals("bolt", cliArgs.getScheme());
173+
assertEquals("localhost", cliArgs.getHost());
174+
assertEquals(10000, cliArgs.getPort());
175+
}
176+
168177
@Test
169178
public void parseAddressWithRoutingContext()
170179
{

0 commit comments

Comments
 (0)