User tests: Successful: Unsuccessful:
Pull Request resolves #44687.
I read the Generative AI policy and my contribution is compatible with the policy and GNU/GPL 2 or later.
Fixes an issue in Text::sprintf() where the options array (e.g. ["script" => true]) was not removed from the argument list before calling sprintf().
As a result, the options array was incorrectly passed as an extra formatting argument, which could lead to incorrect or unexpected output.
The fix extracts the options array using array_pop($args) and stores it separately, ensuring that only valid formatting arguments are passed to sprintf().
Execute:
echo \Joomla\CMS\Language\Text::sprintf("MOD_EXAMPLE_ARGS_EXAMPLE", 12, ["script" => true]);Verify:
PHP output returns the key: MOD_EXAMPLE_ARGS_EXAMPLE
In browser console:
joomla.jtext["MOD_EXAMPLE_ARGS_EXAMPLE"]returns the correctly formatted string (e.g. "Trying to use 12 inside JavaScript" if translation exists)
Test normal usage:
echo \Joomla\CMS\Language\Text::sprintf("MOD_EXAMPLE_ARGS_EXAMPLE", 12);Test other options:
echo \Joomla\CMS\Language\Text::sprintf("MOD_EXAMPLE_ARGS_EXAMPLE", 12, ["jsSafe" => true]);Optional: Define a language string with %s and verify that formatting works correctly.
$argssprintf() as an extra argumentsprintf()script => true is used, the formatted string is correctly registered in joomla.jtextNo documentation changes for guide.joomla.org needed
No documentation changes for manual.joomla.org needed
I have read the Generative AI policy.
This contribution was developed with the assistance of AI tools for analysis and validation. The root cause was identified by tracing the execution flow and confirming that the options array was not removed before formatting.
All code changes, testing, and final implementation decisions were reviewed and validated manually.
I confirm that:
| Status | New | ⇒ | Pending |
| Category | ⇒ | Libraries |
Thanks for pointing that out.
I’ll update the PR to strictly follow the provided template.
does this also fix the other related issues mentioned by @Fedik #44687 (comment)
| Labels |
Added:
PR-5.4-dev
|
||
Thanks for the feedback.
I’ve fixed the code style issues and pushed the updates. Please let me know if any further changes are needed.
does this also fix the other related issues mentioned by @Fedik #44687 (comment)
does this also fix the other related issues mentioned by @Fedik #44687 (comment)
Thanks for pointing that out.
This fix specifically addresses Text::sprintf() by ensuring the options array is removed before calling sprintf().
From reviewing the related methods:
Text::plural() follows a similar argument handling pattern and may require the same fix.Text::passSprintf() uses a different implementation and does not accept an options array, so the issue does not apply in the same way.I can look into applying a similar fix to Text::plural() if needed.
I can look into applying a similar fix to Text::plural() if needed.
yes please
Sure, I’ll extend the fix to Text::plural() as well.
| Title |
|
||||||
@bharath110520 Thank you for your contribution. Please also fix the PHP code style errors.
does this also fix the other related issues mentioned by @Fedik #44687 (comment)
Yeah, that seems fixed it.
@bharath110520 Please pay attention how Text::script() works, and fix all HTMLHelper::_('behavior.core'); you added here.
The $key in $strings[strtoupper($key)] and static::$strings[$key] must be equal.
It was not for fun that you were given a template to complete when you submitted your pull request