Skip to content
Browse files

Make req_param() always return utf8 safe data

  • Loading branch information...
1 parent cccbcb2 commit baa4f4a73a56b30fbaa78b84c017bdb31c848787 @abh committed Jun 29, 2011
Showing with 21 additions and 5 deletions.
  1. +0 −4 dist.ini
  2. +2 −1 lib/Combust/Request/Plack.pm
  3. +10 −0 lib/Combust/Util.pm
  4. +9 −0 t/utf8_safe.t
View
4 dist.ini
@@ -58,7 +58,3 @@ HTML::TagCloud = 0
; Combust::Control::API
Return::Value = 0
-
-
-
-
View
3 lib/Combust/Request/Plack.pm
@@ -3,6 +3,7 @@ use Moose;
use MooseX::NonMoose;
use Plack::Request;
use Combust::Request::URI;
+use Combust::Util qw(utf8_safe);
extends 'Plack::Request';
has 'response' => (
@@ -46,7 +47,7 @@ sub remote_ip {
sub req_param {
my ($self, $param) = (shift, shift);
$self->args->{$param} = shift if @_;
- return $self->parameters->{$param};
+ return utf8_safe($self->parameters->{$param});
}
sub args {
View
10 lib/Combust/Util.pm
@@ -1,11 +1,13 @@
package Combust::Util;
use warnings;
use strict;
+use utf8;
use base qw(Exporter);
use Carp qw(croak);
our @EXPORT_OK = qw(
run
+ utf8_safe
);
sub run {
@@ -27,4 +29,12 @@ sub run {
return 0;
}
+sub utf8_safe {
+ my $text = shift;
+ $text = Encode::decode("windows-1252", $text)
+ unless utf8::is_utf8($text)
+ or utf8::decode($text);
+ return $text;
+}
+
1;
View
9 t/utf8_safe.t
@@ -0,0 +1,9 @@
+use Test::More;
+use strict;
+use utf8;
+
+use_ok('Combust::Util', 'utf8_safe');
+
+is(utf8_safe("æøå – ®"), "æøå – ®", 'utf8_safe()');
+
+done_testing();

0 comments on commit baa4f4a

Please sign in to comment.
Something went wrong with that request. Please try again.