Terminal control characters are not always escaped safely
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 35/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- go
调研方向
从 main.go 中的 Go 复现开始,运行四个 sloghuman 日志记录用例,以比较消息和字段值的呈现方式。跟踪输出格式化和转义路径;完成的标准是,孤立的回车符、响铃符及其他终端控制字符不能被解释,同时预期的对齐 CRLF 呈现仍能被正确理解。
由索引模型根据 Issue 内容生成。
描述
Not sure whether or not this is considered a feature or a bug, but in certain scenarios, terminal escape chars are interpreted as-is, and in other they're escaped into string form.
package main
import (
"context"
"os"
"cdr.dev/slog"
"cdr.dev/slog/sloggers/sloghuman"
)
func main() {
ctx := context.Background()
log := slog.Make(sloghuman.Sink(os.Stderr))
log.Info(ctx, "test1\r\nw\reird\a")
log.Info(ctx, "test2", slog.F("boop", "hello\r\nb\rell\a"))
log.Info(ctx, "test3\r\nt\rest", slog.F("boop", "hello\r\nb\rell\a"))
log.Info(ctx, "test4", slog.F("clipboard", "\033]52;c;surprise!\a"))
}
// Output:
2022-11-10 18:10:11.256 [INFO] <main.go:18> main ...
"msg": test1
eird w
2022-11-10 18:10:11.256 [INFO] <main.go:19> main test2 ...
"boop": hello
ell b
2022-11-10 18:10:11.256 [INFO] <main.go:20> main ... {"boop": "hello\r\nb\rell\u0007"}
"msg": test3
est t
2022-11-10 18:10:11.257 [INFO] <main.go:21> main test4 {"clipboard": "\u001b]52;c;surprise!\u0007"}
Pretty printing \r\n seems intended and like a nice feature (since it's aligned), but stray \r and also \a are interpreted as-is. The latter (\a) will also ring the terminal bell which I would venture is never the expectation.
Out of these 4 cases, only the clipboard case behaved as I would expect.
- 主要语言
- Go
- 星标
- 351
- 派生
- 23
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
coder/slog 的其他 Issue
-
难度 4/5 3-5 天 新手友好度 30/100
-
难度 4/5 3-5 天 新手友好度 35/100
-
feature
难度 5/5 一周以上 新手友好度 20/100
-
feature
难度 3/5 1-2 天 新手友好度 35/100
-
feature
难度 5/5 一周以上 新手友好度 20/100
相似的 Issue
-
enhancement
难度 2/5 1-3 小时 新手友好度 70/100
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 70/100
superplanehq/superplane#8604 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
documentation hacktoberfest priority: low skill: good first issue status: ready for dev
难度 2/5 半天 新手友好度 85/100
hyperledger-labs/fabric-smart-client#2142 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
numberly/vault-db-injector#107 ·
维护者通常 1 天内回复