Skip to content

Commit

Permalink
copr: don't resize binary opaque when the type flen is unspecified (t…
Browse files Browse the repository at this point in the history
…ikv#16617)

close tikv#16616

Signed-off-by: Yang Keao <yangkeao@chunibyo.icu>

Co-authored-by: Wenxuan <breezewish@outlook.com>
Signed-off-by: dbsid <chenhuansheng@pingcap.com>
  • Loading branch information
2 people authored and dbsid committed Mar 24, 2024
1 parent 100d8a5 commit 9bdb897
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions components/tidb_query_expr/src/impl_cast.rs
Expand Up @@ -1385,8 +1385,9 @@ fn cast_string_as_json(
let mut vec;
if typ.tp() == FieldTypeTp::String {
vec = (*val).to_owned();
// the `flen` of string is always greater than zero
vec.resize(typ.flen().try_into().unwrap(), 0);
if typ.flen() > 0 {
vec.resize(typ.flen().try_into().unwrap(), 0);
}
buf = &vec;
}

Expand Down Expand Up @@ -7022,6 +7023,17 @@ mod tests {
Json::from_opaque(FieldTypeTp::String, &[97]).unwrap(),
true,
),
(
FieldTypeBuilder::new()
.tp(FieldTypeTp::VarChar)
.flen(UNSPECIFIED_LENGTH)
.charset(CHARSET_BIN)
.collation(Collation::Binary)
.build(),
"a".to_string(),
Json::from_opaque(FieldTypeTp::String, &[97]).unwrap(),
true,
),
];
for (arg_type, input, expect, parse_to_json) in cs {
let arg_value = ScalarValue::Bytes(Some(input.clone().into_bytes()));
Expand Down

0 comments on commit 9bdb897

Please sign in to comment.