Skip to content
Snippets Groups Projects
Unverified Commit efa73ebf authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3489538 by mondrake, daffie, alexpott:...

Issue #3489538 by mondrake, daffie, alexpott: StatementPrefetchIterator::fetchField fails silently if the column index is out of range
parent 28c7686a
Branches
Tags
11 merge requests!11197Issue #3506427 by eduardo morales alberti: Remove responsive_image.ajax from hook,!11131[10.4.x-only-DO-NOT-MERGE]: Issue ##2842525 Ajax attached to Views exposed filter form does not trigger callbacks,!10786Issue #3490579 by shalini_jha, mstrelan: Add void return to all views...,!3878Removed unused condition head title for views,!3818Issue #2140179: $entity->original gets stale between updates,!3154Fixes #2987987 - CSRF token validation broken on routes with optional parameters.,!2964Issue #2865710 : Dependencies from only one instance of a widget are used in display modes,!2062Issue #3246454: Add weekly granularity to views date sort,!10223132456: Fix issue where views instances are emptied before an ajax request is complete,!617Issue #3043725: Provide a Entity Handler for user cancelation,!579Issue #2230909: Simple decimals fail to pass validation
Pipeline #351968 passed with warnings
Pipeline: drupal

#351990

    Pipeline: drupal

    #351984

      Pipeline: drupal

      #351971

        ......@@ -99,11 +99,17 @@ protected function assocToClass(array $rowAssoc, string $className, array $const
        * @param int $columnIndex
        * The index of the column to fetch the value of.
        *
        * @return string|false
        * The value of the column, or FALSE if the column is not defined.
        * @return string
        * The value of the column.
        *
        * @throws \ValueError
        * If the column index is not defined.
        */
        protected function assocToColumn(array $rowAssoc, array $columnNames, int $columnIndex): mixed {
        return $rowAssoc[$columnNames[$columnIndex]] ?? FALSE;
        if (!isset($columnNames[$columnIndex])) {
        throw new \ValueError('Invalid column index');
        }
        return $rowAssoc[$columnNames[$columnIndex]];
        }
        }
        ......@@ -108,6 +108,9 @@ public function fetch($mode = NULL, $cursor_orientation = NULL, $cursor_offset =
        *
        * @return mixed
        * A single field from the next record, or FALSE if there is no next record.
        *
        * @throws \ValueError
        * If there is a record and the column index is not defined.
        */
        public function fetchField($index = 0);
        ......
        ......@@ -260,7 +260,7 @@ public function fetch($fetch_style = NULL, $cursor_orientation = \PDO::FETCH_ORI
        */
        public function fetchColumn($index = 0) {
        if ($row = $this->fetch(\PDO::FETCH_ASSOC)) {
        return $row[$this->columnNames[$index]];
        return $this->assocToColumn($row, $this->columnNames, $index);
        }
        return FALSE;
        }
        ......
        ......@@ -230,6 +230,69 @@ public function testQueryFetchField(): void {
        $this->assertSame($expectedResults, $actualResults);
        }
        /**
        * Tests ::fetchField() for edge values returned.
        */
        public function testQueryFetchFieldEdgeCases(): void {
        $this->connection->insert('test_null')
        ->fields([
        'name' => 'Foo',
        'age' => 0,
        ])
        ->execute();
        $this->connection->insert('test_null')
        ->fields([
        'name' => 'Bar',
        'age' => NULL,
        ])
        ->execute();
        $this->connection->insert('test_null')
        ->fields([
        'name' => 'Qux',
        'age' => (int) FALSE,
        ])
        ->execute();
        $statement = $this->connection->select('test_null')
        ->fields('test_null', ['age'])
        ->orderBy('id')
        ->execute();
        // First fetch returns '0' since an existing value is always a string.
        $this->assertSame('0', $statement->fetchField());
        // Second fetch returns NULL since NULL was inserted.
        $this->assertNull($statement->fetchField());
        // Third fetch returns '0' since a FALSE bool cast to int was inserted.
        $this->assertSame('0', $statement->fetchField());
        // Fourth fetch returns FALSE since no row was available.
        $this->assertFalse($statement->fetchField());
        }
        /**
        * Confirms that an out of range index throws an error.
        */
        public function testQueryFetchFieldIndexOutOfRange(): void {
        $this->expectException(\ValueError::class);
        $this->expectExceptionMessage('Invalid column index');
        $this->connection
        ->query('SELECT [name] FROM {test} WHERE [age] = :age', [':age' => 25])
        ->fetchField(200);
        }
        /**
        * Confirms that empty result set prevails on out of range index.
        */
        public function testQueryFetchFieldIndexOutOfRangeOnEmptyResultSet(): void {
        $this->assertFalse($this->connection
        ->query('SELECT [name] FROM {test} WHERE [age] = :age', [':age' => 255])
        ->fetchField(200));
        }
        /**
        * Tests that rowCount() throws exception on SELECT query.
        */
        ......
        0% Loading or .
        You are about to add 0 people to the discussion. Proceed with caution.
        Please register or to comment