-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Log::Dispatch:Screen: fix encoding test #68
base: master
Are you sure you want to change the base?
Conversation
The STD{IN,OUT,ERR} default handles start out in some unspecified (platform-specific) text encoding. The 'utf8' option of Log::Dispatch::Screen manually encodes the logged messages as bytes in UTF-8 format before writing them to the output handle. Thus, by default, the UTF-8 bytes get re-encoded by whatever the native text encoding is on the platform. The correct way to handle this is to either not set 'utf8' (and rely on the encoding layer of the handle) or set 'utf8' and call binmode() on the handle (or otherwise apply a ':raw' layer) to ensure that bytes are written as is (without further re-encoding). Fixes houseabsolute#32.
Hi @mauke, Thanks for this PR. It's been a while since I thought about this, but looking at the discussion in #32, I'm not sure this is a good change. Here's a summary of relevant points from the discussion:
What do you think? |
I have some objections.
Quoting
... which is all systems that use Unicode, like mine (with
My use case is explicitly supported by how (Also, just once I'd like to be able to say |
I personally prefer to avoid PERL_UNICODE, but I think that it is correct that the test should ensure it is testing byte stream handles regardless of this - the failure does not seem useful to me, particularly to the end user of Log::Dispatch or modules using it. |
Additionally, both the reason I avoid PERL_UNICODE and the reason I am hesitant to recommend changing the runtime behavior of the module is that changing the handles one way or another is global behavior which requires every part of the program to make the same correct assumptions. "Fixing" the handles to be binary at runtime could arbitrarily break the next warning another part of the program emits. |
The STD{IN,OUT,ERR} default handles start out in some unspecified (platform-specific) text encoding. The 'utf8' option of Log::Dispatch::Screen manually encodes the logged messages as bytes in UTF-8 format before writing them to the output handle. Thus, by default, the UTF-8 bytes get re-encoded by whatever the native text encoding is on the platform.
The correct way to handle this is to either not set 'utf8' (and rely on the encoding layer of the handle) or set 'utf8' and call binmode() on the handle (or otherwise apply a ':raw' layer) to ensure that bytes are written as is (without further re-encoding).
Fixes #32.