fuel / orm

Fuel PHP Framework - Fuel v1.x ORM
http://fuelphp.com/docs/packages/orm/intro.html
152 stars 96 forks source link

Fix substr on unicode string #409

Open Seb-C opened 7 years ago

Seb-C commented 7 years ago

This replaces substr by mb_substr.

My specific case happened with a varchar(250) field, and a string that was longer. The 250th and 251th bytes of the string were an UTF-8 non-breakable space (0xC2A0).

Since C2 is a control character that can't exist alone, this made everything using this string crash thereafter (including debugging tools).

WanWizard commented 7 years ago

That code will fail if mbstring isn't loaded. Ideally, this should use \Str::truncate(), which is multibyte aware.

I think this needs to be looked at in more broader terms, quite a bit of the Fuel was written when overloading string functions was the norm, which isn't the case anymore, and is even deprecated as of PHP 7.2.