0001-esmith-db-safely-decode-DB-data-to-UTF-8-strings.-Re.patch

nethserver-lib patch - Davide Principi, 09/29/2014 06:39 AM

Download (2.13 KB)

View differences:

lib/perl/esmith/db.pm
8 8

  
9 9
use esmith::config;
10 10
use strict;
11

  
11
use Encode qw(encode decode);
12 12

  
13 13
=head1 NAME
14 14

  
......
439 439
    }
440 440
    
441 441
    foreach (@list) {
442
	my %tmp = ('name' => $_);
443
        my $type = db_get_type($hash, $_);
442
	my %tmp = ('name' => decode('UTF-8', $_, Encode::FB_DEFAULT));
443
        my $type = db_get_type($hash, $_); 
444 444

  
445 445
	# Skip empty types:
446 446
        if ( ! defined $type) {
447 447
	    next;
448 448
        } 
449 449
	
450
	$tmp{'type'} =  $type;
450
	$tmp{'type'} = decode('UTF-8', $type, Encode::FB_DEFAULT);
451 451

  
452 452
        my %properties = db_get_prop($hash, $_);
453
        
454
	# Add properties if present:
455
	if( keys %properties)  {
456
	    $tmp{'props'} = \%properties;
453
	while(my($pk, $pv) = each %properties) {
454
	    $tmp{'props'}->{decode('UTF-8', $pk, Encode::FB_DEFAULT)} = decode('UTF-8', $pv, Encode::FB_DEFAULT);
457 455
	}
458

  
456
        
459 457
        push(@ret, \%tmp);
460 458
    }
461 459

  
root/sbin/e-smith/db
193 193
sub DB_dump_json
194 194
{
195 195
    my $key = shift;
196
    print to_json($db->prepare_json($key), {utf8 => 0, pretty => 0, allow_nonref => 1});
196
    print to_json($db->prepare_json($key), {utf8 => 1, pretty => 0, allow_nonref => 1});
197 197
}
198 198

  
199 199
sub DB_dump_json_pretty
200 200
{
201 201
    my $key = shift;
202
    print to_json($db->prepare_json($key), {utf8 => 0, pretty => 1, allow_nonref => 1}) . "\n";
202
    print to_json($db->prepare_json($key), {utf8 => 1, pretty => 1, allow_nonref => 1}) . "\n";
203 203
}
204 204

  
205 205
sub DB_keys
206
-