Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix](Prepared Statment) use fixed charset to init StringLiteral #36860

Merged
merged 1 commit into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.Objects;

public class StringLiteral extends LiteralExpr {
Expand Down Expand Up @@ -344,7 +345,9 @@ public void setupParamFromBinary(ByteBuffer data, boolean isUnsigned) {
}
byte[] bytes = new byte[strLen];
data.get(bytes);
value = new String(bytes);
// ATTN: use fixed StandardCharsets.UTF_8 to avoid unexpected charset in
// different environment
value = new String(bytes, StandardCharsets.UTF_8);
if (LOG.isDebugEnabled()) {
LOG.debug("parsed value '{}'", value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import java.math.BigDecimal;
import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.Locale;
import java.util.Objects;
import java.util.Optional;
Expand Down Expand Up @@ -582,14 +583,18 @@ private static Literal handleStringLiteral(ByteBuffer data) {
strLen = Math.min(strLen, data.remaining());
byte[] bytes = new byte[strLen];
data.get(bytes);
return new StringLiteral(new String(bytes));
// ATTN: use fixed StandardCharsets.UTF_8 to avoid unexpected charset in
// different environment
return new StringLiteral(new String(bytes, StandardCharsets.UTF_8));
}

private static Literal handleVarcharLiteral(ByteBuffer data) {
int strLen = getParmLen(data);
strLen = Math.min(strLen, data.remaining());
byte[] bytes = new byte[strLen];
data.get(bytes);
return new VarcharLiteral(new String(bytes));
// ATTN: use fixed StandardCharsets.UTF_8 to avoid unexpected charset in
// different environment
return new VarcharLiteral(new String(bytes, StandardCharsets.UTF_8));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,9 @@ private void handleExecute(PrepareCommand prepareCommand, long stmtId, PreparedS
// process COM_EXECUTE, parse binary row data
// https://dev.mysql.com/doc/dev/mysql-server/latest/page_protocol_com_stmt_execute.html
private void handleExecute() {
// debugPacket();
if (LOG.isDebugEnabled()) {
debugPacket();
}
packetBuf = packetBuf.order(ByteOrder.LITTLE_ENDIAN);
// parse stmt_id, flags, params
int stmtId = packetBuf.getInt();
Expand Down
Loading