Skip to content

Commit

Permalink
Fix char counting for multibyte UTF-8 inputs, bump Perl requirement t…
Browse files Browse the repository at this point in the history
…o 5.8.7

Addresses #69 and #65.

This UTF-8 handling approach is based on Debian's UTF-8 handling patch for cowsay 3.03 at https://sources.debian.org/patches/cowsay/3.03%2Bdfsg2-8/utf8_width, discussed at https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=254557. It has been in place on Debian since 2010, so I think we can consider it reasonably well tested and supported.
  • Loading branch information
apjanke committed Dec 1, 2024
1 parent 50fa639 commit b91f3d2
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ Cowsay Changelog

## 3.9.0 (unreleased)

(nothing here yet)
### Changes

- Require Perl 5.8.7 or later.
- Fix character counts for multibyte UTF-8 inputs. ([#69](https://github.com/cowsay-org/cowsay/issues/69))

## 3.8.5 (unreleased)

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ As of 2016, Monroe was no longer interested in maintaining Cowsay, and posted a

## Requirements

Cowsay requires Perl 5.005_03 or later. Because all our development and testing is done with the Perl from recent OS distributions, it may well require a version newer than 5.005_03, but I'm not sure exactly which.
Cowsay requires Perl 5.8.7 or later.

## Other cow collections

Expand Down
19 changes: 19 additions & 0 deletions bin/cowsay
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,25 @@ $Text::Wrap::initial_tab = 8;
$Text::Wrap::subsequent_tab = 8;
$Text::Wrap::tabstop = 8;

sub enable_utf8_input() {
# Enable UTF-8 inputs on stdin/out/err if running in a UTF-8 locale.
# This fixes character-count problems with multibyte UTF-8 characters. (But
# it doesn't handle "wide" characters that should be *displayed* taking up
# multiple character spaces; that's a different issue.)
# This is done in the code here instead of relying on `perl -C` options
# (e.g. in the shebang line) so that it still works when this program is
# called with plain `perl cowsay`.
if (${^UTF8LOCALE}) {
require Encode;
binmode STDIN, ':utf8';
binmode STDOUT, ':utf8';
binmode STDERR, ':utf8';
eval { $_ = Encode::decode_utf8($_,1) } for @ARGV;
}
}

&enable_utf8_input;

%opts = (
'e' => 'oo',
'f' => 'default.cow',
Expand Down
2 changes: 1 addition & 1 deletion doc-project/Release Checklist.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ See the "Developer Notes.md" doc for more details. (Well, as soon as I get to wr
Dependencies and tools needed:

1. Perl
1. Use version 5.005_03 or later, but hopefully not too new (for compatibility). As of 2024-11, I'm testing against Perl 5.40. Really probably should be using whatever version is in the oldest in-support releases of Debian/Ubuntu and Fedora.
1. Use version 5.8.7 or later, but preferably not too new (for compatibility). As of 2024-11, I'm testing against Perl 5.40. Really probably should be using whatever version is in the oldest in-support releases of Debian/Ubuntu and Fedora.
2. Ideally, also test against the current Perl from Mac Homebrew.
2. Asciidoctor
1. Version 2.0.x or later.

0 comments on commit b91f3d2

Please sign in to comment.