Differential D10798 Diff 25951 src/aphront/storage/connection/mysql/AphrontBaseMySQLDatabaseConnection.php
Changeset View
Changeset View
Standalone View
Standalone View
src/aphront/storage/connection/mysql/AphrontBaseMySQLDatabaseConnection.php
Show First 20 Lines • Show All 318 Lines • ▼ Show 20 Lines | abstract class AphrontBaseMySQLDatabaseConnection | ||||
} | } | ||||
/** | /** | ||||
* Check inserts for characters outside of the BMP. Even with the strictest | * Check inserts for characters outside of the BMP. Even with the strictest | ||||
* settings, MySQL will silently truncate data when it encounters these, which | * settings, MySQL will silently truncate data when it encounters these, which | ||||
* can lead to data loss and security problems. | * can lead to data loss and security problems. | ||||
*/ | */ | ||||
protected function validateUTF8String($string) { | protected function validateUTF8String($string) { | ||||
// TODO: Make this `true` eventually, once we make storage adjustment | |||||
// mandatory. For now, you can set it to `true` to test things. | |||||
$has_utf8mb4 = false; | |||||
if ($has_utf8mb4) { | |||||
if (phutil_is_utf8($string)) { | if (phutil_is_utf8($string)) { | ||||
return; | return; | ||||
} | } | ||||
throw new AphrontCharacterSetQueryException( | throw new AphrontCharacterSetQueryException( | ||||
pht( | pht( | ||||
'Attempting to construct a query using a non-utf8 string when '. | 'Attempting to construct a query using a non-utf8 string when '. | ||||
'utf8 is expected. Use the `%%B` conversion to escape binary '. | 'utf8 is expected. Use the `%%B` conversion to escape binary '. | ||||
'strings data.')); | 'strings data.')); | ||||
} else { | |||||
if (phutil_is_utf8_with_only_bmp_characters($string)) { | |||||
return; | |||||
} | |||||
throw new AphrontCharacterSetQueryException( | |||||
pht( | |||||
'Attempting to construct a query containing characters outside of '. | |||||
'the Unicode Basic Multilingual Plane. MySQL will silently truncate '. | |||||
'this data if it is inserted into a `utf8` column. Use the `%%B` '. | |||||
'conversion to escape binary strings data.')); | |||||
} | |||||
} | } | ||||
} | } |