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]);
}
}