fix(bulk-context-menu): escape special characters in data-filepath selector to support double quotes in filenames (#845)

This commit is contained in:
Will Miao
2026-03-12 08:49:10 +08:00
parent 5c29e26c4e
commit 4fcf641d57
7 changed files with 34 additions and 10 deletions

View File

@@ -846,8 +846,14 @@ function setupLoraSpecificFields(filePath) {
const currentPath = resolveFilePath();
if (!currentPath) return;
const loraCard = document.querySelector(`.model-card[data-filepath="${currentPath}"]`) ||
document.querySelector(`.model-card[data-filepath="${filePath}"]`);
const escapedCurrentPath = window.CSS && typeof window.CSS.escape === 'function'
? window.CSS.escape(currentPath)
: currentPath.replace(/["\\]/g, '\\$&');
const escapedFilePath = window.CSS && typeof window.CSS.escape === 'function'
? window.CSS.escape(filePath)
: filePath.replace(/["\\]/g, '\\$&');
const loraCard = document.querySelector(`.model-card[data-filepath="${escapedCurrentPath}"]`) ||
document.querySelector(`.model-card[data-filepath="${escapedFilePath}"]`);
const currentPresets = parsePresets(loraCard?.dataset.usage_tips);
if (key === 'strength_range') {

View File

@@ -49,7 +49,10 @@ function formatPresetKey(key) {
*/
window.removePreset = async function(key) {
const filePath = document.querySelector('#modelModal .modal-content .file-path').dataset.filepath;
const loraCard = document.querySelector(`.model-card[data-filepath="${filePath}"]`);
const escapedPath = window.CSS && typeof window.CSS.escape === 'function'
? window.CSS.escape(filePath)
: filePath.replace(/["\\]/g, '\\$&');
const loraCard = document.querySelector(`.model-card[data-filepath="${escapedPath}"]`);
const currentPresets = parsePresets(loraCard.dataset.usage_tips);
delete currentPresets[key];