Skip Menu |

This queue is for tickets about the ExtUtils-MakeMaker CPAN distribution.

Report information
The Basics
Id: 49043
Status: resolved
Worked: 35 min
Priority: 0/
Queue: ExtUtils-MakeMaker

People
Owner: Nobody in particular
Requestors: ddascalescu+perl [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in:
  • 6.54
  • 6.55_01
  • 6.55_02
Fixed in: 6.75_03



Subject: pompt() on Windows doesn't remove the \r
On Windows, prompt() malfunctions pretty seriously: If the user just hits Enter, the input is "\r", which will be returned. If the user types something, "\r" will be appended. http://github.com/dandv/extutils-makemaker/commit/ facc9de154130054462f46c1d364f0ecf886a07f fixes that. Would be great if this fix made it onto CPAN, as many SSL-related modules fail to build on Strawberry Perl because they prompt for the path to OpenSSL.
On Wed Aug 26 17:32:26 2009, dandv wrote: Show quoted text
> On Windows, prompt() malfunctions pretty seriously: > > If the user just hits Enter, the input is "\r", which will be returned. > > If the user types something, "\r" will be appended. > > http://github.com/dandv/extutils-makemaker/commit/ > facc9de154130054462f46c1d364f0ecf886a07f fixes that. Would be great if > this fix made it onto CPAN, as many SSL-related modules fail to build > on Strawberry Perl because they prompt for the path to OpenSSL.
Hmm. There should be no need for that patch. chomp() should handle it. This would seem to indicate either a bug in chomp() or something changed $/ or that \n is broken or that $ans is not what we think it is. What is in $ans prior to stripping? What version of Perl is this? What is $/ set to inside prompt()?
[...] Show quoted text
> chomp() should handle it. > This would seem to indicate either a bug in chomp() or something > changed $/ or that \n is broken > > What version of Perl is this?
With Strawberry Perl 5.10.0.6: c:\> perl -v This is perl, v5.10.0 built for MSWin32-x86-multi-thread chomp.pl below: << use strict; use Data::Dump 'ddx'; my $string = "foo\r\n"; ddx $string; chomp $string; ddx $string; Show quoted text
>>
prints: << c:\> perl "chomp.pl" # chomp.pl:6: "foo\r\n" # chomp.pl:9: "foo\r" Show quoted text
>>
Bug in chomp then? I don't remember ever having had this problem with chomp on Windows in 6+ years of ActivePerl. But then again, I might just not have had code that compared a chomped string with another, and trailing "\r"s on display/output tend to go unnoticed.
Subject: Re: [rt.cpan.org #49043] pompt() on Windows doesn't remove the \r
Date: Sun, 30 Aug 2009 12:16:58 -0700
To: bug-ExtUtils-MakeMaker [...] rt.cpan.org
From: Michael G Schwern <schwern [...] pobox.com>
Dan Dascalescu via RT wrote: Show quoted text
>> What version of Perl is this?
> > With Strawberry Perl 5.10.0.6: > > c:\> perl -v > > This is perl, v5.10.0 built for MSWin32-x86-multi-thread > > > chomp.pl below: > << > use strict; > use Data::Dump 'ddx'; > > my $string = "foo\r\n"; > ddx $string; > > chomp $string; > ddx $string; > > prints: > > << > c:\> perl "chomp.pl" > # chomp.pl:6: "foo\r\n" > # chomp.pl:9: "foo\r"
\n changes according to the operating system. It's \015\012 (carriage return, newline) on Windows (do an ASCII dump instead of . "foo\r\n" is effectively "\015\015\012". So chomp() is working fine. You should never have to write "\r\n", "\n" is portable. Using this instead of ddx() should confirm: print join " ", map { ord $_ } split "", $string; You should get 102 111 111 13 13 10 before the chomp and 102 111 111 13 after. A \n alone should be 13 10. Perhaps you're feeding prompt() a \r\n somehow? -- There will be snacks.
RT-Send-CC: dagolden [...] cpan.org, adamk [...] cpan.org
Show quoted text
> \n changes according to the operating system. > It's \015\012 (carriage return, newline) on Windows (do an ASCII > dump instead of . "foo\r\n" is effectively "\015\015\012".
I've been working with Perl on Windows XP since cca. 2002 and \n has always been \x0A, with ActivePerl and Strawberry. The script below outputs just "10". print join " ", map { ord $_ } split "", "\n"; Show quoted text
> Perhaps you're feeding prompt() a \r\n somehow?
prompt() does receive a "\r\n", and I just press enter. Adding a few Win32 Perl people in the loop.
21:02 Alias So question, what is "\n" on windows 21:03 Alias (stay with me here) :) 21:03 nothingmuch IIRC "that depends" 21:03 Alias uh... 21:04 Alias on what? 21:04 dipsy on what is the kudos based anyway 21:04 nothingmuch perlport/NewLlines 21:04 nothingmuch it says that it's \012 21:04 nothingmuch but that this is translated to/from \015\012 in text mode 21:04 nothingmuch (which IIRC is the default) 21:04 nothingmuch so printing \n will result in something different than what e.g. unpack("H*", "\n") will report the way I parse it 21:05 Alias How have I managed to go this long without noticing :/ 21:05 nothingmuch you probably have a good binmode() habit?
On Mon Aug 31 02:48:14 2009, dandv wrote: Show quoted text
> > \n changes according to the operating system. > > It's \015\012 (carriage return, newline) on Windows (do an ASCII > > dump instead of . "foo\r\n" is effectively "\015\015\012".
> > I've been working with Perl on Windows XP since cca. 2002 and \n has > always been \x0A, with ActivePerl and Strawberry. The script below > outputs just "10". > > print join " ", map { ord $_ } split "", "\n"; >
> > Perhaps you're feeding prompt() a \r\n somehow?
> > prompt() does receive a "\r\n", and I just press enter.
I don't know what the "real world" case is, but most likely, something is setting binmode on STDIN. Run the attached program on Strawberry to see the difference. It would probably be smart for EU::MM::prompt not to rely on chomp alone. See the attached patch for a change to from chomp to s{\015?\012$}{} -- David
#!/usr/bin/env perl use 5.010; use strict; use warnings; use ExtUtils::MakeMaker qw/prompt/; sub prompter { my $resp = prompt("Type something:"); $resp =~ s{\r}{\\r}; say "you said '$resp'"; } prompter(); binmode *STDIN; prompter();
diff --git a/lib/ExtUtils/MakeMaker.pm b/lib/ExtUtils/MakeMaker.pm index 893c0bf..5963aef 100644 --- a/lib/ExtUtils/MakeMaker.pm +++ b/lib/ExtUtils/MakeMaker.pm @@ -179,7 +179,7 @@ sub prompt ($;$) { ## no critic else { $ans = <STDIN>; if( defined $ans ) { - chomp $ans; + $ans =~ s{\015?\012$}{}; } else { # user hit ctrl-D print "\n";
Show quoted text
> I don't know what the "real world" case is, but most likely, something > is setting binmode on STDIN.
I had PERLIO set to perlio, but after unsetting that, I get the same results as before. Show quoted text
> Run the attached program on Strawberry to see the difference.
With both SET PERLIO=perlio and SET PERLIO= this is the output: C:\prg\perl\test>perl prompt-test.pl Type something: foo you said 'foo' Type something: foo you said 'foo'
Subject: Re: [rt.cpan.org #49043] pompt() on Windows doesn't remove the \r
Date: Mon, 31 Aug 2009 15:09:37 -0700
To: bug-ExtUtils-MakeMaker [...] rt.cpan.org
From: Michael G Schwern <schwern [...] pobox.com>
David Golden via RT wrote: Show quoted text
> I don't know what the "real world" case is, but most likely, something > is setting binmode on STDIN.
Looking through the likely suspects... IPC::Run appears to do that in Win32. Could that be it? Dan, does this happen on every module which uses prompt() or just some? If some, check what's in %INC. Show quoted text
> Run the attached program on Strawberry to see the difference. > > It would probably be smart for EU::MM::prompt not to rely on chomp > alone. See the attached patch for a change to from chomp to s{\015?\012$}{}
I'm not about to go around second guessing every programming mistake someone makes. If something is screwing with STDIN and chomp() is busted something else down the line will break. Rather see it fixed at the source. -- E: "Would you want to maintain a 5000 line Perl program?" d: "Why would you write a 5000 line program?"
Dan, any info?
Applied Dave's change. Patched in repository.
Stable release 6.76 is now on CPAN.