Skip to content

Commit

Permalink
Revert "fix: don't ignore unquoted non-ascii whitespace"
Browse files Browse the repository at this point in the history
This reverts commit 8281083.
  • Loading branch information
bokken committed Jul 21, 2018
1 parent 8281083 commit 8b5072d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 42 deletions.
26 changes: 1 addition & 25 deletions pgjdbc/src/main/java/org/postgresql/jdbc/PgArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ private synchronized void buildArrayList() throws SQLException {
insideString = !insideString;
wasInsideString = true;
continue;
} else if (!insideString && isArrayWhiteSpace(chars[i])) {
} else if (!insideString && Character.isWhitespace(chars[i])) {
// white space
continue;
} else if ((!insideString && (chars[i] == delim || chars[i] == '}'))
Expand Down Expand Up @@ -529,30 +529,6 @@ private synchronized void buildArrayList() throws SQLException {
}
}

/**
* Is whitespace which postgresql will force quotes.
*
* https://github.com/postgres/postgres/blob/f2c587067a8eb9cf1c8f009262381a6576ba3dd0/src/backend/utils/adt/arrayfuncs.c#L421-L438
*
* @param c
* Character to examine.
* @return Indication if the character is a whitespace which back end will
* escape.
*/
private static boolean isArrayWhiteSpace(char c) {
switch (c) {
case '\t':
case '\n':
// vertical tab
case 0x0B:
case '\f':
case '\r':
case ' ':
return true;
}
return false;
}

/**
* Convert {@link ArrayList} to array.
*
Expand Down
21 changes: 4 additions & 17 deletions pgjdbc/src/test/java/org/postgresql/test/jdbc2/ArrayTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,10 @@ public void testSetNull() throws SQLException {

@Test
public void testSetPrimitiveObjects() throws SQLException {

final String stringWithNonAsciiWhiteSpace = "a\u2001b";
PreparedStatement pstmt = conn.prepareStatement("INSERT INTO arrtest VALUES (?,?,?)");
pstmt.setObject(1, new int[] { 1, 2, 3 }, Types.ARRAY);
pstmt.setObject(2, new double[] { 3.1d, 1.4d }, Types.ARRAY);
pstmt.setObject(3, new String[] { stringWithNonAsciiWhiteSpace, "f'a", "fa\"b" }, Types.ARRAY);
pstmt.setObject(1, new int[]{1,2,3}, Types.ARRAY);
pstmt.setObject(2, new double[]{3.1d, 1.4d}, Types.ARRAY);
pstmt.setObject(3, new String[]{"abc", "f'a", "fa\"b"}, Types.ARRAY);
pstmt.executeUpdate();
pstmt.close();

Expand Down Expand Up @@ -122,9 +120,6 @@ public void testSetPrimitiveObjects() throws SQLException {
assertEquals("f'a", strarr[0]);
assertEquals("fa\"b", strarr[1]);

strarr = (String[]) arr.getArray();
assertEquals(stringWithNonAsciiWhiteSpace, strarr[0]);

rs.close();
}

Expand Down Expand Up @@ -247,10 +242,9 @@ public void testRetrieveArrays() throws SQLException {
public void testRetrieveResultSets() throws SQLException {
Statement stmt = conn.createStatement();

final String stringWithNonAsciiWhiteSpace = "a\u2001b";
// you need a lot of backslashes to get a double quote in.
stmt.executeUpdate("INSERT INTO arrtest VALUES ('{1,2,3}','{3.1,1.4}', '"
+ TestUtil.escapeString(conn, "{\"a\u2001b\",f'a,\"fa\\\"b\",def}") + "')");
+ TestUtil.escapeString(conn, "{abc,f'a,\"fa\\\"b\",def}") + "')");

ResultSet rs = stmt.executeQuery("SELECT intarr, decarr, strarr FROM arrtest");
Assert.assertTrue(rs.next());
Expand Down Expand Up @@ -295,13 +289,6 @@ public void testRetrieveResultSets() throws SQLException {
Assert.assertTrue(!arrrs.next());
arrrs.close();

arrrs = arr.getResultSet(1, 1);
Assert.assertTrue(arrrs.next());
Assert.assertEquals(1, arrrs.getInt(1));
Assert.assertEquals(stringWithNonAsciiWhiteSpace, arrrs.getString(2));
Assert.assertFalse(arrrs.next());
arrrs.close();

rs.close();
stmt.close();
}
Expand Down

0 comments on commit 8b5072d

Please sign in to comment.