Skip to content

Commit

Permalink
Item13378: unicode
Browse files Browse the repository at this point in the history
  • Loading branch information
Comment committed May 17, 2015
1 parent 88f0185 commit c383f64
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
28 changes: 15 additions & 13 deletions lib/Foswiki/Contrib/JsonRpcContrib/Request.pm
Expand Up @@ -20,6 +20,7 @@ use strict;
use warnings;

use JSON ();
use Encode ();
use Foswiki::Contrib::JsonRpcContrib::Error ();
use Error qw( :try );
use Foswiki::Func ();
Expand All @@ -37,7 +38,7 @@ sub new {
# get json-rpc request object
my $data = $request->param('POSTDATA');
if ($data) {
$data = fromUtf8($data);
$data = toSiteCharSet($data);
}
else {

Expand All @@ -60,7 +61,7 @@ sub new {
# override json-rpc params using url params
foreach my $key ( $request->multi_param() ) {
next if $key =~ /^(POSTDATA|method|id|jsonrpc)$/; # these are different
my @vals = map( fromUtf8($_), $request->multi_param($key) );
my @vals = map( toSiteCharSet($_), $request->multi_param($key) );
if ( scalar(@vals) == 1 ) {
$this->param( $key => $vals[0] )
; # set json-rpc params using url params
Expand All @@ -76,7 +77,7 @@ sub new {
$this->id($id) if defined $id;

# copy method to json-rpc request
$method = $request->param("method") if defined $request->param("method");
$method = $request->param('method') if defined $request->param("method");
$this->method($method) if defined $method;

# check that this is a http POST
Expand Down Expand Up @@ -195,22 +196,23 @@ sub writeDebug {
}

###############################################################################
sub fromUtf8 {
sub toSiteCharSet {
my $string = shift;

return $string unless $string;

return $string
if ( $Foswiki::cfg{Site}{CharSet} || 'utf-8' ) =~ /^utf-?8/i;
# Convert to unicode if the core supports it
return $string if $Foswiki::UNICODE;

return $string
if $Foswiki::Plugins::VERSION >
2.1; # not required on "newer" foswikis, is it?

# SMELL: CDot doesn't understand why you would ever want to convert
# params to unicode, especially not in a pre-1.2 wiki.....
require Encode;
return Encode::decode_utf8($string);
if ( $Foswiki::cfg{Site}{CharSet} =~ /^utf-?8/i );

# If the site charset is not utf-8, need to convert it
return Encode::encode(
$Foswiki::cfg{Site}{CharSet},
Encode::decode_utf8($string),
Encode::FB_PERLQQ
);
}

1;
9 changes: 5 additions & 4 deletions lib/Foswiki/Contrib/JsonRpcContrib/Server.pm
Expand Up @@ -92,7 +92,8 @@ sub dispatch {

# get topic parameter and set the location overriding any
# other value derived from the namespace param
my $topic = $request->param("topic") || $Foswiki::cfg{HomeTopicName};
my $topic = $request->param('topic')
|| $Foswiki::cfg{HomeTopicName};
( $session->{webName}, $session->{topicName} ) =
Foswiki::Func::normalizeWebTopicName( $Foswiki::cfg{UsersWebName},
$topic );
Expand All @@ -113,10 +114,10 @@ sub dispatch {
}

# if there's login info, try and apply it
my $userName = $request->param("username");
my $userName = $request->param('username');
if ($userName) {
writeDebug("checking password for $userName") if TRACE;
my $pass = $request->param("password") || '';
my $pass = $request->param('password') || '';
unless ( $session->{users}->checkPassword( $userName, $pass ) ) {
Foswiki::Contrib::JsonRpcContrib::Response->print(
$session,
Expand Down Expand Up @@ -183,7 +184,7 @@ sub dispatch {
};

# finally
my $redirectto = $request->param("redirectto");
my $redirectto = $request->param('redirectto');
if ( $code == 0 && defined $redirectto ) {
my $url;
if ( $redirectto =~ /^https?:/ ) {
Expand Down

0 comments on commit c383f64

Please sign in to comment.