2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-03 04:36:36 +00:00

10_MQTT2_DEVICE.pm: CheckRegexp with devicetopic for readingList (Forum #126969)

git-svn-id: https://svn.fhem.de/fhem/trunk@25889 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2022-03-27 10:39:22 +00:00
parent 493ca454f7
commit 7a328160c4
2 changed files with 9 additions and 5 deletions

View File

@ -474,10 +474,6 @@ MQTT2_DEVICE_Attr($$)
return "$dev attr $attrName: more parameters needed" if(!$par2);
if($atype eq "reading") {
$par1 =~ s/\$[a-z0-9_]+/\.\*/gi;
eval { "Hallo" =~ m/^$par1$/ };
return "Bad regexp in $dev readingList: $@" if($@);
if($par2 =~ m/^{.*}\s*$/) {
my %v = ("%TOPIC"=>1, "%EVENT"=>"0 1 2 3 4 5 6 7 8 9",
"%NAME"=>$dev, "%CID"=>"clientId", "%JSONMAP"=>"");
@ -625,10 +621,11 @@ MQTT2_DEVICE_addReading($$)
next if($line eq "");
my ($re,$code) = split(" ", $line,2);
return "ERROR: empty code in line >$line< for $name" if(!defined($code));
map { $re =~ s/\$$_/$hash->{".DT"}{$_}/g } keys %{$hash->{".DT"}};
my $errMsg = CheckRegexp($re, "readingList attribute for $name");
return $errMsg if($errMsg);
map { $re =~ s/\$$_/$hash->{".DT"}{$_}/g } keys %{$hash->{".DT"}};
if($cid && $re =~ m/^$cid:/) {
if($re =~ m/^$cid:([^\\\?.*\[\](|)]+):\.\*$/) { # cid:topic:.*
$modules{MQTT2_DEVICE}{defptr}{"re:$cid:$1"}{$re}{"$name,$code"} = 1;

View File

@ -6396,8 +6396,15 @@ CheckRegexp($$)
my ($re,$context) = @_;
return "Empty regexp in $context" if(!defined($re));
return "Bad regexp >$re< in $context" if($re =~ m/^[*+]/);
my $warn;
my $osig = $SIG{__WARN__};
$SIG{__WARN__} = sub { $warn = @_[0]};
eval { "Hallo" =~ m/^$re$/ };
$SIG{__WARN__} = $osig;
return "Bad regexp >$re< in $context: $@" if($@);
return "Bad regexp >$re< in $context: $warn" if($warn);
return undef;
}