fix: disable pipe/filter feature to prevent breaking macros with pipe characters in arguments (#5644)

Temporarily commented out Filter.Pipe and Filter.EscapedPipe token handling in MacroLexer to fix issue where pipe characters in argument values (e.g., {{setvar::foo::|bar}}) were incorrectly parsed as filter operators. Added regression tests for pipe handling in argument values and skipped existing output modifier tests until filter flag (>) logic is properly implemented.

Resolves: #5618
This commit is contained in:
Wolfsblvt
2026-05-18 19:56:38 +03:00
committed by GitHub
parent 45d166ff6a
commit 355598bb30
2 changed files with 52 additions and 3 deletions
+7 -2
View File
@@ -214,11 +214,16 @@ const Def = {
// Macro args allow nested macros
enter(Tokens.Macro.Start, modes.macro_def),
// PIPE/FILTER FEATURE DISABLED: Lines below commented out until pipe/filter feature is fully implemented.
// Currently, having these active breaks macros that use | as a regular character in argument values (e.g., {{setvar::foo::|bar}})
// See: https://github.com/SillyTavern/SillyTavern/issues/5618
// TODO: Re-enable when filter flag (>) logic is properly implemented to conditionally enable pipe parsing
// We allow escaped pipes to not start output modifiers. We need to capture this first, before the pipe
using(Tokens.Filter.EscapedPipe),
// using(Tokens.Filter.EscapedPipe),
// If at any place during args writing there is a pipe, we lex it as an output identifier, and then continue with lex its args
enter(Tokens.Filter.Pipe, modes.macro_filter_modifer),
// enter(Tokens.Filter.Pipe, modes.macro_filter_modifer),
using(Tokens.Args.DoubleColon),
using(Tokens.Args.Colon),
+45 -1
View File
@@ -508,6 +508,49 @@ test.describe('MacroLexer', () => {
expect(tokens).toEqual(expectedTokens);
});
// TODO: test invalid argument name identifiers
// REGRESSION TEST: https://github.com/SillyTavern/SillyTavern/issues/5618
// {{setvar::foo::|bar}} - pipe character should NOT be treated as Filter.Pipe (which breaks parsing)
test('should handle pipe character in argument values (issue #5618)', async ({ page }) => {
const input = '{{setvar::foo::|bar}}';
const tokens = await runLexerGetTokens(page, input);
const expectedTokens = [
{ type: 'Macro.Start', text: '{{' },
{ type: 'Macro.Identifier', text: 'setvar' },
{ type: 'Args.DoubleColon', text: '::' },
{ type: 'Identifier', text: 'foo' },
{ type: 'Args.DoubleColon', text: '::' },
// Pipe is captured as Unknown (not Filter.Pipe), which allows the macro to parse correctly
{ type: 'Unknown', text: '|' },
{ type: 'Identifier', text: 'bar' },
{ type: 'Macro.End', text: '}}' },
];
expect(tokens).toEqual(expectedTokens);
});
// Test multiple pipes in argument values
test('should handle multiple pipe characters in argument values', async ({ page }) => {
const input = '{{setvar::key::a|b|c}}';
const tokens = await runLexerGetTokens(page, input);
const expectedTokens = [
{ type: 'Macro.Start', text: '{{' },
{ type: 'Macro.Identifier', text: 'setvar' },
{ type: 'Args.DoubleColon', text: '::' },
{ type: 'Identifier', text: 'key' },
{ type: 'Args.DoubleColon', text: '::' },
{ type: 'Identifier', text: 'a' },
{ type: 'Unknown', text: '|' },
{ type: 'Identifier', text: 'b' },
{ type: 'Unknown', text: '|' },
{ type: 'Identifier', text: 'c' },
{ type: 'Macro.End', text: '}}' },
];
expect(tokens).toEqual(expectedTokens);
});
});
test.describe('Macro Execution Modifiers', () => {
@@ -931,7 +974,8 @@ test.describe('MacroLexer', () => {
});
});
test.describe('Macro Output Modifiers', () => {
// SKIPPED: Pipe/filter feature temporarily disabled. See https://github.com/SillyTavern/SillyTavern/issues/5618
test.describe.skip('Macro Output Modifiers', () => {
// {{macro | outputModifier}}
test('should support output modifier without arguments', async ({ page }) => {
const input = '{{macro | outputModifier}}';