From 8eed5f51bd9be76fbacd2427e1dedecf124043e9 Mon Sep 17 00:00:00 2001 From: Dariusz L Date: Thu, 6 Aug 2026 21:24:06 +0200 Subject: [PATCH] Unify folder token normalization --- tests/test_downloads_tab_workflow_route.mjs | 28 +++++++++++++------ .../search/download_target_methods.js | 7 ++--- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/tests/test_downloads_tab_workflow_route.mjs b/tests/test_downloads_tab_workflow_route.mjs index cee6f57..9f8e5e2 100644 --- a/tests/test_downloads_tab_workflow_route.mjs +++ b/tests/test_downloads_tab_workflow_route.mjs @@ -30,6 +30,7 @@ import { normalizeCategoryToken, } from '../web/resolver/utils/category_aliases.generated.js'; import { getSha256Field, normalizeSha256 } from '../web/resolver/utils/hash_utils.js'; +import { normalizeSearchToken } from '../web/resolver/utils/search_utils.js'; import { getSourceDisplayLabel, normalizeSourceKey } from '../web/resolver/utils/source_labels.js'; import { baseModelAliasMethods } from '../web/resolver/search/base_model_alias_methods.js'; import { searchHashMethods } from '../web/resolver/search/search_hash_methods.js'; @@ -3089,6 +3090,22 @@ test('clicked Krea 2 concept metadata resolves to the matching LoRA subfolder', assert.equal(suggestion.matchedTag, 'concept'); }); +test('folder token normalization matches the shared search token normalization', () => { + const normalizeFolderToken = eval(`(${extractMethod(downloadTargetMethodsSource, 'normalizeFolderToken')})`); + const values = [ + '', + 'Pony\\Styles', + 'KREA-2 / Concept', + ' SDXL_v1.0 ', + 'Żółć 模型', + 'a+++b' + ]; + + values.forEach(value => { + assert.equal(normalizeFolderToken.call({}, value), normalizeSearchToken(value), value); + }); +}); + test('queued workflow model selection survives missing data and completes after analysis', () => { const queueWorkflowModelReferenceSelection = eval(`(${extractMethod(missingBrowserMethodsSource, 'queueWorkflowModelReferenceSelection')})`); const applyPendingWorkflowModelSelection = eval(`(${extractMethod(missingBrowserMethodsSource, 'applyPendingWorkflowModelSelection')})`); @@ -4188,9 +4205,7 @@ test('options path preview delegates token rendering to the shared template form test('download subfolder tooltip identifies a folder taken from the workflow model path', () => { const getDownloadSubfolderSuggestionReason = eval(`(${extractMethod(downloadTargetMethodsSource, 'getDownloadSubfolderSuggestionReason')})`); const dialog = { - normalizeFolderToken(value = '') { - return String(value || '').toLowerCase().replace(/[^a-z0-9]+/g, ''); - } + normalizeFolderToken: normalizeSearchToken }; const reason = getDownloadSubfolderSuggestionReason.call(dialog, { @@ -4914,12 +4929,7 @@ test('subfolder suggestion ignores hidden local matches below the visible confid getCachedSearchSuggestionData() { return {}; }, - normalizeFolderToken(value = '') { - return String(value || '') - .toLowerCase() - .replace(/[\\/]+/g, ' ') - .replace(/[^a-z0-9]+/g, ''); - } + normalizeFolderToken: normalizeSearchToken }; const missing = { original_path: 'KNPV3_1.safetensors', diff --git a/web/resolver/search/download_target_methods.js b/web/resolver/search/download_target_methods.js index 39efb3e..ef23bd9 100644 --- a/web/resolver/search/download_target_methods.js +++ b/web/resolver/search/download_target_methods.js @@ -5,7 +5,7 @@ import { normalizeDownloadCategoryValue } from "../utils/category_utils.js"; import { safeStorage } from "../utils/html_utils.js"; import { getSha256Field } from "../utils/hash_utils.js"; import { joinPathPreservingStyle } from "../utils/path_utils.js"; -import { matchesSearchText } from "../utils/search_utils.js"; +import { matchesSearchText, normalizeSearchToken } from "../utils/search_utils.js"; const localStorage = safeStorage; const invalidWindowsPathCharacters = new RegExp( `[<>:"|?*${Array.from({ length: 32 }, (_, code) => String.fromCharCode(code)).join('')}]+`, @@ -1712,10 +1712,7 @@ export const downloadTargetMethods = { }, normalizeFolderToken(value = '') { - return String(value || '') - .toLowerCase() - .replace(/[/\\]+/g, ' ') - .replace(/[^a-z0-9]+/g, ''); + return normalizeSearchToken(value); }, getFolderSuggestionEntries(folders = []) {