mirror of
https://github.com/t8y2/dbx.git
synced 2026-10-28 00:06:50 +00:00
fix(redis): 优化 UTF-8 展示与提示文案
This commit is contained in:
@@ -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";
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -523,6 +523,7 @@ export default {
|
||||
members: "{count} 个成员",
|
||||
entries: "{count} 条记录",
|
||||
noExpiry: "永不过期",
|
||||
binaryStringReadonlyHint: "二进制字符串按转义文本只读展示;当前不支持直接编辑原始字节值。",
|
||||
},
|
||||
mongo: {
|
||||
documents: "{count} 个文档",
|
||||
|
||||
Reference in New Issue
Block a user