Skip to content

Commit

Permalink
MONDRIAN: Fix connect string parser bug 1938151, "StringIndexOutOfBou…
Browse files Browse the repository at this point in the history
…ndsException instead of a meaningful error".

[git-p4: depot-paths = "//open/mondrian/": change = 10843]
  • Loading branch information
julianhyde committed Apr 9, 2008
1 parent 6cdc19d commit 06b76b0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/main/mondrian/olap/Util.java
Expand Up @@ -1655,6 +1655,9 @@ PropertyList parse() {
*/
void parsePair(PropertyList list) {
String name = parseName();
if (name == null) {
return;
}
String value;
if (i >= n) {
value = "";
Expand All @@ -1666,9 +1669,10 @@ void parsePair(PropertyList list) {
}
list.put(name, value);
}

/**
* Reads "name=". Name can contain equals sign if equals sign is
* doubled.
* doubled. Returns null if there is no name to read.
*/
String parseName() {
nameBuf.setLength(0);
Expand All @@ -1690,6 +1694,11 @@ 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/main/mondrian/olap/UtilTestCase.java
Expand Up @@ -78,6 +78,35 @@ public void testConnectStringMore() {
p("empty= ;foo=bar", "empty", "");
}

/**
* Testcase for bug 1938151, "StringIndexOutOfBoundsException instead of a
* meaningful error"
*/
public void testBug1938151 () {
Util.PropertyList properties;

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

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

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

// actual testcase for bug
properties = Util.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.list.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 06b76b0

Please sign in to comment.