Skip to content
Permalink
Browse files

Fix setURL in BaseDataSource (#1341)

* make sure an invalid URL throws an exception in setUrl
  • Loading branch information...
davecramer committed Nov 22, 2018
1 parent 9f248e1 commit 2ad1ac3fc0e07edce957aaed51167240a970b1f1
@@ -1109,6 +1109,9 @@ public void setUrl(String url) {

Properties p = org.postgresql.Driver.parseURL(url, null);

if (p == null ) {
throw new IllegalArgumentException("URL invalid " + url);
}
for (PGProperty property : PGProperty.values()) {
if (!this.properties.containsKey(property.getName())) {
setProperty(property, property.get(p));
@@ -5,8 +5,11 @@

package org.postgresql.test.jdbc2.optional;

import org.postgresql.ds.PGSimpleDataSource;
import org.postgresql.jdbc2.optional.SimpleDataSource;

import org.junit.Test;

/**
* Performs the basic tests defined in the superclass. Just adds the configuration logic.
*
@@ -24,4 +27,11 @@ protected void initializeDataSource() {
setupDataSource(bds);
}
}

@Test(expected = IllegalArgumentException.class)
public void testTypoPostgresUrl() {
PGSimpleDataSource ds = new PGSimpleDataSource();
// this should fail because the protocol is wrong.
ds.setUrl("jdbc:postgres://localhost:5432/test");
}
}

0 comments on commit 2ad1ac3

Please sign in to comment.
You can’t perform that action at this time.