Skip to content

Commit

Permalink
SQL: Fix JDBC url pattern in docs and error message
Browse files Browse the repository at this point in the history
The docs pattern url was using `*` which means zero or many instead
of `?` which means zero or one. The pattern url returned in error
messages was not in sync with the one in the docs.

Fixes: elastic#56476
  • Loading branch information
matriv committed May 12, 2020
1 parent eb4a557 commit 470608e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/reference/sql/endpoints/jdbc.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Once registered, the driver understands the following syntax as an URL:

["source","text",subs="attributes"]
----
jdbc:es://[[http|https]://]*[host[:port]]*/[prefix]*<[?[option=value]&]*
jdbc:es://[[http|https]://]?[host[:port]]?/[prefix]?[?[option=value]&]*
----
`jdbc:es://`:: Prefix. Mandatory.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public static JdbcConfiguration create(String u, Properties props, int loginTime

private static URI parseUrl(String u) throws JdbcSQLException {
String url = u;
String format = "jdbc:es://[http|https]?[host[:port]]*/[prefix]*[?[option=value]&]*";
String format = "jdbc:es://[[http|https]://]?[host[:port]]?/[prefix]?[\\?[option=value]&]*";
if (!canAccept(u)) {
throw new JdbcSQLException("Expected [" + URL_PREFIX + "] url, received [" + u + "]");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ private JdbcConfiguration ci(String url) throws SQLException {
return JdbcConfiguration.create(url, null, 0);
}

public void testInvalidUrl() {
JdbcSQLException e = expectThrows(JdbcSQLException.class, () -> ci("jdbc:es://localhost9200/?ssl=#5#"));
assertEquals("Invalid URL [jdbc:es://localhost9200/?ssl=#5#], format should be " +
"[jdbc:es://[[http|https]://]?[host[:port]]?/[prefix]?[\\?[option=value]&]*]", e.getMessage());
}

public void testJustThePrefix() throws Exception {
Exception e = expectThrows(JdbcSQLException.class, () -> ci("jdbc:es:"));
assertEquals("Expected [jdbc:es://] url, received [jdbc:es:]", e.getMessage());
Expand Down

0 comments on commit 470608e

Please sign in to comment.