From 470608ec7d573600f4b989a9729be3701c0e183b Mon Sep 17 00:00:00 2001 From: Marios Trivyzas Date: Tue, 12 May 2020 16:46:01 +0200 Subject: [PATCH] SQL: Fix JDBC url pattern in docs and error message 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 --- docs/reference/sql/endpoints/jdbc.asciidoc | 2 +- .../org/elasticsearch/xpack/sql/jdbc/JdbcConfiguration.java | 2 +- .../xpack/sql/jdbc/JdbcConfigurationTests.java | 6 ++++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/docs/reference/sql/endpoints/jdbc.asciidoc b/docs/reference/sql/endpoints/jdbc.asciidoc index 7b19d6411bf32..c7c8cb16ee1fa 100644 --- a/docs/reference/sql/endpoints/jdbc.asciidoc +++ b/docs/reference/sql/endpoints/jdbc.asciidoc @@ -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. diff --git a/x-pack/plugin/sql/jdbc/src/main/java/org/elasticsearch/xpack/sql/jdbc/JdbcConfiguration.java b/x-pack/plugin/sql/jdbc/src/main/java/org/elasticsearch/xpack/sql/jdbc/JdbcConfiguration.java index 04ba6046229b1..2578a544b892a 100644 --- a/x-pack/plugin/sql/jdbc/src/main/java/org/elasticsearch/xpack/sql/jdbc/JdbcConfiguration.java +++ b/x-pack/plugin/sql/jdbc/src/main/java/org/elasticsearch/xpack/sql/jdbc/JdbcConfiguration.java @@ -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 + "]"); } diff --git a/x-pack/plugin/sql/jdbc/src/test/java/org/elasticsearch/xpack/sql/jdbc/JdbcConfigurationTests.java b/x-pack/plugin/sql/jdbc/src/test/java/org/elasticsearch/xpack/sql/jdbc/JdbcConfigurationTests.java index 680b1eebe4883..07791430e16f8 100644 --- a/x-pack/plugin/sql/jdbc/src/test/java/org/elasticsearch/xpack/sql/jdbc/JdbcConfigurationTests.java +++ b/x-pack/plugin/sql/jdbc/src/test/java/org/elasticsearch/xpack/sql/jdbc/JdbcConfigurationTests.java @@ -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());