-
Notifications
You must be signed in to change notification settings - Fork 41
Open
backdrop/backdrop
#5085Description
Description of the bug
A fatal error can happen when the pager attempts to add a string and int together:
TypeError: Unsupported operand types: int + string in views_plugin_pager_full->query() (line 265 of C:\wamp64\www\[...]\httpdocs\core\modules\views\plugins\views_plugin_pager_full.inc).
Steps To Reproduce
I'm not sure if this is completely reproduceable on a fresh system, but on our client's development installation, just opening /admin/structure/layouts/manage/default
will cause the error.
To reproduce on a vanilla install of Backdrop:
- Create a bunch of nodes (e.g. with Devel Generate, more than 10)
- Create a simple View that shows nodes, with a pager (10 items e.g.)
- Head to the Pager configuration of the View and remove the "0" under offset (leave that field blank).
- Save the View and visit it. You'll see the same Fatal error
Actual behavior
A Fatal Error occurs.
Expected behavior
Layout admin interface loads.
Additional information
Add any other information that could help, such as:
- Backdrop CMS version: 1.31
- Web server and its version: apache 2.4.54
- PHP version: 8.0+ (tested with 8.0, 8.1, 8.2 and 8.3)
- Database sever (MySQL or MariaDB?) and its version: MariaDB Version: 10.11.11
- Operating System and its version: Windows NT 10.0 build 19045 (Windows 10) AMD64
The issue is in the query()
function:
function query() {
if ( $this->items_per_page_exposed() && !empty($_GET['items_per_page']) ) {
if ( is_numeric($_GET['items_per_page']) && $_GET['items_per_page'] > 0 ) {
$this->options['items_per_page'] = $_GET['items_per_page'];
}
else if ( $_GET['items_per_page'] == 'All' && $this->options['expose']['items_per_page_options_all'] ) {
$this->options['items_per_page'] = 0;
}
}
if ( $this->offset_exposed() ) {
if ( isset($_GET['offset']) && $_GET['offset'] >= 0 ) {
$this->options['offset'] = $_GET['offset'];
}
}
$limit = $this->options['items_per_page'];
$offset = $this->current_page * $this->options['items_per_page'] + $this->options['offset'];
if ( !empty($this->options['total_pages']) ) {
if ( $this->current_page >= $this->options['total_pages'] ) {
$limit = $this->options['items_per_page'];
$offset = $this->options['total_pages'] * $this->options['items_per_page'];
}
}
$this->view->query->set_limit($limit);
$this->view->query->set_offset($offset);
}
Adding typecasting to the $offset
will fix the error:
$offset = (int) $this->current_page * (int) $this->options['items_per_page'] + (int) $this->options['offset'];