Merge pull request #3827 from SillyTavern/fix/wi-rename-same-name Prevent similarily-ish world info, preset and chat file renames (preventing data loss on on case-insensitive systems)

f302c67b955b479988df1ace5a600ba81bcabfc8

Cohee <18619528+Cohee1207@users.noreply.github.com>

Signed
3 files changed, +23 -2Showing whitespace changes
public/script.js+10 -0
@@ -173,6 +173,7 @@ import {
173173 escapeHtml,
174174 saveBase64AsFile,
175175 uuidv4,
176+ equalsIgnoreCaseAndAccents,
176177} from './scripts/utils.js';
177178import { debounce_timeout, IGNORE_SYMBOL } from './scripts/constants.js';
178179
@@ -9878,6 +9879,15 @@ export async function renameChat(oldFileName, newName) {
98789879 renamed_file: `${newName.trim()}.jsonl`,
98799880 };
98809881
9882+ if (body.original_file === body.renamed_file) {
9883+ console.debug('Chat rename cancelled, old and new names are the same');
9884+ return;
9885+ }
9886+ if (equalsIgnoreCaseAndAccents(body.original_file, body.renamed_file)) {
9887+ toastr.warning(t`Name not accepted, as it is the same as before (ignoring case and accents).`, t`Rename Chat`);
9888+ return;
9889+ }
9890+
98819891 try {
98829892 showLoader();
98839893 const response = await fetch('/api/chats/rename', {
public/scripts/preset-manager.js+8 -1
@@ -36,7 +36,7 @@ import {
3636 textgenerationwebui_presets,
3737 textgenerationwebui_settings as textgen_settings,
3838} from './textgen-settings.js';
3939import { download, equalsIgnoreCaseAndAccents, parseJsonFile, waitUntilCondition } from './utils.js';
4040import { t } from './i18n.js';
4141import { reasoning_templates } from './reasoning.js';
4242
@@ -454,6 +454,9 @@ class PresetManager {
454454
455455 async renamePreset(newName) {
456456 const oldName = this.getSelectedPresetName();
457+ if (equalsIgnoreCaseAndAccents(oldName, newName)) {
458+ throw new Error('New name must be different from old name');
459+ }
457460 try {
458461 await this.savePreset(newName);
459462 await this.deletePreset(oldName);
@@ -892,6 +895,10 @@ export async function initPresetManager() {
892895 console.debug(!presetManager.isAdvancedFormatting() ? 'Preset rename cancelled' : 'Template rename cancelled');
893896 return;
894897 }
898+ if (equalsIgnoreCaseAndAccents(oldName, newName)) {
899+ toastr.warning(t`Name not accepted, as it is the same as before (ignoring case and accents).`, t`Rename Preset`);
900+ return;
901+ }
895902
896903 await presetManager.renamePreset(newName);
897904
public/scripts/world-info.js+5 -1
@@ -1,7 +1,7 @@
11import { Fuse } from '../lib.js';
22
33import { saveSettings, substituteParams, getRequestHeaders, chat_metadata, this_chid, characters, saveCharacterDebounced, menu_type, eventSource, event_types, getExtensionPromptByName, saveMetadata, getCurrentChatId, extension_prompt_roles } from '../script.js';
44import { 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';
55import { extension_settings, getContext } from './extensions.js';
66import { NOTE_MODULE_NAME, metadata_keys, shouldWIAddPrompt } from './authors-note.js';
77import { isMobile } from './RossAscends-mods.js';
@@ -3586,6 +3586,10 @@ async function renameWorldInfo(name, data) {
35863586 console.debug('World info rename cancelled');
35873587 return;
35883588 }
3589+ if (equalsIgnoreCaseAndAccents(oldName, newName)) {
3590+ toastr.warning(t`Name not accepted, as it is the same as before (ignoring case and accents).`, t`Rename World Info`);
3591+ return;
3592+ }
35893593
35903594 const entryPreviouslySelected = selected_world_info.findIndex((e) => e === oldName);
35913595