From fcf603ea90d25fab5a0dd73ac96892b89590ea89 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 4 Oct 2022 12:53:25 +0200 Subject: [PATCH] Check all regex fingerprint matches --- profile/fingerprint.go | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/profile/fingerprint.go b/profile/fingerprint.go index 1fb44fbf..4b71cddf 100644 --- a/profile/fingerprint.go +++ b/profile/fingerprint.go @@ -22,7 +22,7 @@ import ( // 3. How "strong" was the match? // 1. Equals: Length of path (irrelevant) // 2. Prefix: Length of prefix -// 3. Regex: 0 (we are not suicidal) +// 3. Regex: Length of match // ms-store:Microsoft.One.Note @@ -137,12 +137,20 @@ type fingerprintRegex struct { } func (fp fingerprintRegex) Match(value string) (score int) { - if fp.regex.MatchString(value) { - // Do not return any deviation from the base score. - // Trying to assign different scores to regex probably won't turn out to - // be a good idea. - return fingerprintRegexBaseScore + // Find best match. + for _, match := range fp.regex.FindAllString(value, -1) { + // Save match length if higher than score. + // This will also ignore empty matches. + 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 }