Make WordPress Core

Opened 10 years ago

Closed 10 years ago

#34708 closed defect (bug) (fixed)

Empty DB_CHARSET leads to error in strip_invalid_text

Reported by: rmccue's profile rmccue Owned by: pento's profile pento
Milestone: 4.4 Priority: normal
Severity: normal Version:
Component: Database Keywords:
Focuses: Cc:

Description

Found this while running unit tests without DB_CHARSET defined. wpdb::strip_invalid_text assumes $wpdb->charset is set and uses it in a query.

For the unit tests, this causes test_strip_invalid_text_from_query_cp1251_is_safe to fail:

WordPress database error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') AS x_0' at line 1 for query SELECT CONVERT( CONVERT( 'INSERT INTO test_cp1251_query_d9187( `a` ) VALUES( \'safe data\' )' USING cp1251 ) USING  ) AS x_0 made by PHPUnit_TextUI_Command::main, PHPUnit_TextUI_Command->run, PHPUnit_TextUI_TestRunner->doRun, PHPUnit_Framework_TestSuite->run, PHPUnit_Framework_TestSuite->run, PHPUnit_Framework_TestCase->run, PHPUnit_Framework_TestResult->run, PHPUnit_Framework_TestCase->runBare, PHPUnit_Framework_TestCase->runTest, ReflectionMethod->invokeArgs, Tests_DB_Charset->test_strip_invalid_text_from_query_cp1251_is_safe, wpdb_exposed_methods_for_testing->strip_invalid_text_from_query, wpdb_exposed_methods_for_testing->__call, call_user_func_array

Since at least [33310].

Change History (1)

#1 @pento
10 years ago

  • Owner set to pento
  • Resolution set to fixed
  • Status changed from new to closed

In 35655:

WPDB: Fall back to the connection charset when sanity checking strings.

If DB_CHARSET isn't defined (or is empty), wpdb::$charset will be empty, too. wpdb::strip_invalid_text() assumes that it isn't empty, however, so we need to fall back to the connection character set when we're running our sanity checks.

Fixes #34708.

Note: See TracTickets for help on using tickets.