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: 12401
Status: resolved
Priority: 0/
Queue: CGI

People
Owner: MARKSTOS [...] cpan.org
Requestors: jkeenan [...] cpan.org
Cc:
AdminCc:

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



Subject: CGI::Pretty Mishandles local $"='';
Perl: 5.8.4 CGI.pm: 3.04 CGI:Pretty: 1.08 OS: Mac OS X 10.3.8 Browsers tried: Safari; Mozilla I am experiencing problems with CGI::Pretty's handling of Perl's special variable $". According to the module's documentation (echoed in chapter 5 of CGI Programming with Perl, 2nd ed.) substituting CGI::Pretty for CGI should have no effect on output; it should merely make the HTML source more readable. But I have found a case where using CGI::Pretty actually deletes characters intended to be output. That case centers around localized use of $" for the purpose of eliminating whitespace between elements of a list. Consider the following two scripts: ##### mycgi.cgi #!/usr/local/bin/perl -wT use strict; use CGI; my $q = new CGI; print $q->header( -type => "text/html" ); print $q->start_html(-title => "The Time"); print $q->p( "The server name is:", $q->server_name ); { local $" = ''; print $q->p( "Server=", $q->server_name ); } print $q->end_html; ##### mycgipretty.cgi #!/usr/local/bin/perl -wT use strict; use CGI::Pretty qw(:html3); my $q = new CGI::Pretty; print $q->header( -type => "text/html" ); print $q->start_html(-title => "The Time"); print $q->p( "The server name is:", $q->server_name ); { local $" = ''; print $q->p( "Server=", $q->server_name ); } print $q->end_html; 1. When I run the first script from the command line, I get: The server name is: localhost in the first case and Server=localhost in the second. This DWIMs. 2. But when I run the second script from the command line, I get the same result in the first case, but in the second I get: Server=localhos The final 't' is chopped off! When I run these two scripts through the browsers on my Mac, I get: The server name is: macintosh.local Server=macintosh.local as expected in the first case, but this in the second: The server name is: macintosh.local Server=macintosh.loca In this case, it's the final 'l' that is chopped off. I have discussed this case with the module's author and have submitted a patch represented by the following diff. The patch passes some tests that I have written, but I don't pretend to have thoroughly tested it. 13c13 < $CGI::Pretty::VERSION = '1.08'; --- Show quoted text
> $CGI::Pretty::VERSION = '1.0803';
108c108 < chop \$args[0]; --- Show quoted text
> chop \$args[0] unless \$" eq "";
130,131c130,134 < local \$" = "" if \$CGI::Pretty::LINEBREAK || \$CGI::Pretty::INDENT; < return "\@result"; --- Show quoted text
> if (\$CGI::Pretty::LINEBREAK || \$CGI::Pretty::INDENT) { > return join ("", \@result); > } else { > return "\@result"; > }
Jim Keenan
Jim, Thanks for the report. I've confirmed the bug still exists with the 3.43 release. I also appreciate the patch. Hopefully it can get integrated and released soon. Mark n Sun Apr 24 20:12:00 2005, guest wrote: Show quoted text
> Perl: 5.8.4 > CGI.pm: 3.04 > CGI:Pretty: 1.08 > OS: Mac OS X 10.3.8 > Browsers tried: Safari; Mozilla > > I am experiencing problems with CGI::Pretty's handling of Perl's > special variable $". According to the module's documentation > (echoed in chapter 5 of CGI Programming with Perl, 2nd ed.) > substituting CGI::Pretty for CGI should have no effect on output; > it should merely make the HTML source more readable. > > But I have found a case where using CGI::Pretty actually deletes > characters intended to be output. That case centers around > localized use of $" for the purpose of eliminating whitespace > between elements of a list. Consider the following two scripts: > > ##### mycgi.cgi > #!/usr/local/bin/perl -wT > use strict; > use CGI; > my $q = new CGI; > print $q->header( -type => "text/html" ); > print $q->start_html(-title => "The Time"); > print $q->p( "The server name is:", $q->server_name ); > { > local $" = ''; > print $q->p( "Server=", $q->server_name ); > } > print $q->end_html; > > ##### mycgipretty.cgi > #!/usr/local/bin/perl -wT > use strict; > use CGI::Pretty qw(:html3); > my $q = new CGI::Pretty; > print $q->header( -type => "text/html" ); > print $q->start_html(-title => "The Time"); > print $q->p( "The server name is:", $q->server_name ); > { > local $" = ''; > print $q->p( "Server=", $q->server_name ); > } > print $q->end_html; > > 1. When I run the first script from the command line, I get: > > The server name is: localhost > > in the first case and > > Server=localhost > > in the second. This DWIMs. > > 2. But when I run the second script from the command line, I get the > same result in the first case, but in the second I get: > > Server=localhos > > The final 't' is chopped off! > > When I run these two scripts through the browsers on my Mac, I get: > > The server name is: macintosh.local > > Server=macintosh.local > > as expected in the first case, but this in the second: > > The server name is: macintosh.local > > Server=macintosh.loca > > In this case, it's the final 'l' that is chopped off. > > I have discussed this case with the module's author and have submitted > a patch represented by the following diff. The patch passes some > tests > that I have written, but I don't pretend to have thoroughly tested it. > > 13c13 > < $CGI::Pretty::VERSION = '1.08'; > ---
> > $CGI::Pretty::VERSION = '1.0803';
> 108c108 > < chop \$args[0]; > ---
> > chop \$args[0] unless \$" eq "";
> 130,131c130,134 > < local \$" = "" if \$CGI::Pretty::LINEBREAK || > \$CGI::Pretty::INDENT; > < return "\@result"; > ---
> > if (\$CGI::Pretty::LINEBREAK || \$CGI::Pretty::INDENT) { > > return join ("", \@result); > > } else { > > return "\@result"; > > }
> > Jim Keenan
Thanks, this patch has been applied in my git repo now.
Subject: released, thanks.
I believe this change was released today as part of CGI.pm 3.45. Thanks for the contribution.