diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Run.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Run.pm index a0ff1784e..050a233fe 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Run.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Run.pm @@ -14,6 +14,7 @@ our $VERSION = '2.0.0'; package Lemonldap::NG::Portal::Main; use strict; +use URI::Escape; # List constants sub authProcess { qw(extractFormInfo getUser authenticate) } @@ -39,7 +40,7 @@ sub handler { # Restore pdata if ( my $v = $req->cookies->{ $self->conf->{cookieName} . 'pdata' } ) { $sp = 1; - eval { $req->pdata( JSON::from_json($v) ); }; + eval { $req->pdata( JSON::from_json( uri_unescape($v) ) ); }; if ($@) { $self->logger->error("Bad JSON content in cookie pdata"); $req->pdata( {} ); @@ -53,7 +54,7 @@ sub handler { name => $self->conf->{cookieName} . 'pdata', ( %{ $req->pdata } - ? ( value => JSON::to_json( $req->pdata ) ) + ? ( value => uri_escape( JSON::to_json( $req->pdata ) ) ) : ( value => '', expires => 'Wed, 21 Oct 2015 00:00:00 GMT' ) ) ); diff --git a/lemonldap-ng-portal/t/01-pdata.t b/lemonldap-ng-portal/t/01-pdata.t index 581146dd5..31bab9dba 100644 --- a/lemonldap-ng-portal/t/01-pdata.t +++ b/lemonldap-ng-portal/t/01-pdata.t @@ -1,6 +1,7 @@ use Test::More; use strict; use IO::String; +use URI::Escape; require 't/test-lib.pm'; @@ -19,15 +20,15 @@ my $client = LLNG::Manager::Test->new( # Two simple access to see if pdata is set and restored ok( $res = $client->_get( '/', ), 'Simple access' ); $tmp = expectCookie( $res, 'lemonldappdata' ); -ok( $tmp eq '{"mytest":1}', 'Pdata is {"mytest":1}' ) - or explain( $tmp, '{"mytest":1}' ); +ok( $tmp eq uri_escape('{"mytest":1}'), 'Pdata is {"mytest":1}' ) + or explain( $tmp, uri_escape('{"mytest":1}') ); count(2); -ok( $res = $client->_get( '/', cookie => 'lemonldappdata={"mytest":1}', ), +ok( $res = $client->_get( '/', cookie => 'lemonldappdata=' . $tmp, ), 'Second simple access' ); $tmp = expectCookie( $res, 'lemonldappdata' ); -ok( $tmp eq '{"mytest":2}', 'Pdata is {"mytest":2}' ) - or explain( $tmp, '{"mytest":1}' ); +ok( $tmp eq uri_escape('{"mytest":2}'), 'Pdata is {"mytest":2}' ) + or explain( $tmp, uri_escape('{"mytest":2}') ); count(2); # Try to authenticate