Skip to content

Commit

Permalink
fix utf8.DecodeRune error condition check
Browse files Browse the repository at this point in the history
On error it's documented as returning "RuneError, 1" (which is
incorrect/wrong, since RuneError has size 2). But we didn't check that
second return value, so when you actually *wanted* RuneError it didn't
work.

Fixes #46
  • Loading branch information
arp242 committed Nov 24, 2023
1 parent d2f428c commit 5f9eb0d
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion uni.go
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ func print(args []string, format string, raw bool, as printAs) error {
}

r, s := utf8.DecodeRune(byt)
if r == utf8.RuneError {
if r == utf8.RuneError && s == 1 {
return fmt.Errorf("invalid UTF-8 sequence: %q", a)
}
if s != len(byt) {
Expand Down

0 comments on commit 5f9eb0d

Please sign in to comment.