Skip to content

fix: reassemble comma-in-parens formatters at any chain position#2437

Merged
adrai merged 1 commit into
i18next:masterfrom
spokodev:fix/chained-formatter-comma-in-parens
Jun 24, 2026
Merged

fix: reassemble comma-in-parens formatters at any chain position#2437
adrai merged 1 commit into
i18next:masterfrom
spokodev:fix/chained-formatter-comma-in-parens

Conversation

@spokodev

Copy link
Copy Markdown
Contributor

Problem

Chained formatters support parenthesised options that may contain the format separator, for example join(separator: ', '). When such a formatter is split on the separator, the option fragments have to be rejoined before parsing.

Today that reassembly only runs for formats[0]. A formatter whose parenthesised options contain the separator therefore works only when it is first in the chain:

// works
{{v, join(separator: ', '), uppercase}}

// broken: corrupt output
{{v, uppercase, join(separator: ', ')}}

In the broken case the join(separator: ', ') fragment is split into join(separator: ' ' and ')', never rejoined, and the value comes out corrupted (e.g. ANaNB).

Fix

Replace the formats[0]-only repair with a single position-independent pass: walk the split fragments and, whenever a fragment opens a paren that is not yet closed, keep appending following fragments (re-inserting the separator) until the paren closes. This reassembles comma-in-parens options at any position in the chain. The downstream formats.reduce(...) is unchanged.

Tests

Added a regression test in test/runtime/i18next.translation.formatting.test.js exercising a chain where the comma-in-parens formatter is not first ({{myVar, upper, join(separator: ', ')}} with ['a','b'] -> A, B).

  • Before the fix, the new test fails (Hello ANaNB).
  • After the fix it passes, and the full runtime suite stays green.

Chained formatters support parenthesised options that may contain the
format separator (e.g. join(separator: ', ')). The reassembly that
rejoins such split fragments only ran for formats[0], so a formatter
with comma-in-parens options anywhere other than first produced corrupt
output (e.g. {{v, upper, join(separator: ', ')}} yielded 'ANaNB').

Reassemble fragments in a single position-independent pass so options
containing the separator are handled at any position in the chain.
@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 94.985% (+0.008%) from 94.977% — spokodev:fix/chained-formatter-comma-in-parens into i18next:master

@adrai adrai merged commit 6901e04 into i18next:master Jun 24, 2026
9 checks passed
adrai added a commit that referenced this pull request Jun 24, 2026
@adrai

adrai commented Jun 24, 2026

Copy link
Copy Markdown
Member

thx.... merged and included in v26.3.2

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.

3 participants