symfony/polyfill-mbstring
Partial native PHP polyfill for the mbstring extension, enabling multibyte string functions when ext-mbstring isn’t available. Part of Symfony’s Polyfill suite; provides compatible helpers to improve portability across environments.
mbstring functions (e.g., Blade templating, localization, validation). Laravel’s core and ecosystem (e.g., laravel/framework, spatie/laravel-translatable) already depend on Symfony’s polyfills, ensuring seamless integration. The fixes in v1.38.2 (e.g., mb_scrub() for control characters, mb_str_pad() for RTL languages) directly address Laravel’s pain points in user-generated content sanitization and multilingual UI consistency.ext-mbstring functionality transparently.mb_scrub() in Illuminate\Validation\Rules\Sanitize).mb_str_pad() for RTL text alignment).mb_scrub()’s prior handling of control characters may need updates.mb_scrub() or mb_str_pad() (e.g., custom validation rules, localization middleware)?Illuminate/Support/Str).composer require symfony/polyfill-mbstring:^1.38.2 --update-with-dependencies
mb_scrub() with:
$input = "\x00Malicious\x0B"; // Control characters
$scrubbed = mb_scrub($input);
assert($scrubbed === "Malicious"); // No crashes
mb_str_pad() with Arabic/Hebrew:
$rtlText = "مرحبا";
$padded = mb_str_pad($rtlText, 10, " ", STR_PAD_LEFT);
assert(mb_strlen($padded) === 10);
//IGNORE fallbacks were fixed in v1.38.0).ext-mbstring).ext-iconv: Mandatory (used as a fallback).v1.38.2 in a staging environment.mb_scrub()/mb_str_pad() usage (e.g., via grep -r "mb_scrub\|mb_str_pad").Illuminate\Validation).composer.json already pins polyfill versions, reducing drift risk.mb_scrub(): Eliminates crashes from control characters in user input (e.g., spam filters).mb_str_pad(): Resolves RTL alignment issues in dashboards/CMS.mb_* functions remain valid; no additional guidance needed.mbstring). Suitable for:
ext-mbstring is unavailable).ext-iconv.| Failure Scenario | Likelihood | Impact | Mitigation |
|---|---|---|---|
mb_scrub() crashes on invalid UTF-8 |
Low (fixed in v1.38.2) | Data corruption in sanitization | Re-test with edge cases (e.g., \xFF\xFE€). |
mb_str_pad() misaligns RTL text |
Low (fixed in v1.38.2) | UI regression in Arabic/Hebrew | Validate RTL padding in staging before production. |
Custom mb_scrub() logic breaks |
Medium | Undefined behavior for control chars | Audit custom implementations; update to use native mb_scrub() behavior. |
Alpine Linux //IGNORE fallback fails |
Very Low (fixed in v1.38.0) | Encoding errors in CI | Test on Alpine in CI pipeline. |
mbstring.mb_scrub() and mb_str_pad() edge cases (see Integration Approach).ext-mbstring if performance becomes critical.^1.38.2 to avoid regressions.How can I help you explore Laravel packages today?