fix(redis): bound large string previews to avoid crashes
This commit is contained in:
14 files changed
+210
-29
No files matched your search
@@ -180,6 +180,23 @@ describe("redisValuePresentation", () => {
|
||||
expect(redisValueSize(value)).toBe(1);
|
||||
});
|
||||
|
||||
it("uses the original byte count for a truncated Redis String preview", () => {
|
||||
const value = {
|
||||
key_display: "bf:ali_health_monitor",
|
||||
key_raw: "YmY6YWxpX2hlYWx0aF9tb25pdG9y",
|
||||
ttl: -1,
|
||||
redis_type: "string",
|
||||
data: {
|
||||
kind: "string" as const,
|
||||
content: { raw_base64: "cHJldmlldw==", encoding: "utf8" as const },
|
||||
total_bytes: 45 * 1024 * 1024,
|
||||
truncated: true,
|
||||
},
|
||||
};
|
||||
|
||||
expect(redisValueSize(value)).toBe(45 * 1024 * 1024);
|
||||
});
|
||||
|
||||
it("labels raw text views by encoding instead of generic raw text", () => {
|
||||
expect(formatRedisMemberDetail("plain-text").rawLabel).toBe("ASCII");
|
||||
expect(
|
||||
|
||||
@@ -2542,7 +2542,7 @@ export interface RedisStreamPendingPage {
|
||||
}
|
||||
|
||||
export type RedisValueData =
|
||||
| { kind: "string"; content: RedisBlob }
|
||||
| { kind: "string"; content: RedisBlob; total_bytes?: number; truncated?: boolean }
|
||||
| { kind: "json"; value: string }
|
||||
| {
|
||||
kind: "list";
|
||||
|
||||
@@ -446,7 +446,7 @@ export function redisValueCollectionScanCursor(value: RedisValue): number | unde
|
||||
export function redisValueSize(value: RedisValue): number {
|
||||
switch (value.data.kind) {
|
||||
case "string":
|
||||
return decodeRedisBlob(value.data.content).byteLength;
|
||||
return value.data.total_bytes ?? decodeRedisBlob(value.data.content).byteLength;
|
||||
case "json":
|
||||
return new TextEncoder().encode(redisJsonValueText(value.data)).byteLength;
|
||||
case "list":
|
||||
|
||||
Reference in new issue
Block a user