fix(pipeline/template): preserve commas in replace() filter replacement value#1917
Open
Chen17-sq wants to merge 1 commit into
Open
fix(pipeline/template): preserve commas in replace() filter replacement value#1917Chen17-sq wants to merge 1 commit into
Chen17-sq wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The
replace(old, new)pipeline template filter truncates any replacement value that contains a comma. For example:returns
'x'instead of the expected'x,y'.Root cause
src/pipeline/template.ts:103(pre-fix) split the raw filter arguments on every comma:replace('a', 'x,y')hasrawArgs === "'a', 'x,y'", whichsplit(',')turns into["'a'", " 'x", "y'"]. Onlyparts[0](a) andparts[1](x) are used, so the replacement is silently truncated at the first comma in the value.Fix
Split on the first comma only, treating everything after it as the replacement value:
This makes replacement values containing commas work while keeping existing behavior for simple args (single-comma usage, non-string passthrough, single-arg no-op). Quote-stripping and
replaceAllsemantics are unchanged.Tests
Added five co-located unit tests in
src/pipeline/template.test.ts(theevalExprfilter block had no priorreplacecoverage, so there is zero regression risk):replace('foo','bar')on'foo baz'->'bar baz'replace('a','x,y')on'a'->'x,y'replace(' ','_')on'a b c'->'a_b_c'42->42)replace('a')returns the value unchangednpx vitest run src/pipeline/template.test.ts: 57 passing (52 baseline + 5 new).tsc --noEmitclean. The existingjoin(,)test is on a separate code path and is unaffected.Scope
Single-concern: this PR fixes only the
replace-filter comma splitting. Two related items are deliberately left out to keep the change surgical:replace(',', ';')) remains unsupported by design — the comma is the argument separator. This fix only guarantees the replacement value may contain commas.|-in-filter-args concern (e.g.join(|), handled by the pipe tokenizer attemplate.ts:43) is out of scope; addressing it would require a paren-aware change to the hot-path tokenizer and turn this into a two-concern parser PR. It can be a follow-up if there is demand.A full quoted-arg parser was intentionally avoided to keep the diff small and low-risk.