From 55ed5b325c9bf9fdf1c3c40faa5b4fc8f7500711 Mon Sep 17 00:00:00 2001 From: Wolfsblvt Date: Tue, 8 Apr 2025 21:14:09 +0200 Subject: [PATCH] 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);