Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Terminal control characters are not always escaped safely

未关闭
#156 3 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 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,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

coder/slog 的其他 Issue

查看 coder/slog 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。