Skip to content
This repository

sprintf complains unless the correct number of arguments are passed #1720

Merged
merged 1 commit into from over 1 year ago

5 participants

Elijah Madden Nikolai Plath Andrew Eddie elinw AmyStephen
Elijah Madden

An undefined variable was being passed to JText::sprintf in two places. This was fixed a little while ago, in one case it was replaced but in another it was omitted. Since sprintf throws a warning when the format uses numbered arguments but insufficient arguments are passed to the function... we need to pass something. Luckily, there is already a suitable string: JLIB_APPLICATION_ERROR_COMPONENT_NOT_FOUND

libraries/legacy/component/helper.php
... ... @@ -397,7 +397,7 @@ protected static function _load($option)
397 397 if (empty(self::$components[$option]))
398 398 {
399 399 // Fatal error.
400   - JLog::add(JText::sprintf('JLIB_APPLICATION_ERROR_COMPONENT_NOT_LOADING', $option), JLog::WARNING, 'jerror');
  400 + JLog::add(JText::sprintf('JLIB_APPLICATION_ERROR_COMPONENT_NOT_LOADING', $option, JText::_('JLIB_APPLICATION_ERROR_COMPONENT_NOT_FOUND')), JLog::WARNING, 'jerror');
1

I have a feeling the length of this line is just over the limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Elijah Madden

Is there a rule about that? phpcs didn't complain.

Nikolai Plath

It should generate a warning if the line contains more than 150 chars.

Maybe we should change that to error ?

Andrew Eddie

My personal rule-of-thumb is 120 characters (which gives me a bugger between 120 and 150 if I really need it). The reason is that 120 chars fits really well in the github code windows.

Elijah Madden

I hope you mean buffer. Anyway, I didn't get a warning but the line was surely over the 150 character limit. I've broken it up into two.

Andrew Eddie eddieajau merged commit ec2677e into from
Andrew Eddie

Oops (blush). Merged. Thanks.

elinw

I wanted to mention about this that the removal of that $error was also done during thee 12.2 to 12.3 period (#1572), but clearly without being positive what the implications are. And not to be a harpie about testing but ... we should not be doing things like that without serious unit tests in place especially in the legacy folder where applications are particularly counting on stability.

AmyStephen

What is unfortunate is that everyone missed @ianmacl 's message at the time. Looks like he saw this right away.

But, in all fairness, the application was better off after the patch. It fixed one of two problems. Removing the second undefined variable basically turned in one warning for another. Still, +1 in the overall count. ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 2 additions and 1 deletion. Show diff stats Hide diff stats

  1. +2 1  libraries/legacy/component/helper.php
3  libraries/legacy/component/helper.php
@@ -397,7 +397,8 @@ protected static function _load($option)
397 397 if (empty(self::$components[$option]))
398 398 {
399 399 // Fatal error.
400   - JLog::add(JText::sprintf('JLIB_APPLICATION_ERROR_COMPONENT_NOT_LOADING', $option), JLog::WARNING, 'jerror');
  400 + $error = JText::_('JLIB_APPLICATION_ERROR_COMPONENT_NOT_FOUND');
  401 + JLog::add(JText::sprintf('JLIB_APPLICATION_ERROR_COMPONENT_NOT_LOADING', $option, $error), JLog::WARNING, 'jerror');
401 402
402 403 return false;
403 404 }

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.