Skip to content

Pattern matching dot treatment #1

@JeeeK

Description

@JeeeK

I'm wondering that "vc*.kom" matches "vcvm.srv_kom" for a hostname rule. I looked into the source code and if I'm right this subroutine (in NoMa/notifier/lib/contacts.pm) is responsible for the observed behavior:
sub matchString { # test a string against a comma separated list and return 1 if it matches
my ($matchList, $match) =@_;

    my @items = split( ',', $matchList );
    @items = map( { lc($_) } @items );

    for my $item (@items)
    {
        # remove leading/trailing whitespace
        $item =~ s/^\s+|\s+$//g;

        if ( $item ne '' )
        {

    # Use * and ? as wildcards
            $item =~ s/\*/.*/g;
            $item =~ s/\./\./g;
            $item =~ s/\?/./g;

            # only add item to list if it matches the passed one
            return 1 if ( $match =~ m/^$item$/i );

        }

    }
return 0;

}

The treatment of "." in $item seems to be wrong, eventhough the dot will be correctly recognized, the replacement doesn't quote it right. $item still contains just a ".". The quoting expression should go like this:

$item =~ s/\./\\./g;
Could be verified by using following tests.
This matches, but should not:
perl -e '$p=".";$p=~s/\./\./g;$m="vc_kom";if($m =~ /$p/){print "$p matched $m\n"}'
Quoting it right, the dot really matches only literal dots:
perl -e '$p=".";$p=~s/\./\\./g;$m="vc_kom";if($m =~ /$p/){print "$p matched $m\n"}'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions