Skip to content
Snippets Groups Projects
Unverified Commit 0a714b88 authored by Ryan Senior's avatar Ryan Senior Committed by GitHub
Browse files

Merge pull request #8641 from metabase/allow-jdbc-prefix

Ignore leading `jdbc` prefix in JDBC connection uri
parents 0224abdf 1bf2152b
No related branches found
No related tags found
No related merge requests found
......@@ -46,12 +46,15 @@
;; if we don't have an absolute path then make sure we start from "user.dir"
[(System/getProperty "user.dir") "/" db-file-name options]))))))
(def ^:private jdbc-connection-regex
#"^(jdbc:)?([^:/@]+)://(?:([^:/@]+)(?::([^:@]+))?@)?([^:@]+)(?::(\d+))?/([^/?]+)(?:\?(.*))?$")
(defn- parse-connection-string
"Parse a DB connection URI like
`postgres://cam@localhost.com:5432/cams_cool_db?ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory` and
return a broken-out map."
[uri]
(when-let [[_ protocol user pass host port db query] (re-matches #"^([^:/@]+)://(?:([^:/@]+)(?::([^:@]+))?@)?([^:@]+)(?::(\d+))?/([^/?]+)(?:\?(.*))?$" uri)]
(when-let [[_ _ protocol user pass host port db query] (re-matches jdbc-connection-regex uri)]
(merge {:type (case (keyword protocol)
:postgres :postgres
:postgresql :postgres
......
......@@ -18,3 +18,10 @@
:ssl "true", :sslfactory "org.postgresql.ssl.NonValidatingFactory"}
(#'mdb/parse-connection-string (str "postgres://tom:1234@localhost:5432/toms_cool_db"
"?ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory")))
;; the leading "jdbc" found in driver JDBC docs should be ignored
(expect
{:type :postgres, :user "tom", :password "1234", :host "localhost", :port "5432", :dbname "toms_cool_db",
:ssl "true", :sslfactory "org.postgresql.ssl.NonValidatingFactory"}
(#'mdb/parse-connection-string (str "jdbc:postgres://tom:1234@localhost:5432/toms_cool_db"
"?ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory")))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment