Skip to content

A platform for community discussion. Free, open, simple.

FIX: Overly aggressive fuzzy matching in site setting matcher (#39439)

Martin Brennan90d023018bc0
diff --git a/frontend/discourse/admin/lib/site-setting-matcher.js b/frontend/discourse/admin/lib/site-setting-matcher.js
index 9611ce8ca8b..1f8f0a9034e 100644
--- a/frontend/discourse/admin/lib/site-setting-matcher.js
+++ b/frontend/discourse/admin/lib/site-setting-matcher.js
@@ -1,3 +1,8 @@
+// Fuzzy name matches with strength below this (more negative) are order-only
+// subsequence matches that are too weak to show, unless the stripped query
+// appears as a contiguous block in the stripped name (see isFuzzyNameMatch).
+const MIN_FUZZY_NAME_MATCH_STRENGTH = -2;
+
export default class SiteSettingMatcher {
constructor(filter, siteSetting) {
this.filter = filter;
@@ -61,6 +66,12 @@ export default class SiteSettingMatcher {
return false;
}
+ // Contiguous block in the de-punctuated name: keep matchStrength 0 and
+ // skip gap scoring (subsequence can still look "weak" for long names).
+ if (strippedSetting.includes(this.strippedQuery)) {
+ return true;
+ }
+
const gapResult = strippedSetting.match(this.fuzzyRegexGaps);
if (gapResult) {
@@ -70,6 +81,12 @@ export default class SiteSettingMatcher {
this.matchStrength -= numberOfGaps;
}
+ // Order-only subsequence: drop very weak matches (e.g. "teams" matched
+ // across letters in "…telegram…" in a long `chat_integration_*` name).
+ if (this.matchStrength < MIN_FUZZY_NAME_MATCH_STRENGTH) {
+ return false;
+ }
+
return true;
}
}
diff --git a/frontend/discourse/tests/unit/lib/site-setting-matcher-test.js b/frontend/discourse/tests/unit/lib/site-setting-matcher-test.js
index 7f5d83b5594..0cf5089566e 100644
--- a/frontend/discourse/tests/unit/lib/site-setting-matcher-test.js
+++ b/frontend/discourse/tests/unit/lib/site-setting-matcher-test.js
@@ -68,4 +68,29 @@ module("Unit | Lib | SiteSettingMatcher", function (hooks) {
assert.true(matchingMatcher.isFuzzyNameMatch);
assert.strictEqual(matchingMatcher.matchStrength, -1); // Smallest number of gaps.
});
+
+ test("#isFuzzyNameMatch requires contiguous stripped query or sufficient matchStrength", function (assert) {
+ const teamsEnabled = SiteSetting.create({
+ setting: "chat_integration_teams_enabled",
+ description: "x",
+ });
+ const telegram = SiteSetting.create({
+ setting: "chat_integration_telegram_access_token",
+ description: "x",
+ });
+
+ const query = "chat_integration_teams";
+ const good = new SiteSettingMatcher(query, teamsEnabled);
+ const tooWeak = new SiteSettingMatcher(query, telegram);
+
+ assert.true(
+ good.isFuzzyNameMatch,
+ "name contains the full stripped query consecutively"
+ );
+
+ assert.false(
+ tooWeak.isFuzzyNameMatch,
+ "order-only match on a different long token is dropped"
+ );
+ });
});