mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-09-20 18:51:26 -03:00
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:
@@ -227,8 +227,20 @@ function formatAutocompleteInsertion(text = '') {
|
||||
return getAutocompleteAppendCommaPreference() ? `${trimmed},` : `${trimmed} `;
|
||||
}
|
||||
|
||||
// Matches a complete <lora:name:strength[:clip_strength]> tag. Kept
|
||||
// permissive on the strength fields (mirrors the backend parser) so tags
|
||||
// are still protected while the user is mid-edit.
|
||||
const LORA_TAG_PATTERN = /(<lora:[^:>]+:[^:>]+(?::[^:>]+)?>)/gi;
|
||||
|
||||
function normalizeAutocompleteSegment(segment = '') {
|
||||
return segment.replace(/\s+/g, ' ').trim();
|
||||
// Collapse whitespace only outside <lora:...> tags: names inside the tags
|
||||
// may legitimately contain repeated spaces (e.g. "test - 0021"), and
|
||||
// collapsing them breaks file resolution at runtime.
|
||||
return segment
|
||||
.split(LORA_TAG_PATTERN)
|
||||
.map((part, index) => (index % 2 === 1 ? part : part.replace(/\s+/g, ' ')))
|
||||
.join('')
|
||||
.trim();
|
||||
}
|
||||
|
||||
export function formatAutocompleteTextOnBlur(text = '') {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user