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
@@ -40,6 +40,15 @@ describe("applyLoraValuesToText", () => {
expect(result).toBe("<lora:Expanded:1.00:1.00>");
});
it("preserves repeated spaces inside LoRA names", () => {
const original = "<lora:test - 0021:1.00>";
const result = applyLoraValuesToText(original, [
{ name: "test - 0021", strength: 0.5 }
]);
expect(result).toBe("<lora:test - 0021:0.50>");
});
});
describe("normalizeStrengthValue", () => {
@@ -74,6 +83,18 @@ describe("cleanupLoraSyntax", () => {
it("collapses whitespace and stray commas", () => {
expect(cleanupLoraSyntax(" <lora:A:1.00> , ," )).toBe("<lora:A:1.00>");
});
it("preserves repeated spaces inside LoRA names", () => {
expect(cleanupLoraSyntax("<lora:test - 0021:1.00> , ,")).toBe(
"<lora:test - 0021:1.00>"
);
});
it("still normalizes whitespace between entries", () => {
expect(
cleanupLoraSyntax(" <lora:A:1.00> <lora:test - 0021:0.50> ")
).toBe("<lora:A:1.00> <lora:test - 0021:0.50>");
});
});
describe("debounce", () => {