From 5163015cba157944500c324991a13d0849ee2ee6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Sikorski?= Date: Wed, 28 Oct 2026 21:13:32 +0100 Subject: [PATCH 1/3] fix: preserve dots in filename date replacements --- src/utils/searchAndReplace.test.ts | 29 ++++++++++++++++++++++++++++- src/utils/searchAndReplace.ts | 12 ++++-------- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/utils/searchAndReplace.test.ts b/src/utils/searchAndReplace.test.ts index d2835152b68..d473fd6132e 100644 --- a/src/utils/searchAndReplace.test.ts +++ b/src/utils/searchAndReplace.test.ts @@ -1,4 +1,4 @@ -import { describe, expect, it } from 'vitest' +import { describe, expect, it, vi } from 'vitest' import { LGraph, LGraphNode } from '@/lib/litegraph/src/litegraph' import { applyTextReplacements } from '@/utils/searchAndReplace' @@ -12,6 +12,33 @@ function graphWithWidgetValue(value: string): LGraph { } describe('applyTextReplacements', () => { + describe('date replacements', () => { + it.for([ + ['yyyy-MM-dd', '2026-10-28'], + ['yyyy.MM', '2026.10'], + ['yyyy.MM.dd', '2026.10.28'], + ['hh.mm.ss', '14.05.09'] + ])('preserves separators in the date format %s', ([format, expected]) => { + vi.setSystemTime(new Date(2026, 9, 28, 14, 5, 9)) + + expect(applyTextReplacements(new LGraph(), `%date:${format}%`)).toBe( + expected + ) + }) + + it('combines dated folders and filenames with node widget values', () => { + vi.setSystemTime(new Date(2026, 9, 28, 14, 5, 9)) + const graph = graphWithWidgetValue('portrait') + + expect( + applyTextReplacements( + graph, + 'outputs/%date:yyyy.MM.dd%/%TestNode.testWidget%_%date:hh.mm.ss%' + ) + ).toBe('outputs/2026.10.28/portrait_14.05.09') + }) + }) + // Test specifically the filename sanitization part describe('filename sanitization', () => { it('should replace invalid filename characters with underscores', () => { diff --git a/src/utils/searchAndReplace.ts b/src/utils/searchAndReplace.ts index c7ecd96bc74..0df2e6027ac 100644 --- a/src/utils/searchAndReplace.ts +++ b/src/utils/searchAndReplace.ts @@ -9,25 +9,21 @@ export function applyTextReplacements( const allNodes = collectAllNodes(graph) return value.replace(/%([^%]+)%/g, function (match, text) { + if (text.startsWith('date:')) { + return formatDate(text.substring(5), new Date()) + } + const split = text.split('.') if (split.length !== 2) { - // Special handling for dates - if (split[0].startsWith('date:')) { - return formatDate(split[0].substring(5), new Date()) - } - if (text !== 'width' && text !== 'height') { - // Dont warn on standard replacements console.warn('Invalid replacement pattern', text) } return match } - // Find node with matching S&R property name let nodes = allNodes.filter( (n) => n.properties['Node name for S&R'] === split[0] ) - // If we can't, see if there is a node with that title if (!nodes.length) { nodes = allNodes.filter((n) => n.title === split[0]) } From 3994326c524bcc4f790385a8289dc39f570fa456 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Sikorski?= Date: Wed, 28 Oct 2026 21:34:28 +0100 Subject: [PATCH 2/3] fix: preserve date-prefixed node replacements --- src/utils/searchAndReplace.test.ts | 19 +++++++++++++++++++ src/utils/searchAndReplace.ts | 26 +++++++++++++++++--------- 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/src/utils/searchAndReplace.test.ts b/src/utils/searchAndReplace.test.ts index d473fd6132e..3a503601aed 100644 --- a/src/utils/searchAndReplace.test.ts +++ b/src/utils/searchAndReplace.test.ts @@ -13,6 +13,25 @@ function graphWithWidgetValue(value: string): LGraph { describe('applyTextReplacements', () => { describe('date replacements', () => { + it.for([ + { source: 'title', title: 'date:portrait', alias: 'PortraitNode' }, + { source: 'alias', title: 'PortraitNode', alias: 'date:portrait' } + ])( + 'preserves node references with a date-prefixed $source', + ({ title, alias }) => { + vi.setSystemTime(new Date(2026, 9, 28, 14, 5, 9)) + const graph = new LGraph() + const node = new LGraphNode(title) + node.properties['Node name for S&R'] = alias + node.addWidget('string', 'testWidget', 'portrait', () => undefined, {}) + graph.add(node) + + expect(applyTextReplacements(graph, '%date:portrait.testWidget%')).toBe( + 'portrait' + ) + } + ) + it.for([ ['yyyy-MM-dd', '2026-10-28'], ['yyyy.MM', '2026.10'], diff --git a/src/utils/searchAndReplace.ts b/src/utils/searchAndReplace.ts index 0df2e6027ac..90b65580162 100644 --- a/src/utils/searchAndReplace.ts +++ b/src/utils/searchAndReplace.ts @@ -9,16 +9,17 @@ export function applyTextReplacements( const allNodes = collectAllNodes(graph) return value.replace(/%([^%]+)%/g, function (match, text) { - if (text.startsWith('date:')) { - return formatDate(text.substring(5), new Date()) - } + const isDate = text.startsWith('date:') + const fallbackReplacement = isDate + ? formatDate(text.substring(5), new Date()) + : match const split = text.split('.') if (split.length !== 2) { - if (text !== 'width' && text !== 'height') { + if (!isDate && text !== 'width' && text !== 'height') { console.warn('Invalid replacement pattern', text) } - return match + return fallbackReplacement } let nodes = allNodes.filter( @@ -28,8 +29,8 @@ export function applyTextReplacements( nodes = allNodes.filter((n) => n.title === split[0]) } if (!nodes.length) { - console.warn('Unable to find node', split[0]) - return match + if (!isDate) console.warn('Unable to find node', split[0]) + return fallbackReplacement } if (nodes.length > 1) { @@ -40,8 +41,15 @@ export function applyTextReplacements( const widget = node.widgets?.find((w) => w.name === split[1]) if (!widget) { - console.warn('Unable to find widget', split[1], 'on node', split[0], node) - return match + if (!isDate) + console.warn( + 'Unable to find widget', + split[1], + 'on node', + split[0], + node + ) + return fallbackReplacement } return ((widget.value ?? '') + '').replaceAll( From 5b5941bdd5e287d831b2bd26e3d2f1520de8f674 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Sikorski?= Date: Wed, 28 Oct 2026 21:48:02 +0100 Subject: [PATCH 3/3] fix: keep unresolved widget references unchanged --- src/utils/searchAndReplace.test.ts | 19 +++++++++++++++++++ src/utils/searchAndReplace.ts | 11 ++--------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/utils/searchAndReplace.test.ts b/src/utils/searchAndReplace.test.ts index 3a503601aed..6eaba9a88a0 100644 --- a/src/utils/searchAndReplace.test.ts +++ b/src/utils/searchAndReplace.test.ts @@ -13,6 +13,25 @@ function graphWithWidgetValue(value: string): LGraph { describe('applyTextReplacements', () => { describe('date replacements', () => { + it('preserves a date-prefixed node reference when its widget is missing', () => { + vi.setSystemTime(new Date(2026, 9, 28, 14, 5, 9)) + const graph = new LGraph() + const node = new LGraphNode('date:portrait') + node.addWidget('string', 'renamedWidget', 'portrait', () => undefined, {}) + graph.add(node) + + expect(applyTextReplacements(graph, '%date:portrait.testWidget%')).toBe( + '%date:portrait.testWidget%' + ) + expect(console.warn).toHaveBeenCalledWith( + 'Unable to find widget', + 'testWidget', + 'on node', + 'date:portrait', + node + ) + }) + it.for([ { source: 'title', title: 'date:portrait', alias: 'PortraitNode' }, { source: 'alias', title: 'PortraitNode', alias: 'date:portrait' } diff --git a/src/utils/searchAndReplace.ts b/src/utils/searchAndReplace.ts index 90b65580162..282336ad67f 100644 --- a/src/utils/searchAndReplace.ts +++ b/src/utils/searchAndReplace.ts @@ -41,15 +41,8 @@ export function applyTextReplacements( const widget = node.widgets?.find((w) => w.name === split[1]) if (!widget) { - if (!isDate) - console.warn( - 'Unable to find widget', - split[1], - 'on node', - split[0], - node - ) - return fallbackReplacement + console.warn('Unable to find widget', split[1], 'on node', split[0], node) + return match } return ((widget.value ?? '') + '').replaceAll(