Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
remcotolsma opened this issue Apr 22, 2024 · 0 comments

Comments

@remcotolsma
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant