Skip to content
Permalink
Browse files

[misc] better unexcepected character when malformed String (wrong sur…

…rogate)

(cherry picked from commit db8da1f)
  • Loading branch information...
rusher committed Jun 19, 2018
1 parent 0abceec commit bedc9a55a64b33d6f0bd69e8d41c10ae7f625a5e
@@ -545,12 +545,12 @@ public void write(String str, boolean escape, boolean noBackslashEscapes) throws
charsOffset++;
} else {
//must have low surrogate
buf[pos++] = (byte) 0x63;
buf[pos++] = (byte) 0x3f;
}
}
} else {
//low surrogate without high surrogate before
buf[pos++] = (byte) 0x63;
buf[pos++] = (byte) 0x3f;
}
} else {
buf[pos++] = (byte) (0xe0 | ((currChar >> 12)));
@@ -265,4 +265,26 @@ public void languageCasing() throws SQLException {
}
}

@Test
public void wrongSurrogate() throws Throwable {
byte[] bb = "a\ud800b".getBytes("utf8");
Connection conn = null;
try {
conn = setConnection();
Statement stmt = conn.createStatement();
stmt.execute("CREATE TEMPORARY TABLE wrong_utf8_string(tt text) CHARSET utf8mb4");
String wrongString = "a\ud800b";

PreparedStatement preparedStatement = conn.prepareStatement("INSERT INTO wrong_utf8_string values (?)");
preparedStatement.setString(1, wrongString);
preparedStatement.execute();
preparedStatement.close();
ResultSet rs = stmt.executeQuery("SELECT * from wrong_utf8_string");
assertTrue(rs.next());
assertEquals("a?b", rs.getString(1));
} finally {
if (conn != null) conn.close();
}
}

}

0 comments on commit bedc9a5

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