Skip to content

fix: apply pipe filters in SET/DEFAULT directives (GH #174)#429

Open
toddr-bot wants to merge 1 commit into
mainfrom
koan.toddr.bot/fix-set-pipe-filter
Open

fix: apply pipe filters in SET/DEFAULT directives (GH #174)#429
toddr-bot wants to merge 1 commit into
mainfrom
koan.toddr.bot/fix-set-pipe-filter

Conversation

@toddr-bot
Copy link
Copy Markdown
Contributor

What

Pipe filters now work correctly with SET and DEFAULT directives.

Why

[% SET foo = "foo bar" | uri %] assigned "foo bar" unfiltered to foo, while
[% foo = "foo bar" | uri %] (without SET) correctly applied the filter. This
inconsistency has been open since 2010 (rt.cpan.org#59208, GH #174).

The root cause: SET forces parsing through setlistassignexpr, but expr
doesn't include FILTER as an operator. The FILTER token was consumed by the outer
atomexpr FILTER lnameargs rule, wrapping the entire SET directive's output (empty
string) through the filter instead of filtering the assigned value.

How

Added filter-aware assignment rules scoped to SET and DEFAULT in the atomdir
grammar production. A new filter_expr() method in Directive.pm generates filter
code that returns the filtered value as an expression. Grammar changes are scoped to
avoid interfering with the capture: ident ASSIGN mdir path used by implicit assignments.

Testing

  • New t/set-filter.t with 11 test cases covering SET, DEFAULT, implicit, expressions, and regressions
  • Full test suite passes (3192 tests)

Closes #174

🤖 Generated with Claude Code

@toddr-bot
Copy link
Copy Markdown
Contributor Author

Recreated from #380 (auto-closed when the toddr-bot fork was removed). Original branch is now hosted on this repo.

@toddr
Copy link
Copy Markdown
Member

toddr commented May 24, 2026

@toddr-bot rebase

1 similar comment
@toddr
Copy link
Copy Markdown
Member

toddr commented May 24, 2026

@toddr-bot rebase

When using SET or DEFAULT with a pipe filter (e.g. SET foo = "bar" | uri),
the filter was applied to the output of the SET directive rather than to
the value being assigned. This meant the variable received the unfiltered
value while the filter operated on empty output.

Add filter-aware assignment rules scoped to SET and DEFAULT in the atomdir
grammar production. Add filter_expr() to Directive.pm to generate filter
code that returns the filtered value as an expression rather than appending
to output. Regenerate Grammar.pm from the updated Parser.yp.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@toddr-bot
Copy link
Copy Markdown
Contributor Author

Rebase with requested adjustments

Branch koan.toddr.bot/fix-set-pipe-filter was rebased onto main and review feedback was applied.

Stats

4 files changed, 4565 insertions(+), 4278 deletions(-)
Actions performed

CI status

CI will be checked asynchronously.


Automated by Kōan

@toddr-bot toddr-bot force-pushed the koan.toddr.bot/fix-set-pipe-filter branch from 214cbe4 to 1324960 Compare May 24, 2026 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

explicit setting of a variable does not seem to work with pipe based filters [rt.cpan.org #59208]

2 participants