mirror of
https://github.com/safing/portmaster
synced 2025-09-02 10:39:22 +00:00
Check all regex fingerprint matches
This commit is contained in:
parent
f329e40da7
commit
fcf603ea90
1 changed files with 14 additions and 6 deletions
|
@ -22,7 +22,7 @@ import (
|
||||||
// 3. How "strong" was the match?
|
// 3. How "strong" was the match?
|
||||||
// 1. Equals: Length of path (irrelevant)
|
// 1. Equals: Length of path (irrelevant)
|
||||||
// 2. Prefix: Length of prefix
|
// 2. Prefix: Length of prefix
|
||||||
// 3. Regex: 0 (we are not suicidal)
|
// 3. Regex: Length of match
|
||||||
|
|
||||||
// ms-store:Microsoft.One.Note
|
// ms-store:Microsoft.One.Note
|
||||||
|
|
||||||
|
@ -137,12 +137,20 @@ type fingerprintRegex struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fp fingerprintRegex) Match(value string) (score int) {
|
func (fp fingerprintRegex) Match(value string) (score int) {
|
||||||
if fp.regex.MatchString(value) {
|
// Find best match.
|
||||||
// Do not return any deviation from the base score.
|
for _, match := range fp.regex.FindAllString(value, -1) {
|
||||||
// Trying to assign different scores to regex probably won't turn out to
|
// Save match length if higher than score.
|
||||||
// be a good idea.
|
// This will also ignore empty matches.
|
||||||
return fingerprintRegexBaseScore
|
if len(match) > score {
|
||||||
|
score = len(match)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add base score and return if anything was found.
|
||||||
|
if score > 0 {
|
||||||
|
return fingerprintRegexBaseScore + checkMatchStrength(score)
|
||||||
|
}
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue