@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add test coverage that our definition of BMP agrees with MySQL

Summary:
Ref T1191. Test that MySQL's rules match those of `phutil_is_utf8_with_only_bmp_characters()`:

- Build a string with //every// character that we consider to be a BMP character.
- Write it into MySQL.
- Read it back out.
- Make sure MySQL didn't truncate it.

Test Plan: Ran unit test. This test runs pretty quickly (50ms), the string with every character isn't all that enormous.

Reviewers: btrahan, arice

Reviewed By: arice

CC: chad, arice, aran

Maniphest Tasks: T1191

Differential Revision: https://secure.phabricator.com/D8314

+57
+2
resources/sql/autopatches/20140223.bigutf8scratch.sql
··· 1 + ALTER TABLE {$NAMESPACE}_harbormaster.harbormaster_scratchtable 2 + ADD bigData LONGTEXT COLLATE utf8_bin;
+1
src/applications/harbormaster/storage/HarbormasterScratchTable.php
··· 9 9 final class HarbormasterScratchTable extends HarbormasterDAO { 10 10 11 11 protected $data; 12 + protected $bigData; 12 13 13 14 }
+54
src/infrastructure/__tests__/PhabricatorInfrastructureTestCase.php
··· 3 3 final class PhabricatorInfrastructureTestCase 4 4 extends PhabricatorTestCase { 5 5 6 + protected function getPhabricatorTestCaseConfiguration() { 7 + return array( 8 + self::PHABRICATOR_TESTCONFIG_BUILD_STORAGE_FIXTURES => true, 9 + ); 10 + } 11 + 6 12 /** 7 13 * This is more of an acceptance test case instead of a unittest. It verifies 8 14 * that all symbols can be loaded correctly. It can catch problems like ··· 22 28 'In test cases, all applications should default to installed.'); 23 29 } 24 30 31 + public function testMySQLAgreesWithUsAboutBMP() { 32 + // Build a string with every BMP character in it, then insert it into MySQL 33 + // and read it back. We expect to get the same string out that we put in, 34 + // demonstrating that strings which pass our BMP checks are also valid in 35 + // MySQL and no silent data truncation will occur. 36 + 37 + $buf = ''; 38 + 39 + for ($ii = 0x01; $ii <= 0x7F; $ii++) { 40 + $buf .= chr($ii); 41 + } 42 + 43 + for ($ii = 0xC2; $ii <= 0xDF; $ii++) { 44 + for ($jj = 0x80; $jj <= 0xBF; $jj++) { 45 + $buf .= chr($ii).chr($jj); 46 + } 47 + } 48 + 49 + // NOTE: This is \xE0\xA0\xZZ. 50 + for ($ii = 0xE0; $ii <= 0xE0; $ii++) { 51 + for ($jj = 0xA0; $jj <= 0xBF; $jj++) { 52 + for ($kk = 0x80; $kk <= 0xBF; $kk++) { 53 + $buf .= chr($ii).chr($jj).chr($kk); 54 + } 55 + } 56 + } 57 + 58 + // NOTE: This is \xE1\xZZ\xZZ through \xEF\xZZ\xZZ. 59 + for ($ii = 0xE1; $ii <= 0xEF; $ii++) { 60 + for ($jj = 0x80; $jj <= 0xBF; $jj++) { 61 + for ($kk = 0x80; $kk <= 0xBF; $kk++) { 62 + $buf .= chr($ii).chr($jj).chr($kk); 63 + } 64 + } 65 + } 66 + 67 + $this->assertEqual(194431, strlen($buf)); 68 + $this->assertEqual(true, phutil_is_utf8_with_only_bmp_characters($buf)); 69 + 70 + $write = id(new HarbormasterScratchTable()) 71 + ->setData('all.utf8.bmp') 72 + ->setBigData($buf) 73 + ->save(); 74 + 75 + $read = id(new HarbormasterScratchTable())->load($write->getID()); 76 + 77 + $this->assertEqual($buf, $read->getBigData()); 78 + } 25 79 26 80 } 27 81