SQL: Fix JDBC url pattern in docs and error message (#56612)

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: #56476
(cherry picked from commit 1a5945c3962cdda21482f4b0b3e0ca508534c2c4)
This commit is contained in:
Marios Trivyzas 2020-05-13 12:12:23 +02:00
parent c10b4ae15a
commit e781193cf9
No known key found for this signature in database
GPG Key ID: 98004DCEA1252F3D
3 changed files with 8 additions and 2 deletions

View File

@ -51,7 +51,7 @@ Once registered, the driver understands the following syntax as an URL:
["source","text",subs="attributes"] ["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. `jdbc:es://`:: Prefix. Mandatory.

View File

@ -112,7 +112,7 @@ public class JdbcConfiguration extends ConnectionConfiguration {
private static URI parseUrl(String u) throws JdbcSQLException { private static URI parseUrl(String u) throws JdbcSQLException {
String url = u; 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)) { if (!canAccept(u)) {
throw new JdbcSQLException("Expected [" + URL_PREFIX + "] url, received [" + u + "]"); throw new JdbcSQLException("Expected [" + URL_PREFIX + "] url, received [" + u + "]");
} }

View File

@ -36,6 +36,12 @@ public class JdbcConfigurationTests extends ESTestCase {
return JdbcConfiguration.create(url, null, 0); 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 { public void testJustThePrefix() throws Exception {
Exception e = expectThrows(JdbcSQLException.class, () -> ci("jdbc:es:")); Exception e = expectThrows(JdbcSQLException.class, () -> ci("jdbc:es:"));
assertEquals("Expected [jdbc:es://] url, received [jdbc:es:]", e.getMessage()); assertEquals("Expected [jdbc:es://] url, received [jdbc:es:]", e.getMessage());