fix(redis): 优化 UTF-8 展示与提示文案

This commit is contained in:
Bacon2994
2026-05-08 10:31:51 +08:00
parent b669efb5ff
commit d6f5c25c17
4 changed files with 14 additions and 1 deletions
+11
View File
@@ -349,6 +349,10 @@ fn redis_bytes_need_escape(bytes: &[u8]) -> bool {
}
fn redis_bytes_to_display(bytes: &[u8]) -> String {
if let Ok(text) = std::str::from_utf8(bytes) {
return text.replace('\\', "\\\\");
}
let mut output = String::new();
for &byte in bytes {
match byte {
@@ -498,6 +502,13 @@ mod tests {
assert_eq!(redis_key_bytes_to_display(&bytes), "\\xac\\xed\\x00\\x05t\\x00A\\\\");
}
#[test]
fn preserves_utf8_keys_as_readable_text() {
let bytes = "用户:配置".as_bytes();
assert_eq!(redis_key_bytes_to_display(bytes), "用户:配置");
}
#[test]
fn round_trips_raw_key_transport() {
let bytes = b"\xAC\xED\x00\x05t\x00token";
+1 -1
View File
@@ -189,7 +189,7 @@ onMounted(load);
@input="handleStringInput"
/>
<div v-if="isBinaryStringValue" class="px-4 py-2 border-t text-xs text-muted-foreground shrink-0">
二进制字符串按转义文本只读展示;当前不支持直接编辑原始字节值。
{{ t("redis.binaryStringReadonlyHint") }}
</div>
<div v-if="isEditing" class="px-4 py-2 border-t flex justify-end gap-2 shrink-0">
<Button
+1
View File
@@ -532,6 +532,7 @@ export default {
members: "{count} members",
entries: "{count} entries",
noExpiry: "no expiry",
binaryStringReadonlyHint: "Binary string values are shown as escaped text in read-only mode; editing raw bytes is not supported.",
},
mongo: {
documents: "{count} documents",
+1
View File
@@ -523,6 +523,7 @@ export default {
members: "{count} 个成员",
entries: "{count} 条记录",
noExpiry: "永不过期",
binaryStringReadonlyHint: "二进制字符串按转义文本只读展示;当前不支持直接编辑原始字节值。",
},
mongo: {
documents: "{count} 个文档",