Skip to content

Commit

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

close #16616

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

Co-authored-by: Yang Keao <yangkeao@chunibyo.icu>
Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
  • Loading branch information
3 people committed Apr 1, 2024
1 parent b7e9fd7 commit 1db3656
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 @@ -7021,6 +7022,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 1db3656

Please sign in to comment.