mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-04-22 20:24:36 +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:
parent
3a9bf09c88
commit
11a79b0086
@ -2518,14 +2518,15 @@ FW_makeEdit($$$)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
my %jsTab = ( 92=>'\\\\', 34=>'\\"', 9=>'\\t', 13=>'\\r', 10=>'\\n' );
|
|
||||||
sub
|
sub
|
||||||
FW_longpollInfo($@)
|
FW_longpollInfo($@)
|
||||||
{
|
{
|
||||||
my $fmt = shift;
|
my $fmt = shift;
|
||||||
if($fmt && $fmt eq "JSON") {
|
if($fmt && $fmt eq "JSON") {
|
||||||
my @a;
|
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).'"]';
|
return '["'.join('","', @a).'"]';
|
||||||
} else {
|
} else {
|
||||||
return join('<<', @_);
|
return join('<<', @_);
|
||||||
|
@ -55,17 +55,7 @@ JsonEscape($)
|
|||||||
{
|
{
|
||||||
my $a = shift;
|
my $a = shift;
|
||||||
return "null" if(!$a);
|
return "null" if(!$a);
|
||||||
my %esc = (
|
$a=~ s/([\x00-\x19\x22\x5c])/sprintf '\u%04x', ord($1)/ge; # Forum 57377
|
||||||
"\n" => '\n',
|
|
||||||
"\r" => '\r',
|
|
||||||
"\t" => '\t',
|
|
||||||
"\f" => '\f',
|
|
||||||
"\b" => '\b',
|
|
||||||
"\"" => '\"',
|
|
||||||
"\\" => '\\\\',
|
|
||||||
"\'" => '\\\'',
|
|
||||||
);
|
|
||||||
$a =~ s/([\x22\x5c\n\r\t\f\b])/$esc{$1}/eg;
|
|
||||||
return $a;
|
return $a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,17 +25,7 @@ JsonList2_Escape($)
|
|||||||
{
|
{
|
||||||
my $a = shift;
|
my $a = shift;
|
||||||
return "null" if(!defined($a));
|
return "null" if(!defined($a));
|
||||||
my %esc = (
|
$a=~ s/([\x00-\x19\x22\x5c])/sprintf '\u%04x', ord($1)/ge; # Forum 57377
|
||||||
"\n" => '\n',
|
|
||||||
"\r" => '\r',
|
|
||||||
"\t" => '\t',
|
|
||||||
"\f" => '\f',
|
|
||||||
"\b" => '\b',
|
|
||||||
"\"" => '\"',
|
|
||||||
"\\" => '\\\\',
|
|
||||||
"\'" => '\\\'',
|
|
||||||
);
|
|
||||||
$a =~ s/([\x22\x5c\n\r\t\f\b])/$esc{$1}/eg;
|
|
||||||
my $b = "x$a";
|
my $b = "x$a";
|
||||||
$a = "<BINARY>" if(!utf8::decode($b)); # Forum #55318
|
$a = "<BINARY>" if(!utf8::decode($b)); # Forum #55318
|
||||||
return $a;
|
return $a;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user