Skip to content

Commit 5b342e2

Browse files
committed
Use PDO::quote() for string escaping
1 parent ad3beb8 commit 5b342e2

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

wp-includes/sqlite-ast/class-wp-sqlite-driver.php

+14
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,20 @@ public function get_insert_id() {
489489
return $last_insert_id;
490490
}
491491

492+
/**
493+
* Quotes a string for use in a query.
494+
*
495+
* Places quotes around the input string (if required) and escapes special
496+
* characters within the input string. See "PDO::quote()".
497+
*
498+
* @param string $value The string value to quote.
499+
* @param int $type The type of the parameter. Default is PDO::PARAM_STR.
500+
* @return string The quoted string.
501+
*/
502+
public function quote( string $value, int $type = PDO::PARAM_STR ): string {
503+
return $this->pdo->quote( $value, $type );
504+
}
505+
492506
/**
493507
* Translate and execute a MySQL query in SQLite.
494508
*

wp-includes/sqlite/class-wp-sqlite-db.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,13 @@ public function _real_escape( $data ) {
119119
if ( ! is_scalar( $data ) ) {
120120
return '';
121121
}
122-
$escaped = addslashes( $data );
122+
if ( $this->dbh instanceof WP_SQLite_Driver ) {
123+
// WP_SQLite_Driver::quote() wraps the escaped string with quotes,
124+
// while WPDB expects the string to be escaped without them.
125+
$escaped = substr( $this->dbh->quote( $data ), 1, -1 );
126+
} else {
127+
$escaped = addslashes( $data );
128+
}
123129
return $this->add_placeholder_escape( $escaped );
124130
}
125131

0 commit comments

Comments
 (0)