-
-
Notifications
You must be signed in to change notification settings - Fork 531
Fix file size calculation in modTransportPackage #16797
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 3.x
Are you sure you want to change the base?
Conversation
Strip size modifier (K,M,G) before bytes calculation
opengeek
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we should look at the functionality of https://www.php.net/manual/en/function.ini-parse-quantity.php to implement this properly to handle all valid shorthand forms allowed which represent byte values.
|
If you're meaning to use that method, we're not going to be able to do so until MODX's min required php is 8.2. |
I understand that. I meant we need to replicate the functionality of that method so that any valid value from php_ini is converted to a byte value correctly. |
|
I see, so do a polyfill of sorts—I figured you probably wouldn't blow past seeing the 8.2 requirement, but just in case ;-). But do you want to dig into that now or just do this simple little fix for the time being? If the former, then we might as well get the file stat gathering fixed up too. |
|
I'm not concerned about the file stat gathering here. My only intention is to fix the original issue without creating additional bugs, which this implementation currently does. There are several userland implementations of ini_parse_quantity out there. I'm merely suggesting that we use one of those as the implementation of _bytes() to fix the original issue and support all valid ini shorthand values that represent bytes. |
Improve logic for parsing the setting value
|
@opengeek - Ok, I've made a tweak to this minimal effort option. Let me preface what's coming with ... you know I'm all for the complete solution (maybe too much so at times), so I'm happy to work that up if you want to go that way. The Back to the complete solution: If you want to go "big" then we might want to consider creating a static conversion method in the modx class if not a polyfill for
One thing to note, the first userland polyfill I came across on php.watch doesn't even go as far as to convert non-decimal strings to decimal. (Just pointing that one out because you'd think an example shown there would be of the most complete ones.) I confirmed though that php's implementation does. Anywho, that was a book! |
|
I assume you mean integer above, rather than decimal? The userland implementation I was referring to is the one in Symfony's polyfill project. It is the only one that returns the same values you see in the samples from the PHP documentation for See the examples at https://www.php.net/manual/en/function.ini-parse-quantity.php and the implementation at https://github.com/symfony/polyfill/blob/ecf66edfc66a2566b876ba6b909ada51182508c3/src/Php82/Php82.php#L82 We don't currently have any polyfills and I'm not keen on adding such a feature into 3.x, but I think we could (in this case) simply add some global functions to handle this issue. BTW, this same _bytes() function implementation exists in modStaticResource. If you want, I can take a look at handling this issue. |
We're on the same page there. The nomenclature is tricky; php docs refer to the typical number representation as “decimal”—as all four reps of a number are technically an integer. And, yeah, I saw (and mentioned above) that I'll leave it to you, then. I do like the idea of just defining our own |
What does it do?
Strips size modifier (K,M,G) before calculation performed in the
_bytesmethod.Why is it needed?
A php warning occurs (and gets logged in MODX as an error) because the
_bytesfunction attempts to use the inimemory_limitvalue in a calculation without removing the modifier string (e.g., 128M *= 1024). This triggers the “A non-numeric value encountered” warning.How to test
Related issue(s)/PR(s)
Resolves #16504.
Note that the second warning re filesize could not be replicated (for my environ at least), although there needs to be a bit of redesign done in general with how files are read and stats are accessed; basically, everywhere that uses error suppression via the @ operator should be refactored to avoid these errors and warnings in general. This should be done in a different PR though.