mirror of
https://github.com/alibaba/canal.git
synced 2026-11-04 00:30:15 +08:00
fix JSON datatype string value truncated by '\0' (#5482)
This commit is contained in:
@@ -158,7 +158,7 @@ public class JsonConversion {
|
||||
throw new IllegalArgumentException("illegal json data");
|
||||
}
|
||||
return new Json_Value(Json_enum_type.STRING,
|
||||
buffer.rewind().forward((int) n).getFixString((int) str_len, charset));
|
||||
buffer.rewind().forward((int) n).getFixStringIgnore0000((int) str_len, charset));
|
||||
case JSONB_TYPE_OPAQUE:
|
||||
/*
|
||||
* There should always be at least one byte, which tells the field type of the
|
||||
@@ -257,7 +257,7 @@ public class JsonConversion {
|
||||
// entry, always two
|
||||
// bytes.
|
||||
long key_length = m_data.getUint16();
|
||||
return m_data.rewind().forward((int) key_offset).getFixString((int) key_length, charset);
|
||||
return m_data.rewind().forward((int) key_offset).getFixStringIgnore0000((int) key_length, charset);
|
||||
}
|
||||
|
||||
public Json_Value element(int i, Charset charset) {
|
||||
@@ -400,7 +400,7 @@ public class JsonConversion {
|
||||
}
|
||||
buf.append('"').append(text).append('"');
|
||||
} else {
|
||||
text = m_data.getFixString((int) m_length, charset);
|
||||
text = m_data.getFixStringIgnore0000((int) m_length, charset);
|
||||
buf.append('"').append(escapse(text)).append('"');
|
||||
}
|
||||
|
||||
|
||||
@@ -1156,6 +1156,22 @@ public class LogBuffer {
|
||||
return string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return next fix length string from buffer. ignore \0
|
||||
*/
|
||||
public final String getFixStringIgnore0000(final int len, Charset charset) {
|
||||
if (position + len > origin + limit) {
|
||||
throw new IllegalArgumentException("limit excceed: " + (position + len - origin));
|
||||
}
|
||||
|
||||
final int from = position;
|
||||
byte[] buf = buffer;
|
||||
|
||||
String string = new String(buf, from, len, charset);
|
||||
position += len;
|
||||
return string;
|
||||
}
|
||||
|
||||
public final String getFixName(final int len, Charset charset) {
|
||||
if (position + len > origin + limit) {
|
||||
throw new IllegalArgumentException("limit excceed: " + (position + len - origin));
|
||||
|
||||
Reference in New Issue
Block a user