- Issue created by @rondog469
- 🇺🇸United States rondog469
looking more into this issue, with this patch I can now edit my user picture field and this problem has to stem from migrating. The file size value set on this field is just "KB". The is incorrect. Even though the display value on the field's file size limit is just "KB", when I output `$size` its "1024".
Again, this issue must stem from migrating, but I also think $size should still be casted as a number anyway.
- 🇫🇷France andypost
It could use to add type checking and throw deprecation if the
$size
is notint|float
and in D11 we can add type hint to function - Status changed to Needs review
over 1 year ago 6:26pm 6 April 2023 - Status changed to Needs work
over 1 year ago 6:56pm 6 April 2023 - 🇺🇸United States smustgrave
Would like to know the exact scenario that is triggering this. If it's a bad contrib module.
But like the idea @andypost suggested of adding a type check and throw deprecation.
Then a test case to reflect that.
- 🇳🇿New Zealand danielveza Brisbane, AU
I don't think we can typehint the function because it's valid to pass a string - E.g. '1MB'
What about throwing a LogicException if the passed string can't be converted to a number? Attached a patch as a POC. This approach seems to make sense because if you pass an invalid string currently you get an exception, so this at least makes it more clear what the problem is.
- 🇺🇸United States rondog469
@smutgrave, I dont know the exact scenario, but this happened when viewing the user profile picture field after migrating a drupal 7 site to drupal 9. On the d7 site the field in question did not have a size set. After migrating the size value of the field was set to just "KB", no number prepended to it.
- 🇫🇷France andypost
Closed as duplicate 📌 Bytes::toNumber($size) will throw warning is $size failed to parse Closed: duplicate
- Status changed to Needs review
over 1 year ago 10:43am 7 July 2023 - last update
over 1 year ago 29,802 pass - Status changed to Needs work
over 1 year ago 3:23pm 7 July 2023 - 🇺🇸United States smustgrave
Please read the tags and apply interdiffs
Also you patch seems to be removing things from #7 without explanation.
Tests are still needed