Preserve carriage returns and line feeds in configuration values

This commit is contained in:
Clément Oudot 2010-02-08 12:20:37 +00:00
parent 788f688d78
commit bdef53f289
4 changed files with 41 additions and 13 deletions

View File

@ -24,13 +24,20 @@ sub serialize {
}
else {
# mono-line
$v =~ s/[\r\n]/ /gm;
# trim
# trim white spaces
$v =~ s/^\s*(.*?)\s*$/$1/;
# Convert carriage returns (\r) and line feeds (\n)
$v =~ s/\r/%0D/g;
$v =~ s/\n/%0A/g;
# Convert simple quotes
$v =~ s/'/'/g;
# Surround with simple quotes
$v = "'$v'" unless ( $self->{noQuotes} );
# Store value in field
$fields->{$k} = $v;
}
}
@ -41,9 +48,13 @@ sub unserialize {
my ( $self, $fields ) = @_;
my $conf;
while ( my ( $k, $v ) = each(%$fields) ) {
# Remove surrounding quotes
$v =~ s/^'(.*)'$/$1/s;
# Manage hashes
if ( $k =~
/^(?:exportedVars|locationRules|groups|exportedHeaders|macros|globalStorageOptions|notificationStorageOptions|samlServiceMetaData|samlIDPMetaData|samlSPMetaData)$/
/^(?:exportedVars|locationRules|groups|exportedHeaders|macros|globalStorageOptions|notificationStorageOptions|samlIDPMetaData|samlSPMetaData)$/
and $v ||= {}
and not ref($v) )
{
@ -71,6 +82,8 @@ sub unserialize {
}
else {
$v =~ s/&#?39;/'/g;
$v =~ s/%0D/\r/g;
$v =~ s/%0A/\n/g;
$conf->{$k} = $v;
}
}

View File

@ -140,7 +140,7 @@ function lmtext(id){
return $('#text_'+id).attr('name');
}
function lmdata(id){
return $('#text_'+id).attr('value');
return unescape( $('#text_'+id).attr('value') );
}
function lmparent(id){
return $('#'+id).parent().parent().attr('id');
@ -155,7 +155,7 @@ function setlmtext(id,v){
}
}
function setlmdata(id,v){
$('#text_'+id).attr('value',v);
$('#text_'+id).attr('value',escape(v));
}
function setlmsamlassertion(id){
var ind=$('#samlAssertionIndex').attr('value');

View File

@ -10,6 +10,7 @@ use MIME::Base64;
# TODO
use Data::Dumper;
use URI::Escape;
require Lemonldap::NG::Manager::_Struct; #inherits
require Lemonldap::NG::Manager::_i18n; #inherits
@ -411,19 +412,28 @@ sub ajaxNode {
sub span {
my ( $self, %args ) = @_;
#my ( $self, $id, $text, $data, $js, $help, $noT ) = @_;
my $tmp = $args{text};
# Data
$args{data} = '' unless ( defined $args{data} );
$args{js} ||= "none";
$args{data} =~ s/"/'/g;
$args{data} = uri_escape( $args{data} );
# ID
$args{id} = "li_" . encode_base64( $args{id}, '' );
$args{id} =~ s/(=*)$/length($1)/e;
# Javascript
$args{js} ||= "none";
$args{js} .= "('$args{id}')" unless ( $args{js} =~ /\(/ );
$args{data} =~ s/"/'/g;
# Text
my $tmp = $args{text};
$tmp =~ s/"/'/g;
$args{text} = join ' ', map { $self->translate($_) } split /\s+/,
$args{text}
unless ( $args{noT} );
$args{text} = $self->escapeHTML( $args{text} );
# Return HTML code
return
"<span name=\"$tmp\" id=\"text_$args{id}\" onclick=\"$args{js}\" help=\"$args{help}\" value=\"$args{data}\">$args{text}</span>
";

View File

@ -12,6 +12,7 @@ use MIME::Base64;
# TODO
use Data::Dumper;
use URI::Escape;
use Lemonldap::NG::Common::Safelib; #link protected safe Safe object
use Lemonldap::NG::Manager::Downloader; #inherits
use Lemonldap::NG::Manager::_Struct; #link protected struct _Struct object
@ -55,6 +56,10 @@ sub confUpload {
$_->getAttribute('name'),
$_->getAttribute('value')
);
# Unescape value
$value = uri_unescape($value);
my $NK = 0;
$id =~
s/^text_(NewID_)?li_(\w+)(\d)(?:_\d+)?$/decode_base64($2.'='x $3)/e;
@ -90,7 +95,7 @@ sub confUpload {
$errors->{errors}->{$name} = $m || $test->{keyMsgFail};
next;
}
$errors->{warnings}->{$name} = $m if($m);
$errors->{warnings}->{$name} = $m if ($m);
}
if ( $test->{test} ) {
( $res, $m ) = $self->applyTest( $test->{test}, $value );
@ -98,7 +103,7 @@ sub confUpload {
$errors->{errors}->{$name} = $m || $test->{msgFail};
next;
}
$errors->{warnings}->{$name} = $m if($m);
$errors->{warnings}->{$name} = $m if ($m);
}
# 1.3.1.2 Tests that return a warning