Skip to content
Permalink
Browse files

Item13378: unicode

  • Loading branch information
Comment
Comment committed May 17, 2015
1 parent 88f0185 commit c383f648a22c88d17ed2ad524b4af5d7aa7a7ab7
Showing with 20 additions and 17 deletions.
  1. +15 −13 lib/Foswiki/Contrib/JsonRpcContrib/Request.pm
  2. +5 −4 lib/Foswiki/Contrib/JsonRpcContrib/Server.pm
@@ -20,6 +20,7 @@ use strict;
use warnings;

use JSON ();
use Encode ();
use Foswiki::Contrib::JsonRpcContrib::Error ();
use Error qw( :try );
use Foswiki::Func ();
@@ -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 {

@@ -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
@@ -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
@@ -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;
@@ -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 );
@@ -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,
@@ -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?:/ ) {

0 comments on commit c383f64

Please sign in to comment.
You can’t perform that action at this time.