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

People
Owner: Nobody in particular
Requestors: jkeroes [...] gmail.com
Cc:
AdminCc:

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



Subject: start_html( -style => $css ) broken
From the docs: To incorporate a stylesheet into your document, pass the start_html() method a -style parameter. The value of this parameter may be a scalar, in which case it is incorporated directly into a <style> section, or ... Passing CSS directly to -style doesn't work anymore; that scalar ends up in <link href="...">. This broke sometime between 2.91 and 2.98, though I'm not sure where. Env: Bug present under both perl 5.6.0 or 5.8.1RC4. Currently testing on Solaris 2.7. Demonstrative code with workaround: __BEGIN__ #!/usr/bin/perl -w use strict; use CGI::Pretty qw/:standard/; my $css = <<END; <!--/* <![CDATA[ */ BODY {background-color: blue; } /* ]]> */--> END # Broken; used to work: print header, start_html( -style => $css ), "Testing", end_html; # Workaround: # Note that CGI will add the CDATA wrapper for us; # it's not needed above. #print header, start_html( -style => { -code => $css } ), "Testing", end_html; <link rel="stylesheet" type="text/css" href="BODY {background-color: blue; }" /> __END__ Here's the bug output - note the warning: sandbox: ~/public_html/cgi-bin $ /opt/perl581/bin/perl css_bug.cgi Use of uninitialized value in concatenation (.) or string at (eval 13) line 37. Content-Type: text/html; charset=ISO-8859-1 <?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US"><head><title>Untitled Document</title> <link rel="stylesheet" type="text/css" href=" <!--/* <![CDATA[ */ BODY {background-color: blue; } /* ]]> */--> " /> </head><body> Testing</body></html>
I believe this was fixed in 2.99 and in 3.00 [JOSHUA - Thu Aug 14 15:07:15 2003]: Show quoted text
> > From the docs: > > To incorporate a stylesheet into your document, pass the > start_html() > method a -style parameter. The value of this parameter may be a > scalar, in which case it is incorporated directly into a <style> > section, or ... > > Passing CSS directly to -style doesn't work anymore; that scalar ends > up in <link href="...">. > > This broke sometime between 2.91 and 2.98, though I'm not sure where. > > Env: > Bug present under both perl 5.6.0 or 5.8.1RC4. > Currently testing on Solaris 2.7. > > Demonstrative code with workaround: > > __BEGIN__ > #!/usr/bin/perl -w > > use strict; > use CGI::Pretty qw/:standard/; > > my $css = <<END; > <!--/* <![CDATA[ */ > BODY {background-color: blue; } > /* ]]> */--> > END > > # Broken; used to work: > print header, start_html( -style => $css ), "Testing", end_html; > > # Workaround: > # Note that CGI will add the CDATA wrapper for us; > # it's not needed above. > #print header, start_html( -style => { -code => $css } ), "Testing", > end_html; > > <link rel="stylesheet" type="text/css" href="BODY {background-color: > blue; }" /> > > __END__ > > Here's the bug output - note the warning: > > sandbox: ~/public_html/cgi-bin $ /opt/perl581/bin/perl css_bug.cgi > Use of uninitialized value in concatenation (.) or string at (eval
13) Show quoted text
> line 37. > Content-Type: text/html; charset=ISO-8859-1 > > <?xml version="1.0" encoding="iso-8859-1"?> > <!DOCTYPE html > PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> > <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en- > US"><head><title>Untitled Document</title> > <link rel="stylesheet" type="text/css" href=" <!--/* <![CDATA[ */ > BODY {background-color: blue; } > /* ]]> */--> > " /> > </head><body> > Testing</body></html>
[LDS - Mon Aug 18 13:58:25 2003]: Show quoted text
> I believe this was fixed in 2.99 and in 3.00
Bug still present. Included is a patch that adds test file t/start_html.t and patches CGI.pm so that it behaves as documented with start_html( -style => $css )'s old behaviour. Where was this bug introduced? I tested start_html.t with versions 2.91 - 3.00. Here are the results: 2.91 ok 2.92 ok 2.93 ok 2.94 ok 2.95 not ok t/start_html....CGI::_style: In string, @other now must be written as \@other at t/start_html.t line 7 # Looks like your test died before it could output anything. t/start_html....dubious Test returned status 255 (wstat 65280, 0xff00) DIED. FAILED tests 1-3 2.96 not ok (as above) 2.97 not ok bug introduced t/start_html....Use of uninitialized value in concatenation (.) at (eval 6) line 37. t/start_html....NOK 1# Failed test (t/start_html.t at line 7) # '<?xml version="1.0" encoding="iso-8859-1"?> # <!DOCTYPE html # PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" # "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> # <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US"><head><title>Untitled Document</title> # <link rel="stylesheet" type="text/css" href="BODY { background-color: blue; }" /> # </head><body>' # doesn't match '(?-xism:<style type="text/css">\s?<!--/\* <!\[CDATA\[ \*/\s?BODY { background-color: blue ; })' t/start_html....ok 3/3# Looks like you failed 1 tests of 3. t/start_html....dubious Test returned status 1 (wstat 256, 0x100) DIED. FAILED test 1 Failed 1/3 tests, 66.67% okay 2.98 not ok (as above) 2.99 not ok (as above) 3.00 not ok (as above) --- So it looks like there are two bugs, the first introduced in 2.94 (and mentioned in the Changelog), and this one; introduced in 2.97. As promised, here's a patch. This is also available at http://keroes.com/perl/CGI.pm-3.00_01.patch . __BEGIN__ diff -Pru CGI.pm-3.00/CGI.pm CGI.pm-3.00_01/CGI.pm --- CGI.pm-3.00/CGI.pm Mon Aug 18 10:44:24 2003 +++ CGI.pm-3.00_01/CGI.pm Mon Aug 18 11:51:36 2003 @@ -19,7 +19,7 @@ # http://stein.cshl.org/WWW/software/CGI/ $CGI::revision = '$Id: CGI.pm,v 1.130 2003/08/01 14:39:17 lstein Exp $ + patches by merlyn'; -$CGI::VERSION='3.00'; +$CGI::VERSION='3.00_01'; # HARD-CODED LOCATION FOR FILE UPLOAD TEMPORARY FILES. # UNCOMMENT THIS ONLY IF YOU KNOW WHAT YOU'RE DOING. @@ -1532,12 +1532,11 @@ } if ($verbatim) { push(@result, "<style type=\"text/css\">\n$verbatim\n</style>"); - } + } push(@result,style({'type'=>$type},"$cdata_start\n$code\n$cdata_end")) if $code; } else { my $src = $style; - push(@result,$XHTML ? qq(<link rel="stylesheet" type="$type" href="$src" $other/>) - : qq(<link rel="stylesheet" type="$type" href="$src"$other>)); + push(@result, "<style type=\"text/css\">\n$src\n</style>"); } @result; } diff -Pru CGI.pm-3.00/MANIFEST CGI.pm-3.00_01/MANIFEST --- CGI.pm-3.00/MANIFEST Mon Apr 14 11:26:11 2003 +++ CGI.pm-3.00_01/MANIFEST Mon Aug 18 11:54:44 2003 @@ -51,3 +51,4 @@ t/switch.t t/util.t t/util-58.t +t/start_html.t diff -Pru CGI.pm-3.00/t/start_html.t CGI.pm-3.00_01/t/start_html.t --- CGI.pm-3.00/t/start_html.t Wed Dec 31 16:00:00 1969 +++ CGI.pm-3.00_01/t/start_html.t Mon Aug 18 12:09:37 2003 @@ -0,0 +1,17 @@ +use Test::More tests => 3; + +use CGI qw/start_html/; + +$css = 'BODY { background-color: blue; }'; + +like start_html( -style => $css ), + qr|<style type="text/css">\s?<!--/\* <!\[CDATA\[ \*/\s?BODY { background-color: blue; }|, + 'start_html( -style => $css )'; + +like start_html( -style => { -verbatim => $css } ), + qr|<style type="text/css">\s?BODY { background-color: blue; }|, + 'start_html( -style => { -code => $css } )'; + +like start_html( -style => { -code => $css } ), + qr|<style type="text/css">\s?<!--/\* <!\[CDATA\[ \*/\s?BODY { background-color: blue; }|, + 'start_html( -style => { -code => $css } )';
Documentation error. The scalar form of -style takes an href for the stylesheet. Use the -verbatim argument to incorporate the stylesheet text directly into the header.