Skip to content

Commit cfb123c

Browse files
committed
Add additional check to copy MySQL behavior
1 parent f521f5a commit cfb123c

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

tests/WP_SQLite_Translator_Tests.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,18 @@ public function testRegexpReplace() {
128128

129129
$this->assertQuery( "SELECT * FROM _options WHERE REGEXP_REPLACE(option_name, '(-ignore|-remove)', '') = 'test'" );
130130
$this->assertCount( 2, $this->engine->get_query_results() );
131+
132+
$this->assertQuery( 'SELECT REGEXP_REPLACE( null, 'a', 'x') as result' );
133+
$results = $this->engine->get_query_results();
134+
$this->assertEquals( null, $results[0]->result );
135+
136+
$this->assertQuery( 'SELECT REGEXP_REPLACE( 'abc', null, 'x') as result' );
137+
$results = $this->engine->get_query_results();
138+
$this->assertEquals( null, $results[0]->result );
139+
140+
$this->assertQuery( 'SELECT REGEXP_REPLACE( 'abc', 'a', null) as result' );
141+
$results = $this->engine->get_query_results();
142+
$this->assertEquals( null, $results[0]->result );
131143
}
132144

133145
public function testInsertDateNow() {

wp-includes/sqlite/class-wp-sqlite-pdo-user-defined-functions.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,12 @@ public function regexp_replace( $field, $pattern, $replacement ) {
518518
* be reasonably safe since PHP does not allow null bytes in
519519
* regular expressions anyway.
520520
*/
521+
522+
/* Return null if one of the required parameter is null */
523+
if ( is_null( $field ) || is_null( $pattern ) || is_null( $replacement ) ) {
524+
return null;
525+
}
526+
521527
if ( "\x00" === $pattern[0] ) {
522528
$pattern = substr( $pattern, 1 );
523529
$flags = '';

0 commit comments

Comments
 (0)