Fixed vB4 Import: Fix getPostMessage for titles that contain non-ASCII characters

Steffen

Well-known member
We have to count characters instead of bytes.

Diff:
diff --git a/src/addons/XFI/Import/Importer/vBulletin.php b/src/addons/XFI/Import/Importer/vBulletin.php
index c7f7c3485..810d7371e 100644
--- a/src/addons/XFI/Import/Importer/vBulletin.php
+++ b/src/addons/XFI/Import/Importer/vBulletin.php
@@ -4054,8 +4054,8 @@ class vBulletin extends AbstractForumImporter
             $titleRegex = '/^(' . implode('|', $replyPrefixes) . ')?(\s*)?.*/i';
             if (preg_match($titleRegex, $title, $matches))
             {
-                $trimLen = $titleMaxChars - (strlen($matches[1]) + strlen($matches[2]));
-                $threadTitle = rtrim(substr($threadTitle, 0, $trimLen));
+                $trimLen = $titleMaxChars - (mb_strlen($matches[1]) + mb_strlen($matches[2]));
+                $threadTitle = rtrim(mb_substr($threadTitle, 0, $trimLen));
 
                 if ($title !== ($matches[1] . $matches[2] . $threadTitle))
                 {
 
We're using the built-in utf8_ functions instead of mb_ but, great, thanks!

Diff:
Index: src/addons/XFI/Import/Importer/vBulletin.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/addons/XFI/Import/Importer/vBulletin.php    (date 1535417006000)
+++ src/addons/XFI/Import/Importer/vBulletin.php    (date 1535417116000)
@@ -3239,8 +3239,8 @@
             $titleRegex = '/^(' . implode('|', $replyPrefixes) . ')?(\s*)?.*/i';
             if (preg_match($titleRegex, $title, $matches))
             {
-                $trimLen = $titleMaxChars - (strlen($matches[1]) + strlen($matches[2]));
-                $threadTitle = rtrim(substr($threadTitle, 0, $trimLen));
+                $trimLen = $titleMaxChars - (utf8_strlen($matches[1]) + utf8_strlen($matches[2]));
+                $threadTitle = rtrim(utf8_substr($threadTitle, 0, $trimLen));
 
                 if (rtrim($title) !== ($matches[1] . $matches[2] . $threadTitle))
                 {
 
Back
Top Bottom