transloco icon indicating copy to clipboard operation
transloco copied to clipboard

Bug(transpiler): FunctionalTranspiler is too greedy when parsing functions

Open Kleyguerth opened this issue 2 years ago • 0 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Which Transloco package(s) are the source of the bug?

Transloco

Is this a regression?

No

Current behavior

When I try to use two functions in the same translation, the functional transpiler picks everything from the first function up to the second function as a single function call.

I'm providing lodash's function "startCase", which removes symbols and capitalizes the first character of each word. The translation

first [[startCase(second)]] third [[startCase(fourth)]] fifth

results in

first Second Third Start Case Fourth fifth

Expected behavior

first [[startCase(second)]] third [[startCase(fourth)]] fifth

should become

first Second third Fourth fifth

Please provide a link to a minimal reproduction of the bug

Transloco Config

No response

Please provide the environment you discovered this bug in

Transloco: 4.1.1
Angular: 13.2.4
Package Manager: npm
OS: Linux

Browser

No response

Additional context

I believe this is caused by the regex /\[\[\s*(\w+)\((.*)\)\s*]]/g used in the transpiler, changing it to /\[\[\s*(\w+)\((.*?)\)\s*]]/g solves this issue but I don't know if that would cause other issues

I would like to make a pull request for this bug

No

Kleyguerth avatar Aug 10 '22 18:08 Kleyguerth