Fixed castValueToColumnType can throw "[E_WARNING] A non-numeric value encountered"

Xon

Well-known member
Affected version
2.1.8
Because filterCriteria/validateCriteriaValue do not discard malformed numerical values, this causes castValueToColumnType to trigger an a "[E_WARNING] A non-numeric value encountered" when given a non-numerical string for a numerical field.

Example error;
Code:
ErrorException: [E_WARNING] A non-numeric value encountered src/XF/Searcher/AbstractSearcher.php:488
Stack trace
#0 src/XF/Searcher/AbstractSearcher.php(488): XF::handlePhpError(2, '[E_WARNING] A n...', '/var/www/sites/...', 488, Array)
#1 src/XF/Searcher/AbstractSearcher.php(442): XF\Searcher\AbstractSearcher->castValueToColumnType('test', 2)
#2 src/XF/Searcher/AbstractSearcher.php(397): XF\Searcher\AbstractSearcher->applyCriteriaValue(Object(DBTech\eCommerce\Finder\Order), 'order_id', 'test', Array, NULL, NULL)
#3 src/XF/Searcher/AbstractSearcher.php(364): XF\Searcher\AbstractSearcher->applyCriteria(Object(DBTech\eCommerce\Finder\Order), Array)
#4 src/addons/DBTech/eCommerce/Admin/Controller/Log.php(162): XF\Searcher\AbstractSearcher->getFinder()
#5 src/XF/Mvc/Dispatcher.php(350): DBTech\eCommerce\Admin\Controller\Log->actionOrder(Object(XF\Mvc\ParameterBag))
#6 src/XF/Mvc/Dispatcher.php(257): XF\Mvc\Dispatcher->dispatchClass('DBTech\\eCommerc...', 'Order', Object(XF\Mvc\RouteMatch), Object(DBTech\eCommerce\Admin\Controller\Log), NULL)
#7 src/XF/Mvc/Dispatcher.php(113): XF\Mvc\Dispatcher->dispatchFromMatch(Object(XF\Mvc\RouteMatch), Object(DBTech\eCommerce\Admin\Controller\Log), NULL)
#8 src/XF/Mvc/Dispatcher.php(55): XF\Mvc\Dispatcher->dispatchLoop(Object(XF\Mvc\RouteMatch))
#9 src/XF/App.php(2184): XF\Mvc\Dispatcher->run()
#10 src/XF.php(391): XF\App->run()
#11 admin.php(13): XF::runApp('XF\\Admin\\App')
#12 {main}

Triggering code;
PHP:
			case Entity::INT:
			case Entity::UINT:
			case Entity::FLOAT:
				return $value + 0;

It feels like XF\Mvc\Entity\ValueFormatter::castValueToType should be called instead of the contents of castValueToColumnType, or the very least more checks added.

But the bug is that there isn't any feedback on the blatantly invalid value passed into AbstractSearcher via extracting column named fields from the response.
 
Thank you for reporting this issue, it has now been resolved. We are aiming to include any changes that have been made in a future XF release (2.1.10).

Change log:
Ensure integer and float values are correctly casted when using searchers
There may be a delay before changes are rolled out to the XenForo Community.
 
Back
Top Bottom