2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-02-07 16:59:18 +00:00

FHEMWEB+JsonList: fix escaping, second try (Forum #57377)

git-svn-id: https://svn.fhem.de/fhem/trunk@12275 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2016-10-05 14:33:55 +00:00
parent 3a9bf09c88
commit 11a79b0086
3 changed files with 5 additions and 24 deletions

View File

@ -2518,14 +2518,15 @@ FW_makeEdit($$$)
}
my %jsTab = ( 92=>'\\\\', 34=>'\\"', 9=>'\\t', 13=>'\\r', 10=>'\\n' );
sub
FW_longpollInfo($@)
{
my $fmt = shift;
if($fmt && $fmt eq "JSON") {
my @a;
map { my $x=$_; $x=~s/([\\"\t\r\n])/$jsTab{ord($1)}/ge; push @a,$x; } @_;
map { my $x = $_; #Forum 57377, ASCII 0-19 \ "
$x=~ s/([\x00-\x19\x22\x5c])/sprintf '\u%04x', ord($1)/ge;
push @a,$x; } @_;
return '["'.join('","', @a).'"]';
} else {
return join('<<', @_);

View File

@ -55,17 +55,7 @@ JsonEscape($)
{
my $a = shift;
return "null" if(!$a);
my %esc = (
"\n" => '\n',
"\r" => '\r',
"\t" => '\t',
"\f" => '\f',
"\b" => '\b',
"\"" => '\"',
"\\" => '\\\\',
"\'" => '\\\'',
);
$a =~ s/([\x22\x5c\n\r\t\f\b])/$esc{$1}/eg;
$a=~ s/([\x00-\x19\x22\x5c])/sprintf '\u%04x', ord($1)/ge; # Forum 57377
return $a;
}

View File

@ -25,17 +25,7 @@ JsonList2_Escape($)
{
my $a = shift;
return "null" if(!defined($a));
my %esc = (
"\n" => '\n',
"\r" => '\r',
"\t" => '\t',
"\f" => '\f',
"\b" => '\b',
"\"" => '\"',
"\\" => '\\\\',
"\'" => '\\\'',
);
$a =~ s/([\x22\x5c\n\r\t\f\b])/$esc{$1}/eg;
$a=~ s/([\x00-\x19\x22\x5c])/sprintf '\u%04x', ord($1)/ge; # Forum 57377
my $b = "x$a";
$a = "<BINARY>" if(!utf8::decode($b)); # Forum #55318
return $a;