Skip to content

Commit

Permalink
Fix bug in connect-string parser (see mondrian bug 1938151)
Browse files Browse the repository at this point in the history
git-svn-id: https://olap4j.svn.sourceforge.net/svnroot/olap4j/trunk@86 c6a108a4-781c-0410-a6c6-c2d559e19af0
  • Loading branch information
julianhyde committed Apr 9, 2008
1 parent e2863ed commit dc08e7c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/org/olap4j/impl/ConnectStringParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ private PropertyMap parse() {
*/
private void parsePair(PropertyMap map) {
String name = parseName();
if (name == null) {
return;
}
String value;
if (i >= n) {
value = "";
Expand All @@ -93,7 +96,8 @@ private void parsePair(PropertyMap map) {
* Reads "name=". Name can contain equals sign if equals sign is
* doubled.
*
* @return Next name in the connect string being parsed
* @return Next name in the connect string being parsed, or null if there
* is no further name
*/
private String parseName() {
nameBuf.setLength(0);
Expand All @@ -115,6 +119,11 @@ private String parseName() {
if (nameBuf.length() == 0) {
// ignore preceding spaces
i++;
if (i >= n) {
// there is no name, e.g. trailing spaces after
// semicolon, 'x=1; y=2; '
return null;
}
break;
} else {
// fall through
Expand Down
29 changes: 29 additions & 0 deletions testsrc/org/olap4j/impl/ConnectStringParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,35 @@ public void testConnectStringMore() {
p("empty= ;foo=bar", "empty", "");
}

/**
* Testcase for bug 1938151, "StringIndexOutOfBoundsException instead of a
* meaningful error"
*/
public void testBug1938151 () {
Map<String, String> properties;

// ends in semi
properties = ConnectStringParser.parseConnectString("foo=true; bar=xxx;");
assertEquals(2, properties.size());

// ends in semi+space
properties = ConnectStringParser.parseConnectString("foo=true; bar=xxx; ");
assertEquals(2, properties.size());

// ends in space
properties = ConnectStringParser.parseConnectString(" ");
assertEquals(0, properties.size());

// actual testcase for bug
properties = ConnectStringParser.parseConnectString(
"provider=mondrian; JdbcDrivers=org.hsqldb.jdbcDriver;"
+ "Jdbc=jdbc:hsqldb:./sql/sampledata;"
+ "Catalog=C:\\cygwin\\home\\src\\jfreereport\\engines\\classic\\extensions-mondrian\\demo\\steelwheels.mondrian.xml;"
+ "JdbcUser=sa; JdbcPassword=; ");
assertEquals(6, properties.size());
assertEquals("", properties.get("JdbcPassword"));
}

/**
* Checks that <code>connectString</code> contains a property called
* <code>name</code>, whose value is <code>value</code>.
Expand Down

0 comments on commit dc08e7c

Please sign in to comment.