fix: properly display CJK characters in table/column comments (#5633)

fix/comment-in-cjk:
 ### Update `OptionMap` Formatting and Add Tests

 - **Enhancements in `OptionMap`**:
   - Changed formatting from `escape_default` to `escape_debug` for better handling of special characters in `src/sql/src/statements/option_map.rs`.
   - Added unit tests to verify the new formatting behavior.

 - **Test Cases for CJK Comments**:
   - Added test cases for tables with comments in CJK (Chinese, Japanese, Korean) characters in `tests/cases/standalone/common/show/show_create.sql` and `show_create.result`.
This commit is contained in:
Lei, HUANG
2025-03-03 20:32:19 +08:00
committed by GitHub
parent ca81fc6a70
commit 4a277c21ef
3 changed files with 62 additions and 2 deletions

View File

@@ -82,9 +82,9 @@ impl OptionMap {
let mut result = Vec::with_capacity(self.options.len() + self.secrets.len());
for (k, v) in self.options.iter() {
if k.contains(".") {
result.push(format!("'{k}' = '{}'", v.escape_default()));
result.push(format!("'{k}' = '{}'", v.escape_debug()));
} else {
result.push(format!("{k} = '{}'", v.escape_default()));
result.push(format!("{k} = '{}'", v.escape_debug()));
}
}
for (k, _) in self.secrets.iter() {
@@ -154,3 +154,23 @@ impl VisitMut for OptionMap {
ControlFlow::Continue(())
}
}
#[cfg(test)]
mod tests {
use crate::statements::OptionMap;
#[test]
fn test_format() {
let mut map = OptionMap::default();
map.insert("comment".to_string(), "中文comment".to_string());
assert_eq!("comment = '中文comment'", map.kv_pairs()[0]);
let mut map = OptionMap::default();
map.insert("a.b".to_string(), "中文comment".to_string());
assert_eq!("'a.b' = '中文comment'", map.kv_pairs()[0]);
let mut map = OptionMap::default();
map.insert("a.b".to_string(), "中文comment\n".to_string());
assert_eq!("'a.b' = '中文comment\\n'", map.kv_pairs()[0]);
}
}

View File

@@ -392,3 +392,32 @@ drop table test_column_constrain_composite_indexes;
Affected Rows: 0
CREATE TABLE `table_comment_in_cjk` (
`ts` TIMESTAMP(3) NOT NULL COMMENT '时间戳',
`val` DOUBLE NULL COMMENT '值',
TIME INDEX ("ts"),
) WITH (comment = '你好\nこんにちは\n안녕하세요');
Affected Rows: 0
show create table table_comment_in_cjk;
+----------------------+-----------------------------------------------------+
| Table | Create Table |
+----------------------+-----------------------------------------------------+
| table_comment_in_cjk | CREATE TABLE IF NOT EXISTS "table_comment_in_cjk" ( |
| | "ts" TIMESTAMP(3) NOT NULL COMMENT '时间戳', |
| | "val" DOUBLE NULL COMMENT '值', |
| | TIME INDEX ("ts") |
| | ) |
| | |
| | ENGINE=mito |
| | WITH( |
| | comment = '你好\\nこんにちは\\n안녕하세요' |
| | ) |
+----------------------+-----------------------------------------------------+
drop table table_comment_in_cjk;
Affected Rows: 0

View File

@@ -153,3 +153,14 @@ CREATE TABLE test_column_constrain_composite_indexes (
show create table test_column_constrain_composite_indexes;
drop table test_column_constrain_composite_indexes;
CREATE TABLE `table_comment_in_cjk` (
`ts` TIMESTAMP(3) NOT NULL COMMENT '时间戳',
`val` DOUBLE NULL COMMENT '',
TIME INDEX ("ts"),
) WITH (comment = '你好\nこんにちは\n안녕하세요');
show create table table_comment_in_cjk;
drop table table_comment_in_cjk;