Skip Menu |

This queue is for tickets about the Test-WWW-Mechanize-Catalyst CPAN distribution.

Report information
The Basics
Id: 29143
Status: resolved
Priority: 0/
Queue: Test-WWW-Mechanize-Catalyst

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

Bug Information
Severity: Important
Broken in: 0.40
Fixed in: (no value)



[Patch attached] There's a subtle problem in Test::WWW::Mechanize::Catalyst 0.40, which unfortunately makes it die in some circumstances. When HTTP::Response (really HTTP::Headers) has multiple values for the Content-Type header, the $response->header('Content-Type') method returns its values concatenated with a "," (comma) when evaluated in string context. Thus the following regex in Test::WWW::Mechanize::Catalyst (line 86): $response->header('Content-Type') =~ m/charset=(\S+)/xms captures also an extra comma, making the subsequent statement: $response->content( Encode::decode( $1, $response->content ) ); die with something like: Unknown encoding 'utf-8,' To solve that I suggest to simply use the following regex: $response->header('Content-Type') =~ m/charset=([^\s,]+)/xms which should work in any possible situation, since there are no charset aliases with a comma (according to the IANA Character Sets registry). (The attached patch uses this solution). Cheers, Emanuele Zeppieri.
Subject: twmc_040_comma_patch
Download twmc_040_comma_patch
application/octet-stream 500b

Message body not shown because it is not plain text.

Failing test attached (multi_content-type.t). The test is quite tricky since (I forgot to mention,) the bug under discussion is triggered only when Test::WWW::Mechanize::Catalyst connects to an external Catalyst server (i.e. $ENV{CATALYST_SERVER} is set to the server URL). By the way the test script has been accurately tested on various platforms (Linux debian, Win XP/Vista and even Cygwin). *This test requires Test::Exception* Cheers, Emanuele Zeppieri.
#!perl #------------------------------ # Emanuele Zeppieri - Sep 2007 #------------------------------ use strict; use warnings; use lib 'lib'; our $PORT; BEGIN { $PORT = $ENV{TWMC_TEST_PORT} || 7357; $ENV{CATALYST_SERVER} = "http://localhost:$PORT" } package ExternalCatty; use Catalyst qw/-Debug -Engine=HTTP/; our $VERSION = '0.01'; __PACKAGE__->config( name => 'ExternalCatty' ); __PACKAGE__->setup; sub default : Private { my ($self, $c) = @_; $c->response->content_type('text/html; charset=utf-8'); $c->response->output( html('Root', 'Hello, test!') ) } sub html { my ($title, $body) = @_; return qq[ <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>$title</title> </head> <body>$body</body> </html> ]; } # The Cat HTTP server background option is useless here :-( # Thus we have to provide our own background method. sub background { my $self = shift; my $child = fork; die "Can't fork Cat HTTP server: $!" unless defined $child; return $child if $child; if ( $^O !~ /MSWin32/ ) { require POSIX; POSIX::setsid() or die "Can't start a new session: $!"; } $self->run($PORT) } # Back in main. package main; use Test::More tests => 5; use Test::Exception; BEGIN { diag( "###################################################################\n", "Starting an external Catalyst HTTP server on port $PORT\n", "To change the port, please set the TWMC_TEST_PORT env variable.\n", "(The server will be automatically shut-down right after the tests).\n", "###################################################################\n" ) } # Let's catch interrupts to force the END block execution. $SIG{INT} = sub { warn "INT:$$"; exit }; my $pid = ExternalCatty->background; use Test::WWW::Mechanize::Catalyst 'ExternalCatty'; my $m = Test::WWW::Mechanize::Catalyst->new; lives_ok { $m->get_ok('/', 'Get a multi Content-Type response') } 'Survive to a multi Content-Type sting'; is( $m->ct, 'text/html', 'Multi Content-Type Content-Type'); $m->title_is('Root', 'Multi Content-Type title'); $m->content_contains('Hello, test!', 'Multi Content-Type body'); END { kill 9, $pid } 1;
Thanks! This is fixed in version 0.41, which has just hit CPAN.