Skip Menu |
 

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the CGI CPAN distribution.

Report information
The Basics
Id: 57524
Status: resolved
Priority: 0/
Queue: CGI

People
Owner: Nobody in particular
Requestors: mkanat [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: (no value)
Fixed in: (no value)



Subject: CGI.pm always calls binmode on STDOUT, STDERR, and STDIN, even if they already have IO layers
Download (untitled) / with headers
text/plain 382b
In one of my scripts, before I load CGI.pm, I have an encoding() layer set on STDOUT. Simply calling "use CGI;" will remove that layer, because CGI.pm does this: if ($needs_binmode) { $CGI::DefaultClass->binmode(\*main::STDOUT); $CGI::DefaultClass->binmode(\*main::STDIN); $CGI::DefaultClass->binmode(\*main::STDERR); } Thus clearing any already-pushed IO layer.
Subject: Re: [rt.cpan.org #57524] CGI.pm always calls binmode on STDOUT, STDERR, and STDIN, even if they already have IO layers
Date: Sun, 16 May 2010 17:25:56 -0400
To: bug-CGI.pm [...] rt.cpan.org
From: Mark Stosberg <mark [...] summersault.com>
Download (untitled) / with headers
text/plain 478b
Show quoted text
> > In one of my scripts, before I load CGI.pm, I have an encoding() layer > set on STDOUT. Simply calling "use CGI;" will remove that layer, because > CGI.pm does this: > > if ($needs_binmode) { > $CGI::DefaultClass->binmode(\*main::STDOUT); > $CGI::DefaultClass->binmode(\*main::STDIN); > $CGI::DefaultClass->binmode(\*main::STDERR); > } > > Thus clearing any already-pushed IO layer.
Thanks for the report. What alternative do you recommend? Mark
Download (untitled) / with headers
text/plain 763b
On Sun May 16 17:26:09 2010, mark@summersault.com wrote: Show quoted text
> Thanks for the report. What alternative do you recommend?
I'm actually not quite sure. I don't know how to check if a file handle is already in binmode. I do know how to check if it has an encoding or utf8 layer on it, though, which is PerlIO::get_layers(FH). What's the purpose of setting binmode on STD* on Windows? Is it so that it doesn't do CR->CRLF conversion? I don't know if any way to specifically remove the :crlf layer, but if there was one, that might be a better solution. A simple solution that would resolve my problem would be to not call CORE::binmode on any of the file handles if they have any non-default layers (that is, layers other than :crlf, :unix, and :perlio).
Download (untitled) / with headers
text/plain 240b
This issue has been copied to: https://github.com/leejo/CGI.pm/issues/74 please take all future correspondence there. This ticket will remain open but please do not reply here. This ticket will be closed when the github issue is dealt with.
Download (untitled) / with headers
text/plain 692b
commit 7a88db1905cd243e388e3fe0407feeb0a55438e7 Author: Lee Johnson <lee@givengain.ch> Date: Sat Sep 20 13:45:30 2014 +0100 resolve #74 [rt.cpan.org #57524] - check FH layers before we set binmode on STDOUT/STDERR/STDIN check the layers that exist on them and if there are any none defaults then *don't* set binmode as that will wipe out the existing modes. add test for this which means we need to wrap the setting in a subroutine so can test it outside the OS's affected since the alternative is faffing about with $^O lib/CGI.pm | 29 +++++++++++++++++++++++++---- t/rt-57524.t | 19 +++++++++++++++++++ 2 files changed, 44 insertions(+), 4 deletions(-)


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.