PR-5.4-dev Pending

User tests: Successful: Unsuccessful:

avatar bharath110520
bharath110520
30 Mar 2026

Pull Request resolves #44687.

I read the Generative AI policy and my contribution is compatible with the policy and GNU/GPL 2 or later.


Summary of Changes

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().


Testing Instructions

  1. Execute:

    echo \Joomla\CMS\Language\Text::sprintf("MOD_EXAMPLE_ARGS_EXAMPLE", 12, ["script" => true]);
  2. 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)

  3. Test normal usage:

    echo \Joomla\CMS\Language\Text::sprintf("MOD_EXAMPLE_ARGS_EXAMPLE", 12);
  4. Test other options:

    echo \Joomla\CMS\Language\Text::sprintf("MOD_EXAMPLE_ARGS_EXAMPLE", 12, ["jsSafe" => true]);
  5. Optional: Define a language string with %s and verify that formatting works correctly.


Actual result BEFORE applying this Pull Request

  • The options array was not removed from $args
  • It was passed into sprintf() as an extra argument
  • This could lead to incorrect formatting or unexpected results

Expected result AFTER applying this Pull Request

  • The options array is removed before calling sprintf()
  • Only valid formatting arguments are passed
  • The formatted string is correct
  • When script => true is used, the formatted string is correctly registered in joomla.jtext
  • No regression in existing behavior

Link to documentations

No documentation changes for guide.joomla.org needed

No documentation changes for manual.joomla.org needed


AI usage

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:

  • The code is understood and verified by me
  • It complies with GNU/GPL v2 or later
  • No proprietary or copyrighted code is included
  • The implementation has been tested and behaves as expected
avatar bharath110520 bharath110520 - open - 30 Mar 2026
avatar bharath110520 bharath110520 - change - 30 Mar 2026
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 30 Mar 2026
Category Libraries
avatar brianteeman
brianteeman - comment - 30 Mar 2026

It was not for fun that you were given a template to complete when you submitted your pull request

avatar bharath110520
bharath110520 - comment - 30 Mar 2026

Thanks for pointing that out.

I’ll update the PR to strictly follow the provided template.

avatar bharath110520 bharath110520 - change - 30 Mar 2026
The description was changed
avatar bharath110520 bharath110520 - edited - 30 Mar 2026
avatar brianteeman
brianteeman - comment - 30 Mar 2026

does this also fix the other related issues mentioned by @Fedik #44687 (comment)

avatar bharath110520 bharath110520 - change - 30 Mar 2026
Labels Added: PR-5.4-dev
avatar bharath110520
bharath110520 - comment - 30 Mar 2026

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.

avatar bharath110520
bharath110520 - comment - 30 Mar 2026

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.

avatar brianteeman
brianteeman - comment - 30 Mar 2026

I can look into applying a similar fix to Text::plural() if needed.

yes please

avatar bharath110520
bharath110520 - comment - 30 Mar 2026

Sure, I’ll extend the fix to Text::plural() as well.

avatar muhme muhme - change - 30 Mar 2026
Title
Fix: Remove options array before sprintf() in Text::sprintf()
[5.4] Remove options array before sprintf() in Text::sprintf()
avatar muhme muhme - edited - 30 Mar 2026
avatar muhme
muhme - comment - 30 Mar 2026

@bharath110520 Thank you for your contribution. Please also fix the PHP code style errors.

avatar Fedik
Fedik - comment - 31 Mar 2026

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.

Add a Comment

Login with GitHub to post a comment