[Jifty-commit] r1950 - jifty/trunk/lib/Jifty
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Sun Sep 10 23:51:45 EDT 2006
Author: nelhage
Date: Sun Sep 10 23:51:44 2006
New Revision: 1950
Modified:
jifty/trunk/lib/Jifty/I18N.pm
jifty/trunk/lib/Jifty/LetMe.pm
Log:
Properly UTF-safeing Jifty::LetMe
Modified: jifty/trunk/lib/Jifty/I18N.pm
==============================================================================
--- jifty/trunk/lib/Jifty/I18N.pm (original)
+++ jifty/trunk/lib/Jifty/I18N.pm Sun Sep 10 23:51:44 2006
@@ -127,7 +127,27 @@
}
return $string;
+}
+
+=head2 maybe_decode_utf8 STRING
+
+Attempt to decode STRING as UTF-8. If STRING is not valid UTF-8, or
+already contains wide characters, return it undecoded.
+N.B: In an ideal world, we wouldn't need this function, since we would
+know whether any given piece of input is UTF-8. However, the world is
+not ideal.
+
+=cut
+
+sub maybe_decode_utf8 {
+ my $class = shift;
+ my $string = shift;
+ eval {
+ $string = Encode::decode_utf8($string);
+ };
+ Carp::carp "Couldn't decode UTF-8: $@" if $@;
+ return $string;
}
1;
Modified: jifty/trunk/lib/Jifty/LetMe.pm
==============================================================================
--- jifty/trunk/lib/Jifty/LetMe.pm (original)
+++ jifty/trunk/lib/Jifty/LetMe.pm Sun Sep 10 23:51:44 2006
@@ -96,7 +96,7 @@
$digest->add( $user->auth_token );
$digest->add( $self->path );
my %args = %{$self->args};
- $digest->add( $_, $args{$_}) for sort keys %args;
+ $digest->add( Encode::encode_utf8($_), Encode::encode_utf8($args{$_})) for sort keys %args;
$digest->add( $self->until ) if ($self->until);
return $digest->hexdigest();
}
@@ -164,7 +164,7 @@
token => 'update_task/23'
until => 20050101,
checksum_provided => bekidrikufryvagygefuba
-
+
=cut
sub from_token {
@@ -173,11 +173,11 @@
my @atoms = split('/',$token);
- $self->email( URI::Escape::uri_unescape( shift @atoms ) );
+ $self->email( Jifty::I18N->maybe_decode_utf8(URI::Escape::uri_unescape( shift @atoms )) );
$self->path( shift @atoms );
$self->checksum_provided( pop @atoms );
- my %args = map {URI::Escape::uri_unescape($_)} @atoms;
+ my %args = map { Jifty::I18N->maybe_decode_utf8(URI::Escape::uri_unescape($_)) } @atoms;
$self->until( delete $args{until} ) if $args{until};
$self->args(\%args);
More information about the Jifty-commit
mailing list