Skip to content

Commit

Permalink
resolve #84 [rt.cpan.org #67100] - document default charset
Browse files Browse the repository at this point in the history
being nonsensical in some situations and the workaround being to pass
in -charset => '' in those cases. this is the path of least disruption
as there is currently no way to tell if the default charset is one
set by the user or the module, and the alternative of checking the
content type against the charset is a no go IMO
  • Loading branch information
leejo committed Oct 17, 2014
1 parent 2f800ac commit 37ad1ed
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
7 changes: 7 additions & 0 deletions Changes
@@ -1,3 +1,10 @@
4.08 2014-11-01

[ DOCUMENTATION ]
- note that calling headers without a -charset may lead to a nonsensical
charset being added to certain content types due to the default and the
workaround

4.07 2014-10-12

[ RELEASE NOTES ]
Expand Down
8 changes: 7 additions & 1 deletion lib/CGI.pm
Expand Up @@ -5238,7 +5238,13 @@ to use with certain servers that expect all their scripts to be NPH.
The B<-charset> parameter can be used to control the character set
sent to the browser. If not provided, defaults to ISO-8859-1. As a
side effect, this sets the charset() method as well.
side effect, this sets the charset() method as well. B<Note> that the
default being ISO-8859-1 may not make sense for all content types, e.g.:
Content-Type: image/gif; charset=ISO-8859-1
In the above case you need to pass -charset => '' to prevent the default
being used.
The B<-attachment> parameter can be used to turn the page into an
attachment. Instead of displaying the page, some browsers will prompt
Expand Down
30 changes: 30 additions & 0 deletions t/headers/type.t
Expand Up @@ -68,4 +68,34 @@ use Test::More;
is $got, $expected, 'type and charset, type defines charset';
}

{
my $cgi = CGI->new;
my $got = $cgi->header( -type => 'image/gif' );
my $expected = 'Content-Type: image/gif; charset=ISO-8859-1'
. $CGI::CRLF x 2;
is $got, $expected, 'image type, no charset';
}

{
my $cgi = CGI->new;
my $got = $cgi->header(
-type => 'image/gif',
-charset => '',
);
my $expected = 'Content-Type: image/gif'
. $CGI::CRLF x 2;
is $got, $expected, 'image type, no charset';
}

{
my $cgi = CGI->new;
my $got = $cgi->header(
-type => 'image/gif',
-charset => 'utf-8',
);
my $expected = 'Content-Type: image/gif; charset=utf-8'
. $CGI::CRLF x 2;
is $got, $expected, 'image type, forced charset';
}

done_testing;

0 comments on commit 37ad1ed

Please sign in to comment.