2
# Test that header generation is spec compliant.
4
# http://www.w3.org/Protocols/rfc2616/rfc2616.html
5
# http://www.w3.org/Protocols/rfc822/3_Lexical.html
10
use Test::More 'no_plan';
16
like $cgi->header( -type => "text/html" ),
17
qr#Type: text/html#, 'known header, basic case: type => "text/html"';
19
eval { $cgi->header( -type => "text/html".$CGI::CRLF."evil: stuff" ) };
20
like($@,qr/contains a newline/,'invalid header blows up');
22
like $cgi->header( -type => "text/html".$CGI::CRLF." evil: stuff " ),
23
qr#Content-Type: text/html evil: stuff#, 'known header, with leading and trailing whitespace on the continuation line';
25
eval { $cgi->header( -foobar => "text/html".$CGI::CRLF."evil: stuff" ) };
26
like($@,qr/contains a newline/,'unknown header with CRLF embedded blows up');
28
eval { $cgi->header( -foobar => $CGI::CRLF."Content-type: evil/header" ) };
29
like($@,qr/contains a newline/, 'unknown header with leading newlines blows up');
31
eval { $cgi->redirect( -type => "text/html".$CGI::CRLF."evil: stuff" ) };
32
like($@,qr/contains a newline/,'redirect with known header with CRLF embedded blows up');
34
eval { $cgi->redirect( -foobar => "text/html".$CGI::CRLF."evil: stuff" ) };
35
like($@,qr/contains a newline/,'redirect with unknown header with CRLF embedded blows up');
37
eval { $cgi->redirect( $CGI::CRLF.$CGI::CRLF."Content-Type: text/html") };
38
like($@,qr/contains a newline/,'redirect with leading newlines blows up');
41
my $cgi = CGI->new('t=bogus%0A%0A<html>');
43
eval { $out = $cgi->redirect( $cgi->param('t') ) };
44
like($@,qr/contains a newline/, "redirect does not allow double-newline injection");