mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-01-31 06:39:11 +00:00
fhem.pl: add CheckRegexp function (Forum #112168)
git-svn-id: https://svn.fhem.de/fhem/trunk@22189 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
7335ff54d9
commit
37a6ffc566
@ -477,8 +477,8 @@ MQTT2_DEVICE_Attr($$)
|
||||
my ($par1, $par2) = split(" ", $el, 2);
|
||||
next if(!$par1);
|
||||
return "$dev attr $attrName: more parameters needed" if(!$par2);
|
||||
eval { "Hallo" =~ m/^$par1$/ };
|
||||
return "$dev $attrName regexp error: $@" if($@);
|
||||
my $errMsg = CheckRegexp($par1, "bridgeRegexp attribute for $dev");
|
||||
return $errMsg if($errMsg);
|
||||
}
|
||||
if($init_done) {
|
||||
my $name = $hash->{NAME};
|
||||
@ -588,10 +588,9 @@ MQTT2_DEVICE_addReading($$)
|
||||
my $cid = $defs{$name}{CID};
|
||||
foreach my $line (split("\n", $param)) {
|
||||
my ($re,$code) = split(" ", $line,2);
|
||||
return "Bad line >$line< for $name" if(!defined($re) || !defined($code));
|
||||
return "Bad regexp >$re< for $name: $@" if($re =~ m/^[*+]/);
|
||||
eval { "Hallo" =~ m/^$re$/ };
|
||||
return "Bad regexp >$re< for $name: $@" if($@);
|
||||
return "Bad line >$line< for $name" if(!defined($code));
|
||||
my $errMsg = CheckRegexp($re, "readingList attribute for $name");
|
||||
return $errMsg if($errMsg);
|
||||
if($cid && $re =~ m/^$cid:/) {
|
||||
$modules{MQTT2_DEVICE}{defptr}{"re:$cid"}{$re}{"$name,$code"} = 1;
|
||||
} else {
|
||||
|
13
fhem/fhem.pl
13
fhem/fhem.pl
@ -56,6 +56,7 @@ sub Authenticate($$);
|
||||
sub CallFn(@);
|
||||
sub CallInstanceFn(@);
|
||||
sub CheckDuplicate($$@);
|
||||
sub CheckRegexp($$);
|
||||
sub Debug($);
|
||||
sub DoSet(@);
|
||||
sub Dispatch($$;$$);
|
||||
@ -6117,4 +6118,16 @@ execFhemTestFile()
|
||||
InternalTimer(1, sub { require $fhemTestFile }, 0 ) if($fhemTestFile);
|
||||
}
|
||||
|
||||
# return undef if ok or error. Prameter: regexp, error context
|
||||
sub
|
||||
CheckRegexp($$)
|
||||
{
|
||||
my ($re,$context) = @_;
|
||||
return "Empty regexp in $context" if(!defined($re));
|
||||
return "Bad regexp >$re< in $context" if($re =~ m/^[*+]/);
|
||||
eval { "Hallo" =~ m/^$re$/ };
|
||||
return "Bad regexp >$re< in $context: $@" if($@);
|
||||
return undef;
|
||||
}
|
||||
|
||||
1;
|
||||
|
Loading…
Reference in New Issue
Block a user