view release on metacpan or search on metacpan
- Backcompat fix for people that made the mistake of doing $c->{stash}
- Sort controllers in setup_actions so cross-controller precedence is
consistent.
5.90112 - 2016-07-25
- Spelling fixes from Debian group.
- Fixed regression introduced in last release that caused the code to crap out
if you set the encoding to 'undef'.
5.90111 - 2016-07-20
- Improved documentation around some of the unicode changes; tests (melmothx++)
5.90110 - 2016-07-20
- Better catching of HTTP style exceptions so that you can reliable use one to
override many core method.
- Documention on better ways to catch and handle Unicode errors
- We now check the unicode in your URL request queries and raise an error if the
check fails. This was done to be consistent with what we do in other parts of
the code (such as in args, or POSTed parameters). If this breaks your code in
ways you don't want to fix, you may disable this using the global configuration
setting, "do_not_check_query_encoding".
- Removed configuration setting, "decode_query_using_global_encoding" since it no
longer does anything useful. Query decoding follows from whatever you set the
global encoding to, unless you specify an alternative or to not decode.
5.90106 - 2016-07-05
- Fixed regression in debug screen rendering of the private names in chained
5.90084 - 2015-02-23
- Small change to the way body parameters are created in order to prevent
trying to create parameters twice.
- Use new HTTP::Body and code updates to fix issue when POSTed params have
non UTF-8 charset encodings or otherwise complex upload parts that are not
file uploads. In these cases when Catalyst can't determine what the value of
a form upload is, will return an instance of Catalyst::Request::PartData with
all the information need to figure it out. Documentation about this corner
case. For RT https://rt.cpan.org/Ticket/Display.html?id=101556
- Two new application configuration parameters 'skip_body_param_unicode_decoding'
and 'skip_complex_post_part_handling' to assist you with any backward
compatibility issues with all the new UTF8 work in the most recent stable
Catalyst. You may use these settings to TEMPORARILY disable certain new
features while you are seeking a long term fix.
5.90083 - 2015-02-16
- Fixed typo in support for OPTIONS method matching (andre++)
- Stop using $env->{'plack.request.query'} as a query parsing optimization
since 1) it doesn't belong to us and 2) there's subtle differences in the
way plack parses parameters and catalyst does. This fixes a bug when you
case t/data_handler.t
5.90049_001 - 2013-07-26
- Declare PSGI compliant Middleware as part of your Catalyst Application via
a new configuration key, "psgi_middleware".
- Increased lowest allowed module version for Module::Pluggable to be 4.7 (up
from 3.4) to solve the fact this is no longer bundled with Perl in v5.18.
5.90042 - 2013-06-14
- Removed more places where an optional dependency shows up in the test
suite. Hopefully really fixed the unicode regression introduced in 5.90040
- reverted the change we introduced in 5.90040 where a unicode conversion
error warned instead of died. Now it dies again, like in the stand alone
plugin
- More work to make sure nothing happens with encoding unless you explicitly
ask for encoding
- Code to hopefully fix an issue where file uploads using the unicode plugin
caused trouble.
5.90041 - 2013-06-14
- Bug fix release to fix regressions introduced in previous. I would consider
this a likely upgrade and if you are having trouble with the previous I hope
this fixes all of them.
- Fix regression with the cored Unicode plugin that broke systems where you are
setting encoding type in an external configuration file
- Fixed circular dependency introduced when we cored the unicode plugin tests
- Fixed a longstanding problem with stats when locale uses , instead of . for
number decimals
- Fixed some docs that didn't properly date the previous release.
5.90040 - 2013-06-12
! Stricter checking of attributes in Catalyst::DispatchType::Chained:
1) Only allow one of either :CaptureArgs or :Args
2) :CaptureArgs() argument must be numeric
3) :CaptureArgs() and :Args() arguments cannot be negative
- Add Devel::InnerPackage to dependencies, fixing tests on Perl 5.17.11
as it's been removed from core. RT#84787
- New support for closing over the PSGI $writer object, useful for working
with event loops.
- lets you access a psgix.io socket, if your server supports it, for manual
handling of the client - server communication, such as for websockets.
- Fix waiting for the server to start in t/author/http-server.t
- new config flag 'abort_chain_on_error_fix' that exits immediately when a
action in an action chain throws and error (fixes issues where currently
the remaining actions are processed and the error is handled at chain
termination).
- Cored the Encoding plugin. Now get unicode out of the box by just setting
$c->config->{encoding} = 'UTF-8'. BACKCOMPAT WARNING: If you are using
the Encoding plugin on CPAN, we skip it to avoid double encoding issues, so
you should remove it from your plugin list, HOWEVER the 'encoding' config
setting is now undef, rather than 'UTF-8' (this was done to avoid breaking
people's existing applications) so you should add the encoding setting to
you global config. There's some other changes between the stand alone
plugin and the cored version, if you use it be sure to see Catalyst::Upgrading
for more.
- minor documentation typo fixes and updates
is called with the $ctx and \@captures and is expected to return
true to continue the chain matching and false to stop matching.
This can be used to implement action classes or roles which match
conditionally (for example only matching captures which are integers).
Bug fixes:
- Lighttpd script name fix is only applied for lighttpd versions
< 1.4.23. This should fix non-root installs of lighttpd in versions
over that.
- Prepare_action is now inside a try {} block, so that requests containing
bad unicode can be appropriately trapped by
Catalyst::Plugin::Unicode::Encoding
5.90006 - 2011-10-25 09:18:00
New features:
- A new 'run_options' class data method has been added to Catalyst.pm
This is used to store all the options passed by scripts, allowing
application authors to add custom options to their scripts then
get them passed through to the application.
t/query_constraints.t
t/query_keywords_and_parameters.t
t/relative_root_action_for_bug.t
t/remove_redundant_body.t
t/set_allowed_method.t
t/something/Makefile.PL
t/something/script/foo/bar/for_dist
t/state.t
t/undef-params.t
t/undef_encoding_regression.t
t/unicode-exception-bug.t
t/unicode-exception-return-value.t
t/unicode_plugin_charset_utf8.t
t/unicode_plugin_config.t
t/unicode_plugin_live.t
t/unicode_plugin_no_encoding.t
t/unicode_plugin_request_decode.t
t/unit_core_methodattributes_method_metaclass_on_subclasses.t
t/unit_core_script_test.t
t/unit_stats.t
t/unit_utils_load_class.t
t/unit_utils_subdir.t
t/useless_set_headers.t
t/utf8.txt
t/utf_incoming.t
xt/author/http-server.t
xt/author/notabs.t
Makefile.PL view on Meta::CPAN
'Task::Weaken' => 0,
'Text::Balanced' => 0, # core in 5.8.x but mentioned for completeness
'MRO::Compat' => 0,
'MooseX::Getopt' => '0.48',
'String::RewritePrefix' => '0.004', # Catalyst::Utils::resolve_namespace
'Devel::InnerPackage' => 0, # No longer core in blead
'Plack' => '0.9991', # IIS6+7 fix middleware
'Plack::Middleware::ReverseProxy' => '0.04',
'Plack::Test::ExternalServer' => 0,
'Encode' => '2.49',
'LWP' => '5.837', # LWP had unicode fail in 5.8.26
'URI' => '1.65',
'URI::ws' => '0.03',
'JSON::MaybeXS' => '1.000000',
'Stream::Buffered' => 0,
'Hash::MultiValue' => 0,
'Plack::Request::Upload' => 0,
'CGI::Struct' => 0,
"Plack::Middleware::Conditional" => 0,
"Plack::Middleware::IIS6ScriptNameFix" => 0,
"Plack::Middleware::IIS7KeepAliveFix" => 0,
lib/Catalyst.pm view on Meta::CPAN
Prepares action. See L<Catalyst::Dispatcher>.
=cut
sub prepare_action {
my $c = shift;
my $ret = $c->dispatcher->prepare_action( $c, @_);
if($c->encoding) {
foreach (@{$c->req->arguments}, @{$c->req->captures}) {
$_ = $c->_handle_param_unicode_decoding($_);
}
}
return $ret;
}
=head2 $c->prepare_body
Prepares message body.
lib/Catalyst.pm view on Meta::CPAN
if( exists($c->config->{encoding}) && !defined($c->config->{encoding}) ) {
# Ok, so the user has explicitly said "I don't want encoding..."
return;
} else {
my $enc = defined($c->config->{encoding}) ?
delete $c->config->{encoding} : 'UTF-8'; # not sure why we delete it... (JNAP)
$c->encoding($enc);
}
}
=head2 handle_unicode_encoding_exception
Hook to let you customize how encoding errors are handled. By default
we just throw an exception and the default error page will pick it up.
Receives a hashref of debug information. Example of call (from the
Catalyst internals):
my $decoded_after_fail = $c->handle_unicode_encoding_exception({
param_value => $value,
error_msg => $_,
encoding_step => 'params',
});
The calling code expects to receive a decoded string or an exception.
You can override this for custom handling of unicode errors. By
default we just die. If you want a custom response here, one approach
is to throw an HTTP style exception, instead of returning a decoded
string or throwing a generic exception.
sub handle_unicode_encoding_exception {
my ($c, $params) = @_;
HTTP::Exception::BAD_REQUEST->throw(status_message=>$params->{error_msg});
}
Alternatively you can 'catch' the error, stash it and write handling code later
in your application:
sub handle_unicode_encoding_exception {
my ($c, $params) = @_;
$c->stash(BAD_UNICODE_DATA=>$params);
# return a dummy string.
return 1;
}
<B>NOTE:</b> Please keep in mind that once an error like this occurs,
the request setup is still ongoing, which means the state of C<$c> and
related context parts like the request and response may not be setup
up correctly (since we haven't finished the setup yet). If you throw
an exception the setup is aborted.
=cut
sub handle_unicode_encoding_exception {
my ( $self, $exception_ctx ) = @_;
die $exception_ctx->{error_msg};
}
# Some unicode helpers cargo culted from the old plugin. These could likely
# be neater.
sub _handle_unicode_decoding {
my ( $self, $value ) = @_;
return unless defined $value;
## I think this mess is to support the old nested
if ( ref $value eq 'ARRAY' ) {
foreach ( @$value ) {
$_ = $self->_handle_unicode_decoding($_);
}
return $value;
}
elsif ( ref $value eq 'HASH' ) {
foreach (keys %$value) {
my $encoded_key = $self->_handle_param_unicode_decoding($_);
$value->{$encoded_key} = $self->_handle_unicode_decoding($value->{$_});
# If the key was encoded we now have two (the original and current so
# delete the original.
delete $value->{$_} if $_ ne $encoded_key;
}
return $value;
}
else {
return $self->_handle_param_unicode_decoding($value);
}
}
sub _handle_param_unicode_decoding {
my ( $self, $value, $check ) = @_;
return unless defined $value; # not in love with just ignoring undefs - jnap
return $value if blessed($value); #don't decode when the value is an object.
my $enc = $self->encoding;
return $value unless $enc; # don't decode if no encoding is specified
$check ||= $self->_encode_check;
return try {
$enc->decode( $value, $check);
}
catch {
return $self->handle_unicode_encoding_exception({
param_value => $value,
error_msg => $_,
encoding_step => 'params',
});
};
}
=head2 $c->setup_log
Sets up log by instantiating a L<Catalyst::Log|Catalyst::Log> object and
lib/Catalyst.pm view on Meta::CPAN
When creating body parameters from a POST, if we run into a multipart POST
that does not contain uploads, but instead contains inlined complex data
(very uncommon) we cannot reliably convert that into field => value pairs. So
instead we create an instance of L<Catalyst::Request::PartData>. If this causes
issue for you, you can disable this by setting C<skip_complex_post_part_handling>
to true (default is false).
=item *
C<skip_body_param_unicode_decoding>
Generally we decode incoming POST params based on your declared encoding (the
default for this is to decode UTF-8). If this is causing you trouble and you
do not wish to turn all encoding support off (with the C<encoding> configuration
parameter) you may disable this step atomically by setting this configuration
parameter to true.
=item *
C<do_not_decode_query>
lib/Catalyst.pm view on Meta::CPAN
the UTF-8 decoding globally using this configuration.
This setting takes precedence over C<default_query_encoding>
=item *
C<do_not_check_query_encoding>
Catalyst versions 5.90080 - 5.90106 would decode query parts of an incoming
request but would not raise an exception when the decoding failed due to
incorrect unicode. It now does, but if this change is giving you trouble
you may disable it by setting this configuration to true.
=item *
C<default_query_encoding>
By default we decode query and keywords in your request URL using UTF-8, which
is our reading of the relevant specifications. This setting allows one to
specify a fixed value for how to decode your query. You might need this if
you are doing a lot of custom encoding of your URLs and not using UTF-8.
lib/Catalyst.pm view on Meta::CPAN
=head2 Methods
=over 4
=item encoding
Returns an instance of an C<Encode> encoding
print $c->encoding->name
=item handle_unicode_encoding_exception ($exception_context)
Method called when decoding process for a request fails.
An C<$exception_context> hashref is provided to allow you to override the
behaviour of your application when given data with incorrect encodings.
The default method throws exceptions in the case of invalid request parameters
(resulting in a 500 error), but ignores errors in upload filenames.
The keys passed in the C<$exception_context> hash are:
lib/Catalyst/Engine.pm view on Meta::CPAN
my $old_encoding;
if(my $new = $c->config->{default_query_encoding}) {
$old_encoding = $c->encoding;
$c->encoding($new);
}
my $check = $c->config->{do_not_check_query_encoding} ? undef :$c->_encode_check;
my $decoder = sub {
my $str = shift;
return $str if $do_not_decode_query;
return $c->_handle_param_unicode_decoding($str, $check);
};
my $query_string = exists $env->{QUERY_STRING}
? $env->{QUERY_STRING}
: '';
$query_string =~ s/\A[&;]+//;
my @unsplit_pairs = split /[&;]+/, $query_string;
my $p = Hash::MultiValue->new();
lib/Catalyst/Engine.pm view on Meta::CPAN
my ( $self, $c ) = @_;
my $request = $c->request;
return unless $request->_body;
my $enc = $c->encoding;
my $uploads = $request->_body->upload;
my $parameters = $request->parameters;
foreach my $name (keys %$uploads) {
my $files = $uploads->{$name};
$name = $c->_handle_unicode_decoding($name) if $enc;
my @uploads;
for my $upload (ref $files eq 'ARRAY' ? @$files : ($files)) {
my $headers = HTTP::Headers->new( %{ $upload->{headers} } );
my $filename = $upload->{filename};
$filename = $c->_handle_unicode_decoding($filename) if $enc;
my $u = Catalyst::Request::Upload->new
(
size => $upload->{size},
type => scalar $headers->content_type,
charset => scalar $headers->content_type_charset,
headers => $headers,
tempname => $upload->{tempname},
filename => $filename,
);
lib/Catalyst/Request.pm view on Meta::CPAN
return $return;
}
my $params;
my %part_data = %{$self->_body->part_data};
if(scalar %part_data && !$c->config->{skip_complex_post_part_handling}) {
foreach my $key (keys %part_data) {
my $proto_value = $part_data{$key};
my ($val, @extra) = (ref($proto_value)||'') eq 'ARRAY' ? @$proto_value : ($proto_value);
$key = $c->_handle_param_unicode_decoding($key)
if ($c and $c->encoding and !$c->config->{skip_body_param_unicode_decoding});
if(@extra) {
$params->{$key} = [map { Catalyst::Request::PartData->build_from_part_data($c, $_) } ($val,@extra)];
} else {
$params->{$key} = Catalyst::Request::PartData->build_from_part_data($c, $val);
}
}
} else {
$params = $self->_body->param;
lib/Catalyst/Request.pm view on Meta::CPAN
# so, now that HTTP::Body prepared the body params, we gotta 'walk' the structure
# and do any needed decoding.
# This only does something if the encoding is set via the encoding param. Remember
# this is assuming the client is not bad and responds with what you provided. In
# general you can just use utf8 and get away with it.
#
# I need to see if $c is here since this also doubles as a builder for the object :(
if($c and $c->encoding and !$c->config->{skip_body_param_unicode_decoding}) {
$params = $c->_handle_unicode_decoding($params);
}
}
my $return = $self->_use_hash_multivalue ?
Hash::MultiValue->from_mixed($params) :
$params;
$self->body_parameters($return) unless $self->has_body_parameters;
return $return;
}
lib/Catalyst/Request/PartData.pm view on Meta::CPAN
}
my ($ct, $charset) = $hdrs->content_type_charset;
if($ct) {
# Good news, we probably have data we can return. If there is a charset
# then use that to decode otherwise use the default decoding.
if($charset) {
return Encode::decode($charset, $part_data->{data})
} else {
if($c and $c->encoding and !$c->config->{skip_body_param_unicode_decoding}) {
return $c->_handle_param_unicode_decoding($part_data->{data});
} else {
return $part_data->{data}
}
}
} else {
# I have no idea what to do with this now..
return $class->new(
raw_data => $part_data->{data},
name => $part_data->{name},
size => $part_data->{size},
headers => HTTP::Headers->new(%{ $part_data->{headers} }));
}
} else {
if($c and $c->encoding and !$c->config->{skip_body_param_unicode_decoding}) {
return $c->_handle_param_unicode_decoding($part_data->{data});
} else {
return $part_data->{data}
}
}
return $part_data->{data} unless $class->part_data_has_complex_headers($part_data);
return $class->new(
raw_data => $part_data->{data},
name => $part_data->{name},
size => $part_data->{size},
lib/Catalyst/UTF8.pod view on Meta::CPAN
}
=head2 Discussion
In the example controller above we have constructed two matchable URL routes:
http://localhost/root/â¥/{arg}
http://localhost/base/â¥/{capture}/â¥/{arg}
The first one is a classic Path type action and the second uses Chaining, and
spans three actions in total. As you can see, you can use unicode characters
in your Path and PathPart attributes (remember to use the C<utf8> pragma to allow
these multibyte characters in your source). The two constructed matchable routes
would match the following incoming URLs:
(heart_with_arg) -> http://localhost/root/%E2%99%A5/{arg}
(base/capture/arg) -> http://localhost/base/%E2%99%A5/{capture}/%E2%99%A5/{arg}
That path path C<%E2%99%A5> is url encoded unicode (assuming you are hitting this with
a reasonably modern browser). Its basically what goes over HTTP when your type a
browser location that has the unicode 'heart' in it. However we will use the unicode
symbol in your debugging messages:
[debug] Loaded Path actions:
.-------------------------------------+--------------------------------------.
| Path | Private |
+-------------------------------------+--------------------------------------+
| /root/â¥/* | /root/heart_with_arg |
'-------------------------------------+--------------------------------------'
[debug] Loaded Chained actions:
.-------------------------------------+--------------------------------------.
| Path Spec | Private |
+-------------------------------------+--------------------------------------+
| /base/â¥/*/â¥/* | /root/base (0) |
| | -> /root/capture (1) |
| | => /root/arg |
'-------------------------------------+--------------------------------------'
And if the requested URL uses unicode characters in your captures or args (such as
C<http://localhost:/base/â¥/â¥/â¥/â¥>) you should see the arguments and captures as their
unicode characters as well:
[debug] Arguments are "â¥"
[debug] "GET" request for "base/â¥/â¥/â¥/â¥" from "127.0.0.1"
.------------------------------------------------------------+-----------.
| Action | Time |
+------------------------------------------------------------+-----------+
| /root/base | 0.000080s |
| /root/capture | 0.000075s |
| /root/arg | 0.000755s |
'------------------------------------------------------------+-----------'
Again, remember that we are display the unicode character and using it to match actions
containing such multibyte characters BUT over HTTP you are getting these as URL encoded
bytes. For example if you looked at the L<PSGI> C<$env> value for C<REQUEST_URI> you
would see (for the above request)
REQUEST_URI => "/base/%E2%99%A5/%E2%99%A5/%E2%99%A5/%E2%99%A5"
So on the incoming request we decode so that we can match and display unicode characters
(after decoding the URL encoding). This makes it straightforward to use these types of
multibyte characters in your actions and see them incoming in captures and arguments. Please
keep this in might if you are doing for example regular expression matching, length determination
or other string comparisons, you will need to try these incoming variables as though UTF8
strings. For example in the following action:
sub arg :Chained('capture') PathPart('â¥') Args(1) {
my ($self, $c, $arg) = @_;
}
lib/Catalyst/UTF8.pod view on Meta::CPAN
use utf8;
my $url = $c->uri_for( $c->controller('Root')->action_for('example'), {'â¥' => 'â¥â¥'});
When you stringify this object (for use in a template, for example) it will automatically
do the right thing regarding utf8 encoding and url encoding.
http://localhost/example?%E2%99%A5=%E2%99%A5%E2%99%A5
Since again what you want is a properly url encoded version of this. Ultimately what you want
to send over the wire via HTTP needs to be bytes (not unicode characters).
Remember if you use any utf8 literals in your source code, you should use the
C<use utf8> pragma.
B<NOTE:> Assuming UTF-8 in your query parameters and keywords may be an issue if you have
legacy code where you created URL in templates manually and used an encoding other than UTF-8.
In these cases you may find versions of Catalyst after 5.90080+ will incorrectly decode. For
backwards compatibility we offer three configurations settings, here described in order of
precedence:
lib/Catalyst/UTF8.pod view on Meta::CPAN
=head2 UTF8 in Form POST
In general most modern browsers will follow the specification, which says that POSTed
form fields should be encoded in the same way that the document was served with. That means
that if you are using modern Catalyst and serving UTF8 encoded responses, a browser is
supposed to notice that and encode the form POSTs accordingly.
As a result since L<Catalyst> now serves UTF8 encoded responses by default, this means that
you can mostly rely on incoming form POSTs to be so encoded. L<Catalyst> will make this
assumption and decode accordingly (unless you explicitly turn off encoding...) If you are
running Catalyst in developer debug, then you will see the correct unicode characters in
the debug output. For example if you generate a POST request:
use Catalyst::Test 'MyApp';
use utf8;
my $res = request POST "/example/posted", ['â¥'=>'â¥', 'â¥â¥'=>'â¥'];
Running in CATALYST_DEBUG=1 mode you should see output like this:
[debug] Body Parameters are:
lib/Catalyst/UTF8.pod view on Meta::CPAN
=head2 Disabling default UTF8 encoding
You may encounter issues with your legacy code running under default UTF8 body encoding. If
so you can disable this with the following configurations setting:
MyApp->config(encoding=>undef);
Where C<MyApp> is your L<Catalyst> subclass.
If you do not wish to disable all the Catalyst encoding features, you may disable specific
features via two additional configuration options: 'skip_body_param_unicode_decoding'
and 'skip_complex_post_part_handling'. The first will skip any attempt to decode POST
parameters in the creating of body parameters and the second will skip creation of instances
of L<Catalyst::Request::PartData> in the case that the multipart form upload contains parts
with a mix of content character sets.
If you believe you have discovered a bug in UTF8 body encoding, I strongly encourage you to
report it (and not try to hack a workaround in your local code). We also recommend that you
regard such a workaround as a temporary solution. It is ideal if L<Catalyst> extension
authors can start to count on L<Catalyst> doing the right thing for encoding.
lib/Catalyst/Upgrading.pod view on Meta::CPAN
configuration option to undef:
MyApp->config(encoding => undef);
But please consider this a temporary measure since it is the intention that
UTF8 is enabled going forwards and the expectation is that other ecosystem
projects will assume this as well. At some point you application will not
correctly function without this setting.
As of 5.90084 we've added two additional configuration flags for more selective
control over some encoding changes: 'skip_body_param_unicode_decoding' and
'skip_complex_post_part_handling'. You may use these to more selectively
disable new features while you are seeking a long term fix. Please review
CONFIGURATION in L<Catalyst>.
For further information, please see L<Catalyst::UTF8>
A number of projects in the wider ecosystem required minor updates to be able
to work correctly. Here's the known list:
L<Catalyst::View::TT>, L<Catalyst::View::Mason>, L<Catalyst::View::HTML::Mason>,
t/aggregate/unit_core_uri_for.t view on Meta::CPAN
Catalyst::uri_for( $context, '/bar#fragment', { param1 => 'value1' } )->as_string,
'http://127.0.0.1/foo/bar?param1=value1#fragment',
'URI for path with fragment and query params'
);
}
# test with utf-8
is(
Catalyst::uri_for( $context, 'quux', { param1 => "\x{2620}" } )->as_string,
'http://127.0.0.1/foo/yada/quux?param1=%E2%98%A0',
'URI for undef action with query params in unicode'
);
is(
Catalyst::uri_for( $context, 'quux', { 'param:1' => "foo" } )->as_string,
'http://127.0.0.1/foo/yada/quux?param%3A1=foo',
'URI for undef action with query params in unicode'
);
# test with object
is(
Catalyst::uri_for( $context, 'quux', { param1 => $request->base } )->as_string,
'http://127.0.0.1/foo/yada/quux?param1=http%3A%2F%2F127.0.0.1%2Ffoo',
'URI for undef action with query param as object'
);
# test with empty arg
t/lib/TestApp/Controller/Engine/Request/URI.pm view on Meta::CPAN
$c->res->header( 'X-Catalyst-Param-a' => $query{ a } );
$c->forward('TestApp::View::Dump::Request');
}
sub uri_with_utf8 : Local {
my ( $self, $c ) = @_;
# change the current uri
my $uri = $c->req->uri_with( { unicode => "\x{2620}" } );
$c->res->header( 'X-Catalyst-uri-with' => "$uri" );
$c->forward('TestApp::View::Dump::Request');
}
sub uri_with_undef : Local {
my ( $self, $c ) = @_;
my $warnings = 0;
t/lib/TestAppUnicode.pm view on Meta::CPAN
__PACKAGE__->config(
'name' => 'TestAppUnicode',
$ENV{TESTAPP_ENCODING} ? ( encoding => $ENV{TESTAPP_ENCODING} ) : (),
);
__PACKAGE__->log(TestLogger->new);
__PACKAGE__->setup;
sub handle_unicode_encoding_exception {
my ( $self, $param_value, $error_msg ) = @_;
return $param_value;
}
1;
t/lib/TestAppUnicode/Controller/Root.pm view on Meta::CPAN
sub main :Path('') {
my ($self, $ctx, $charset) = @_;
my $content_type = 'text/html';
if ($ctx->stash->{charset}) {
$content_type .= ";charset=" . $ctx->stash->{charset};
}
$ctx->res->body('<h1>It works</h1>');
$ctx->res->content_type($content_type);
}
sub unicode_no_enc :Local {
my ($self, $c) = @_;
my $data = "ã»ã"; # hoge!
utf8::encode($data);
$c->response->body($data);
$c->res->content_type('text/plain');
$c->encoding(undef);
}
sub unicode :Local {
my ($self, $c) = @_;
my $data = "ã»ã"; # hoge!
$c->response->body($data); # should be decoded
$c->res->content_type('text/plain');
}
sub not_unicode :Local {
my ($self, $c) = @_;
my $data = "\x{1234}\x{5678}";
utf8::encode($data); # DO NOT WANT unicode
$c->response->body($data); # just some octets
$c->res->content_type('text/plain');
$c->encoding(undef);
}
sub latin1 :Local {
my ($self, $c) = @_;
$c->res->content_type('text/plain');
$c->response->body('LATIN SMALL LETTER E WITH ACUTE: é');
t/unicode-exception-bug.t view on Meta::CPAN
TestApp::Controller::Root->config(namespace => '');
}
{
package TestApp;
$INC{'TestApp.pm'} = __FILE__;
use Catalyst;
use TestApp::Exception;
sub handle_unicode_encoding_exception {
my ( $self, $param_value, $error_msg ) = @_;
TestApp::Exception->throw(
200, ['content-type'=>'text/plain'], ['Bad unicode data']);
}
__PACKAGE__->setup;
}
use Catalyst::Test 'TestApp';
{
my $res = request('/ok');
is ($res->status_line, "200 OK");
is ($res->content, '<h1>OK</h1>');
}
{
my $res = request('/%E2%C3%83%C6%92%C3%8');
is ($res->content, 'Bad unicode data');
}
done_testing;
#TestApp->to_app;
t/unicode-exception-return-value.t view on Meta::CPAN
}
TestApp::Controller::Root->config(namespace => '');
}
{
package TestApp;
$INC{'TestApp.pm'} = __FILE__;
use Catalyst;
sub handle_unicode_encoding_exception {
my ( $self, $param_value, $error_msg ) = @_;
# totally dummy: we return any invalid string with a fixed
# value. a more clever thing would be try to decode it from
# latin1 or latin2.
return "INVALID-UNICODE";
}
__PACKAGE__->setup;
}
t/unicode_plugin_config.t view on Meta::CPAN
BEGIN { $ENV{TESTAPP_ENCODING} = 'UTF-8' };
# setup library path
use FindBin qw($Bin);
use lib "$Bin/lib";
use Catalyst::Test 'TestAppUnicode';
{
TestAppUnicode->encoding('UTF-8');
action_ok('/unicode', 'encoding configured ok');
}
done_testing;
t/unicode_plugin_live.t view on Meta::CPAN
{
my $res = request('/');
ok($res->is_success, 'get main page');
like($res->decoded_content, qr/it works/i, 'see if it has our text');
is ($res->header('Content-Type'), 'text/html; charset=UTF-8',
'Content-Type with charset'
);
}
{
my $res = request('/unicode_no_enc');
ok($res->is_success, 'get unicode_no_enc');
my $exp = "\xE3\x81\xBB\xE3\x81\x92";
my $got = Encode::encode_utf8($res->decoded_content);
is ($res->header('Content-Type'), 'text/plain',
'Content-Type with no charset');
is($got, $exp, 'content contains hoge');
}
{
my $res = request('/unicode');
ok( $res->is_success, 'get unicode');
is ($res->header('Content-Type'), 'text/plain; charset=UTF-8',
'Content-Type with charset');
my $exp = "\xE3\x81\xBB\xE3\x81\x92";
my $got = Encode::encode_utf8($res->decoded_content);
is($got, $exp, 'content contains hoge');
}
{
my $res = request('/not_unicode');
ok($res->is_success, 'get bytes');
my $exp = "\xE1\x88\xB4\xE5\x99\xB8";
my $got = Encode::encode_utf8($res->decoded_content);
is($got, $exp, 'got 1234 5678');
}
{
my $res = request('/file');
ok($res->is_success, 'get file');
t/unicode_plugin_no_encoding.t view on Meta::CPAN
# JNAP - I am removing this test case because I think its not correct. I think
# we do not check the server encoding to determine if the parts of a request URL
# both paths and query should be decoded. I think its always safe to assume utf8
# encoded urlencoded bits. That is my reading of the spec. Please correct me if
# I am wrong
#check_parameter(GET "/?myparam=$escape_str");
check_parameter(POST '/',
Content_Type => 'form-data',
Content => [
'myparam' => [
"$Bin/unicode_plugin_no_encoding.t",
"$Bin/unicode_plugin_request_decode.t",
]
],
);
sub check_parameter {
my ( undef, $c ) = ctx_request(shift);
my $myparam = $c->req->param('myparam');
unless ( $c->request->method eq 'POST' ) {
is $c->res->output => $encode_str;
t/unicode_plugin_request_decode.t view on Meta::CPAN
my ( $res, $c ) = ctx_request(shift);
ok(!is_server_error($res->code)) or diag('Response code is: ' . $res->code);
}
check_parameter(GET "/?foo=$escape_str");
check_parameter(POST '/', ['foo' => $encode_str]);
check_parameter(POST '/',
Content_Type => 'form-data',
Content => [
'foo' => [
"$Bin/unicode_plugin_request_decode.t",
$encode_str,
]
],
);
check_argument(GET "/$escape_str");
check_capture(GET "/capture/$escape_str");
# sending non-utf8 data
my $non_utf8_data = "%C3%E6%CB%AA";
xt/author/spelling.t view on Meta::CPAN
fastcgi nginx Lighttpd IIS middlewares backend IRC IOLayer
ctx _application MyApp restarter httponly Utils stash's unescapes
actionchain dispatchtype dispatchtypes redispatch redispatching
CaptureArgs ChainedParent PathPart PathParts PathPrefix
BUILDARGS metaclass namespaces pre ARGV ReverseProxy TT UI
filename tempname request's subdirectory ini uninstalled uppercased
wiki bitmask uri url urls dir hostname proxied http https IP SSL
inline INLINE plugins cpanfile resized
FastCGI Stringifies Rethrows DispatchType Wishlist Refactor ROADMAP HTTPS Unescapes Restarter Nginx Refactored
ActionClass LocalRegex LocalRegexp MyAction metadata cometd io psgix websocket websockets proxying
UTF unicode async codebase dev encodable filenames params MyMiddleware Sendfile
JSON xml POSTs POSTed RESTful performant subref actionrole
chunked chunking codewise distingush equivilent plack Javascript gzipping
ConfigLoader getline whitepaper matchable TBD WIP
Andreas
André
Ashton
Axel
Balint
Belka
Brocard