Skip to content

fix(logging): preserve Unicode prefix spacing - #1759

Open
Ricardo-M-L wants to merge 1 commit into
charmbracelet:mainfrom
Ricardo-M-L:fix/unicode-log-prefix
Open

fix(logging): preserve Unicode prefix spacing#1759
Ricardo-M-L wants to merge 1 commit into
charmbracelet:mainfrom
Ricardo-M-L:fix/unicode-log-prefix

Conversation

@Ricardo-M-L

Copy link
Copy Markdown
Contributor

Problem

LogToFileWith promises to append an ASCII space only when the supplied prefix does not already end in whitespace. It currently inspects the final byte and converts that byte to a rune:

finalChar := prefix[len(prefix)-1]
unicode.IsSpace(rune(finalChar))

That works for ASCII but misreads every multibyte trailing rune. Prefixes ending in valid Unicode whitespace such as U+00A0 NO-BREAK SPACE or U+3000 IDEOGRAPHIC SPACE therefore receive an unwanted extra ASCII space.

Fix

Decode the final UTF-8 rune before applying unicode.IsSpace. ASCII behavior stays unchanged, while multibyte whitespace now follows the documented rule.

The table-driven regression test covers empty prefixes, missing and existing ASCII spaces, U+00A0, and U+3000.

Validation

  • go test -run TestLogToFile -count=100 ./...

  • go test -race -run TestLogToFile -count=20 ./...

  • go test ./...

  • go test -race -count=1 ./...

  • go vet ./...

  • go test ./... in examples/

  • go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.9.0 run

  • git diff --check

  • I have read CONTRIBUTING.md.

@Ricardo-M-L

Copy link
Copy Markdown
Contributor Author

Friendly ping — this is a minimal cosmetic fix preserving Unicode prefix spacing in log output. No functional changes. Any feedback welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant