Ori.livneh has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/306804

Change subject: Handle string input in humanSize()
......................................................................

Handle string input in humanSize()

The $.isNumeric( bytes ) in humanSize() is not enough to ensure that bytes is a
number, because $.isNumeric() (by design) returns true for string
representation of numbers, like '14.2'. Fix this by casting strings to number.
Also remove the special-casing of 0 -- it's OK to just let it fall through.
(The alternative would be to check for either 0 or '0').

Change-Id: I7547a8534d6c496d6e68da8a91a62c4f02098714
---
M modules/collectors/ext.PerformanceInspector.imagesize.js
M modules/collectors/ext.PerformanceInspector.modulessize.js
2 files changed, 12 insertions(+), 2 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/PerformanceInspector 
refs/changes/04/306804/1

diff --git a/modules/collectors/ext.PerformanceInspector.imagesize.js 
b/modules/collectors/ext.PerformanceInspector.imagesize.js
index c696d4f..3df17d2 100644
--- a/modules/collectors/ext.PerformanceInspector.imagesize.js
+++ b/modules/collectors/ext.PerformanceInspector.imagesize.js
@@ -20,9 +20,14 @@
                        var i = 0,
                                units = [ '', ' KiB', ' MiB', ' GiB', ' TiB', ' 
PiB' ];
 
-                       if ( !$.isNumeric( bytes ) || bytes === 0 ) {
+                       if ( !$.isNumeric( bytes ) ) {
                                return bytes;
                        }
+
+                       if ( typeof bytes === 'string' ) {
+                               bytes = parseFloat( bytes );
+                       }
+
                        for ( ; bytes >= 1024; bytes /= 1024 ) {
                                i++;
                        }
diff --git a/modules/collectors/ext.PerformanceInspector.modulessize.js 
b/modules/collectors/ext.PerformanceInspector.modulessize.js
index de0699c..815ad6d 100644
--- a/modules/collectors/ext.PerformanceInspector.modulessize.js
+++ b/modules/collectors/ext.PerformanceInspector.modulessize.js
@@ -9,9 +9,14 @@
                        var i = 0,
                                units = [ '', ' KiB', ' MiB', ' GiB', ' TiB', ' 
PiB' ];
 
-                       if ( !$.isNumeric( bytes ) || bytes === 0 ) {
+                       if ( !$.isNumeric( bytes ) ) {
                                return bytes;
                        }
+
+                       if ( typeof bytes === 'string' ) {
+                               bytes = parseFloat( bytes );
+                       }
+
                        for ( ; bytes >= 1024; bytes /= 1024 ) {
                                i++;
                        }

-- 
To view, visit https://gerrit.wikimedia.org/r/306804
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7547a8534d6c496d6e68da8a91a62c4f02098714
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/PerformanceInspector
Gerrit-Branch: master
Gerrit-Owner: Ori.livneh <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to