Joomla 3.6.5
PHP 5.6
Apache/Lightspeed
This bug was fixed in #1872 but reintroduced in #3202 .
/libraries/joomla/cache/storage/helper.php
The working code was:
$this->size = number_format((float) $this->size + (float) $size, 2, '.', '');
This was changed to the current code:
$this->size = number_format((float) $this->size + (float) $size, 2, JText::_('DECIMALS_SEPARATOR'), JText::_('THOUSANDS_SEPARATOR'));
This change was done for numeric localization reasons, however, the number at this point is not an end-user facing number. It's just a numeric value being stored/modified. Because of the casting from(float) $this->size
there will be issues...
This is the issue with using the thousands separator, the number will get cut off at the first comma found:
$this->size = "1,234.56"; // number with a thousands separator
$this->size = (float)$this->size;
echo $this->size; // outputs: 1
This is the issue for the decimal separator:
$this->size = "1.234,56"; // localized number format
$this->size = (float)$this->size;
echo $this->size; // outputs: 1.234
For the second issue, I believe this is the case because the (float) casting does not take the localization into account (ie, I believe it always assumes the decimal separator is a period). See http://php.net/manual/en/language.types.float.php (particularly the "formal" definition near the top that has the algorithm). That could just be a simplified definition though and there is in fact localization support in the underlying code, I don't know.
For those reasons I believe the code should go back to:
$this->size = number_format((float) $this->size + (float) $size, 2, '.', '');
I'm not really sure why number_format() is even being used here. It might actually be better to change it to $this->size += $size
.
The place for localization of the value should be when being outputted:
<?php echo JHtml::_('number.bytes', $item->size*1024); ?>
number.bytes does not do the localization either but that is the logical place for it (IMO); Final calculations on the value are being done and then the value is formatted to a string for display.
I can make a pull request for both files/issues but I wanted input first. If someone else wants to do it that's fine too.
Labels |
Added:
?
|
Category | ⇒ | Cache |
Status | New | ⇒ | Information Required |
Status | Information Required | ⇒ | Closed - No Reply |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2017-05-27 10:34:43 |
Closed_By | ⇒ | franz-wohlkoenig |
Status | Closed - No Reply | ⇒ | Information Required |
Status | Information Required | ⇒ | Closed |
Closed_By | franz-wohlkoenig | ⇒ | joomla-cms-bot |
Set to "closed" on behalf of @franz-wohlkoenig by The JTracker Application at issues.joomla.org/joomla-cms/14014
This has been closed due to lack of response to the requests above – it can always be reopened in the future if it is updated.
@drewgg can you please confirm Issue on latest staging?
This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/14014.