Skip to content

Conversation

@Nasim25
Copy link
Contributor

@Nasim25 Nasim25 commented Nov 26, 2025

Description

Fixes Str::substrReplace() to properly handle multibyte UTF-8 characters.

Problem

Current implementation uses substr_replace() which operates on bytes, causing corruption with multibyte characters:

Str::substrReplace('kenkä', 'ng', -3, 2);
// Current: "kenng¤" ❌
// Expected: "kenga" ✅

Solution

  • Replaced substr_replace() with mb_substr() concatenation
  • Properly normalizes negative offsets and lengths
  • Maintains full backward compatibility

Testing

Str::substrReplace('kenkä', 'ng', -3, 2);  // 'kengä' ✅
Str::substrReplace('kenka', 'ng', -3, 2);  // 'kenga' ✅

Added tests for multibyte string handling, and tests pass.

@taylorotwell taylorotwell merged commit 4b1344d into laravel:12.x Nov 27, 2025
68 of 74 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants