From 6895892d5a9e473c135a3985570ceb144e248e9f Mon Sep 17 00:00:00 2001 From: Wolfsblvt Date: Tue, 8 Apr 2025 20:58:22 +0200 Subject: [PATCH 1/5] Prevent similarily-ish world info renames Adds validation to block renaming world info entries when new name matches existing name after ignoring case and accents This avoids unnecessary operations and potential data duplication issues caused by superficial name changes that don't meaningfully differ in normalized form --- public/scripts/world-info.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/public/scripts/world-info.js b/public/scripts/world-info.js index f0382065e..84f11e18e 100644 --- a/public/scripts/world-info.js +++ b/public/scripts/world-info.js @@ -1,7 +1,7 @@ import { Fuse } from '../lib.js'; import { saveSettings, substituteParams, getRequestHeaders, chat_metadata, this_chid, characters, saveCharacterDebounced, menu_type, eventSource, event_types, getExtensionPromptByName, saveMetadata, getCurrentChatId, extension_prompt_roles } from '../script.js'; -import { download, debounce, initScrollHeight, resetScrollHeight, parseJsonFile, extractDataFromPng, getFileBuffer, getCharaFilename, getSortableDelay, escapeRegex, PAGINATION_TEMPLATE, navigation_option, waitUntilCondition, isTrueBoolean, setValueByPath, flashHighlight, select2ModifyOptions, getSelect2OptionId, dynamicSelect2DataViaAjax, highlightRegex, select2ChoiceClickSubscribe, isFalseBoolean, getSanitizedFilename, checkOverwriteExistingData, getStringHash, parseStringArray, cancelDebounce, findChar, onlyUnique } from './utils.js'; +import { download, debounce, initScrollHeight, resetScrollHeight, parseJsonFile, extractDataFromPng, getFileBuffer, getCharaFilename, getSortableDelay, escapeRegex, PAGINATION_TEMPLATE, navigation_option, waitUntilCondition, isTrueBoolean, setValueByPath, flashHighlight, select2ModifyOptions, getSelect2OptionId, dynamicSelect2DataViaAjax, highlightRegex, select2ChoiceClickSubscribe, isFalseBoolean, getSanitizedFilename, checkOverwriteExistingData, getStringHash, parseStringArray, cancelDebounce, findChar, onlyUnique, equalsIgnoreCaseAndAccents } from './utils.js'; import { extension_settings, getContext } from './extensions.js'; import { NOTE_MODULE_NAME, metadata_keys, shouldWIAddPrompt } from './authors-note.js'; import { isMobile } from './RossAscends-mods.js'; @@ -3586,6 +3586,10 @@ async function renameWorldInfo(name, data) { console.debug('World info rename cancelled'); return; } + if (equalsIgnoreCaseAndAccents(oldName, newName)) { + console.warn('World info name is the same (ignoring case and accents)'); + return; + } const entryPreviouslySelected = selected_world_info.findIndex((e) => e === oldName); From 55ed5b325c9bf9fdf1c3c40faa5b4fc8f7500711 Mon Sep 17 00:00:00 2001 From: Wolfsblvt Date: Tue, 8 Apr 2025 21:14:09 +0200 Subject: [PATCH 2/5] Prevent similarily-ish preset renames Adds validation to prevent renaming presets to names that are identical when ignoring case and accents Avoids accidental duplicates by ensuring meaningful name changes during preset renames --- public/scripts/preset-manager.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/public/scripts/preset-manager.js b/public/scripts/preset-manager.js index cdff9501c..fc2f9e86f 100644 --- a/public/scripts/preset-manager.js +++ b/public/scripts/preset-manager.js @@ -36,7 +36,7 @@ import { textgenerationwebui_presets, textgenerationwebui_settings as textgen_settings, } from './textgen-settings.js'; -import { download, parseJsonFile, waitUntilCondition } from './utils.js'; +import { download, equalsIgnoreCaseAndAccents, parseJsonFile, waitUntilCondition } from './utils.js'; import { t } from './i18n.js'; import { reasoning_templates } from './reasoning.js'; @@ -454,6 +454,9 @@ class PresetManager { async renamePreset(newName) { const oldName = this.getSelectedPresetName(); + if (equalsIgnoreCaseAndAccents(oldName, newName)) { + throw new Error('New name must be different from old name'); + } try { await this.savePreset(newName); await this.deletePreset(oldName); @@ -892,6 +895,10 @@ export async function initPresetManager() { console.debug(!presetManager.isAdvancedFormatting() ? 'Preset rename cancelled' : 'Template rename cancelled'); return; } + if (equalsIgnoreCaseAndAccents(oldName, newName)) { + console.warn('Preset name is the same (ignoring case and accents)'); + return; + } await presetManager.renamePreset(newName); From 47652d7fe9226bd7526d12b0498ac03c181b4fc1 Mon Sep 17 00:00:00 2001 From: Wolfsblvt Date: Tue, 8 Apr 2025 21:16:11 +0200 Subject: [PATCH 3/5] Prevent similarily-ish chat name renames --- public/script.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/public/script.js b/public/script.js index b57dad454..759a7462b 100644 --- a/public/script.js +++ b/public/script.js @@ -173,6 +173,7 @@ import { escapeHtml, saveBase64AsFile, uuidv4, + equalsIgnoreCaseAndAccents, } from './scripts/utils.js'; import { debounce_timeout, IGNORE_SYMBOL } from './scripts/constants.js'; @@ -9878,6 +9879,11 @@ export async function renameChat(oldFileName, newName) { renamed_file: `${newName.trim()}.jsonl`, }; + if (equalsIgnoreCaseAndAccents(body.original_file, body.renamed_file)) { + console.warn('Chat name is the same (ignoring case and accents)'); + return; + } + try { showLoader(); const response = await fetch('/api/chats/rename', { From ceceb8f3f05d046847ae3934068989a555d2fa94 Mon Sep 17 00:00:00 2001 From: Wolfsblvt Date: Wed, 9 Apr 2025 01:21:20 +0200 Subject: [PATCH 4/5] Change same name logs to toast --- public/script.js | 6 +++++- public/scripts/preset-manager.js | 2 +- public/scripts/world-info.js | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/public/script.js b/public/script.js index 759a7462b..6e7ef8fd8 100644 --- a/public/script.js +++ b/public/script.js @@ -9879,8 +9879,12 @@ export async function renameChat(oldFileName, newName) { renamed_file: `${newName.trim()}.jsonl`, }; + if (body.original_file === body.renamed_file) { + console.debug('Chat rename cancelled, old and new names are the same'); + return; + } if (equalsIgnoreCaseAndAccents(body.original_file, body.renamed_file)) { - console.warn('Chat name is the same (ignoring case and accents)'); + toastr.warning('Name not accepted, as it is the same as before (ignoring case and accents).', 'Rename Chat'); return; } diff --git a/public/scripts/preset-manager.js b/public/scripts/preset-manager.js index fc2f9e86f..32d0ecbf9 100644 --- a/public/scripts/preset-manager.js +++ b/public/scripts/preset-manager.js @@ -896,7 +896,7 @@ export async function initPresetManager() { return; } if (equalsIgnoreCaseAndAccents(oldName, newName)) { - console.warn('Preset name is the same (ignoring case and accents)'); + toastr.warning('Name not accepted, as it is the same as before (ignoring case and accents).', 'Rename Preset'); return; } diff --git a/public/scripts/world-info.js b/public/scripts/world-info.js index 84f11e18e..b3985aad4 100644 --- a/public/scripts/world-info.js +++ b/public/scripts/world-info.js @@ -3587,7 +3587,7 @@ async function renameWorldInfo(name, data) { return; } if (equalsIgnoreCaseAndAccents(oldName, newName)) { - console.warn('World info name is the same (ignoring case and accents)'); + toastr.warning('Name not accepted, as it is the same as before (ignoring case and accents).', 'Rename World Info'); return; } From c522baf4f7889a8d1324ec7d8443758a66fa161a Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Wed, 9 Apr 2025 19:18:05 +0300 Subject: [PATCH 5/5] Make texts translatable --- public/script.js | 2 +- public/scripts/preset-manager.js | 2 +- public/scripts/world-info.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/public/script.js b/public/script.js index 6e7ef8fd8..f602a20ac 100644 --- a/public/script.js +++ b/public/script.js @@ -9884,7 +9884,7 @@ export async function renameChat(oldFileName, newName) { return; } if (equalsIgnoreCaseAndAccents(body.original_file, body.renamed_file)) { - toastr.warning('Name not accepted, as it is the same as before (ignoring case and accents).', 'Rename Chat'); + toastr.warning(t`Name not accepted, as it is the same as before (ignoring case and accents).`, t`Rename Chat`); return; } diff --git a/public/scripts/preset-manager.js b/public/scripts/preset-manager.js index 32d0ecbf9..5ddd42422 100644 --- a/public/scripts/preset-manager.js +++ b/public/scripts/preset-manager.js @@ -896,7 +896,7 @@ export async function initPresetManager() { return; } if (equalsIgnoreCaseAndAccents(oldName, newName)) { - toastr.warning('Name not accepted, as it is the same as before (ignoring case and accents).', 'Rename Preset'); + toastr.warning(t`Name not accepted, as it is the same as before (ignoring case and accents).`, t`Rename Preset`); return; } diff --git a/public/scripts/world-info.js b/public/scripts/world-info.js index b3985aad4..c1ff586a3 100644 --- a/public/scripts/world-info.js +++ b/public/scripts/world-info.js @@ -3587,7 +3587,7 @@ async function renameWorldInfo(name, data) { return; } if (equalsIgnoreCaseAndAccents(oldName, newName)) { - toastr.warning('Name not accepted, as it is the same as before (ignoring case and accents).', 'Rename World Info'); + toastr.warning(t`Name not accepted, as it is the same as before (ignoring case and accents).`, t`Rename World Info`); return; }