fix(lora-loader): preserve repeated spaces inside lora names

Whitespace cleanup in cleanupLoraSyntax() and the autocomplete blur
formatter collapsed all whitespace runs, including inside <lora:...>
tags. A file named 'test -  0021.safetensors' was rewritten to
'test - 0021' in the node text, so runtime file resolution failed.

Protect lora tags with placeholders (or segment splitting) so only
whitespace between entries is normalized; names inside tags are kept
byte-for-byte.
This commit is contained in:
Will Miao
2026-09-07 19:20:15 +08:00
parent 82b34097fb
commit 53fa22f39c
4 changed files with 106 additions and 3 deletions
+14 -2
View File
@@ -38,7 +38,17 @@ function cleanupLoraSyntax(text) {
return "";
}
let cleaned = text
// Protect <lora:...> tags with placeholders before cleanup: names inside
// the tags may legitimately contain repeated spaces or commas (e.g.
// "test - 0021"), and collapsing them breaks file resolution at runtime.
const protectedTags = [];
LORA_PATTERN.lastIndex = 0;
const masked = text.replace(LORA_PATTERN, (match) => {
protectedTags.push(match);
return `\u0000${protectedTags.length - 1}\u0000`;
});
let cleaned = masked
.replace(/\s+/g, " ")
.replace(/,\s*,+/g, ",")
.replace(/\s*,\s*/g, ",")
@@ -51,7 +61,9 @@ function cleanupLoraSyntax(text) {
cleaned = cleaned.replace(/(^,)|(,$)/g, "");
cleaned = cleaned.replace(/,\s*/g, ", ");
return cleaned.trim();
return cleaned
.trim()
.replace(/\u0000(\d+)\u0000/g, (_, index) => protectedTags[Number(index)]);
}
export function applyLoraValuesToText(originalText, loras) {