mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-05-04 22:19:38 +00:00
01_FHEMWEB.pm,98_JsonList.pm,98_JsonList2.pm: Better escaping by Boris (Forum #57377)
git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@12254 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
4b8e5b19a2
commit
11ac5865e5
@ -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 = $_;
|
||||
$x =~ s/([^\x20-\x7e]|[\x22\x5c])/sprintf '\u%04x', ord($1)/ge;
|
||||
push @a,$x; } @_;
|
||||
return '["'.join('","', @a).'"]';
|
||||
} else {
|
||||
return join('<<', @_);
|
||||
|
@ -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/([^\x20-\x7e]|[\x22\x5c])/sprintf '\u%04x', ord($1)/ge;
|
||||
return $a;
|
||||
}
|
||||
|
||||
|
@ -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/([^\x20-\x7e]|[\x22\x5c])/sprintf '\u%04x', ord($1)/ge;
|
||||
my $b = "x$a";
|
||||
$a = "<BINARY>" if(!utf8::decode($b)); # Forum #55318
|
||||
return $a;
|
||||
|
Loading…
x
Reference in New Issue
Block a user