Skip to content

Deprecated: addslashes(): Passing null to parameter → WP_SQLite_DB->_real_escape( $str ) #103

Open
@remcotolsma

Description

@remcotolsma

We noticed the following error:

Deprecated: addslashes(): Passing null to parameter #1 ($string) of type string is deprecated in sqlite-database-integration/wp-includes/sqlite/class-wp-sqlite-db.php on line 107

/**
* Method to escape characters.
*
* This overrides wpdb::_real_escape() to avoid using mysql_real_escape_string().
*
* @see wpdb::_real_escape()
*
* @param string $str The string to escape.
*
* @return string escaped
*/
public function _real_escape( $str ) {
return addslashes( $str );
}

I think that in certain cases null is passed to the _real_escape function.

In WordPress core they check on the type with is_scalar( $data ):

	/**
	 * Real escape using mysqli_real_escape_string().
	 *
	 * @since 2.8.0
	 *
	 * @see mysqli_real_escape_string()
	 *
	 * @param string $data String to escape.
	 * @return string Escaped string.
	 */
	public function _real_escape( $data ) {
		if ( ! is_scalar( $data ) ) {
			return '';
		}

		if ( $this->dbh ) {
			$escaped = mysqli_real_escape_string( $this->dbh, $data );
		} else {
			$class = get_class( $this );

			wp_load_translations_early();
			/* translators: %s: Database access abstraction class, usually wpdb or a class extending wpdb. */
			_doing_it_wrong( $class, sprintf( __( '%s must set a database connection for use with escaping.' ), $class ), '3.6.0' );

			$escaped = addslashes( $data );
		}

		return $this->add_placeholder_escape( $escaped );
	}

https://github.com/WordPress/WordPress/blob/9fd435aa157ad7053cdcabed879b843342999ffe/wp-includes/class-wpdb.php#L1262-L1290

Maybe that should be added in this plugin too?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions