Commit ea87afe8 authored by Xavier Guimard's avatar Xavier Guimard

utf8 in progress... (#827)

parent a9881df0
......@@ -4,6 +4,7 @@ use strict;
use utf8;
use Lemonldap::NG::Common::Conf::Constants; #inherits
use JSON::MaybeXS;
use Encode;
our $VERSION = '1.4.0';
our $initDone;
......@@ -81,7 +82,8 @@ sub store {
my ( $self, $fields ) = @_;
my $mask = umask;
umask( oct('0027') );
unless ( open FILE, ">" . $self->_file( $fields->{cfgNum} ) ) {
unless ( open FILE, ">:encoding(UTF-8)", $self->_file( $fields->{cfgNum} ) )
{
$Lemonldap::NG::Common::Conf::msg .= "Open file failed: $! \n";
$self->unlock;
return UNKNOWN_ERROR;
......@@ -97,11 +99,20 @@ sub load {
my $f;
if ( -e $self->_file($cfgNum) ) {
local $/ = '';
open FILE, $self->_file($cfgNum) or die "$!$@";
my $ret;
unless ( open FILE, $self->_file($cfgNum) ) {
$Lemonldap::NG::Common::Conf::msg .= "Read error: $!$@";
return undef;
}
binmode FILE;
$f = join( '', <FILE> );
close FILE;
my $ret = eval { decode_json($f); };
die "Unable to load conf: $@\n" if ($@);
$f = encode( 'UTF-8', $f );
eval { $ret = decode_json($f) };
if ($@) {
$Lemonldap::NG::Common::Conf::msg .=
"JSON fails to read file: $@ \n";
return undef;
}
return $ret;
}
......
......@@ -99,7 +99,7 @@ sub userError {
sub sendJSONresponse {
my ( $self, $req, $j, %args ) = @_;
$args{code} ||= 200;
my $type = 'text/json';
my $type = 'application/json; charset=utf-8';
if ( ref $j ) {
$j = $_json->encode($j);
}
......
......@@ -12,9 +12,9 @@ lib/Lemonldap/NG/Manager/Build/Tree.pm
lib/Lemonldap/NG/Manager/Cli.pm
lib/Lemonldap/NG/Manager/Cli/Lib.pm
lib/Lemonldap/NG/Manager/Conf.pm
lib/Lemonldap/NG/Manager/Conf/Parser.pm
lib/Lemonldap/NG/Manager/Conf/Tests.pm
lib/Lemonldap/NG/Manager/Conf/Zero.pm
lib/Lemonldap/NG/Manager/Conf/Parser.pm
lib/Lemonldap/NG/Manager/Constants.pm
lib/Lemonldap/NG/Manager/Lib.pm
lib/Lemonldap/NG/Manager/Notifications.pm
......@@ -124,6 +124,7 @@ t/02-HTML-template.t
t/03-HTML-forms.t
t/05-rest-api.t
t/06-rest-api.t
t/07-utf8.t
t/10-save-unchanged-conf.t
t/12-save-changed-conf.t
t/20-test-coverage.t
......
......@@ -898,6 +898,9 @@ sub newConf {
$res->{needConfirm} = 1;
$res->{message} .= '__needConfirmation__';
}
else {
$res->{message} = $Lemonldap::NG::Common::Conf::msg;
}
}
}
}
......
......@@ -96,11 +96,16 @@ sub check {
}
unless ( $self->testNewConf ) {
hdebug("testNewConf() failed");
hdebug(" testNewConf() failed");
return 0;
}
$self->message('__confNotChanged__') unless ( $self->confChanged );
return ( $self->confChanged );
hdebug(" tests succeed");
unless ( $self->confChanged ) {
hdebug(" no changes detected");
$self->message('__confNotChanged__');
return 0;
}
return 1;
}
##@method boolean scanTree()
......@@ -791,7 +796,7 @@ sub _unitTest {
sub _globalTest {
my $self = shift;
require Lemonldap::NG::Manager::Conf::Tests;
hdebug('# _globalTest');
hdebug('# _globalTest()');
my $result = 1;
my $tests = &Lemonldap::NG::Manager::Conf::Tests::tests( $self->newConf );
while ( my ( $name, $sub ) = each %$tests ) {
......
......@@ -95,7 +95,7 @@
$scope.message.title = 'networkProblem';
$scope.message.items = [];
}
$scope.showModal('message.html');
return $scope.showModal('message.html');
};
/* Modal launcher */
......@@ -740,10 +740,11 @@
$location.path('/confs/' + n);
$scope.init();
}).error(function(j, e) {
$scope.currentCfg.cfgNum = 0;
$scope.init();
// TODO: insert conf 0
readError(j, e);
readError(j, e).then(function() {
console.log(e);
$scope.currentCfg.cfgNum = 0;
$scope.init();
});
});
} else {
$scope.waiting = false;
......
#!/usr/bin/env perl -I pl/lib
#
# Test if an UTF-8 char is well returned
use Test::More;
use JSON::MaybeXS;
use strict;
require 't/test-lib.pm';
my $href = &client->jsonResponse('/confs/1/cfgAuthor');
print STDERR Dumper($href);use Data::Dumper;
done_testing( count() );
......@@ -84,7 +84,7 @@
}
},
"authentication": "Demo",
"cfgAuthor": "The LemonLDAP::NG team",
"cfgAuthor": "The LemonLDAP::NG team ©",
"cfgAuthorIP": "127.0.0.1",
"cfgDate": 1428138808,
"cfgLog": "Default configuration provided by LemonLDAP::NG team",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment