]> BookStack Code Mirror - bookstack/commitdiff
Updated string functions to use mulitbyte versions where needed
authorDan Brown <redacted>
Sat, 25 May 2019 15:14:57 +0000 (16:14 +0100)
committerDan Brown <redacted>
Sat, 25 May 2019 15:15:19 +0000 (16:15 +0100)
Fixes #816

app/Auth/User.php
app/Console/Commands/CreateAdmin.php
app/Entities/Book.php
app/Entities/Bookshelf.php
app/Entities/Chapter.php
app/Entities/Repos/PageRepo.php
app/Http/Controllers/Auth/RegisterController.php
app/helpers.php

index 12f022b0668491653479e9151ea10373f2fa32eb..259b8eec01375992d3fa4b0f6466397d3f7cbb5a 100644 (file)
@@ -216,12 +216,12 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
      */
     public function getShortName($chars = 8)
     {
-        if (strlen($this->name) <= $chars) {
+        if (mb_strlen($this->name) <= $chars) {
             return $this->name;
         }
 
         $splitName = explode(' ', $this->name);
-        if (strlen($splitName[0]) <= $chars) {
+        if (mb_strlen($splitName[0]) <= $chars) {
             return $splitName[0];
         }
 
index 90c1ddb1c325e4e67761b5a81d9d602ad254c103..e67da871763f8b9ef379c8687961ec2612d33bc3 100644 (file)
@@ -49,7 +49,7 @@ class CreateAdmin extends Command
         if (empty($email)) {
             $email = $this->ask('Please specify an email address for the new admin user');
         }
-        if (strlen($email) < 5 || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
+        if (mb_strlen($email) < 5 || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
             return $this->error('Invalid email address provided');
         }
 
@@ -61,7 +61,7 @@ class CreateAdmin extends Command
         if (empty($name)) {
             $name = $this->ask('Please specify an name for the new admin user');
         }
-        if (strlen($name) < 2) {
+        if (mb_strlen($name) < 2) {
             return $this->error('Invalid name provided');
         }
 
@@ -69,7 +69,7 @@ class CreateAdmin extends Command
         if (empty($password)) {
             $password = $this->secret('Please specify a password for the new admin user');
         }
-        if (strlen($password) < 5) {
+        if (mb_strlen($password) < 5) {
             return $this->error('Invalid password provided, Must be at least 5 characters');
         }
 
index 77cacf632e03dad04c6b9dcec98843170e046224..decdde9dcf026b7e8c67d8c05b15affbcc96a015 100644 (file)
@@ -104,7 +104,7 @@ class Book extends Entity
     public function getExcerpt(int $length = 100)
     {
         $description = $this->description;
-        return strlen($description) > $length ? substr($description, 0, $length-3) . '...' : $description;
+        return mb_strlen($description) > $length ? mb_substr($description, 0, $length-3) . '...' : $description;
     }
 
     /**
index 1de767feca132a283803e04470b8936fa9be3ffe..c8f8b990cde9e019b48d354ef86f1fecb1f178fa 100644 (file)
@@ -83,7 +83,7 @@ class Bookshelf extends Entity
     public function getExcerpt(int $length = 100)
     {
         $description = $this->description;
-        return strlen($description) > $length ? substr($description, 0, $length-3) . '...' : $description;
+        return mb_strlen($description) > $length ? mb_substr($description, 0, $length-3) . '...' : $description;
     }
 
     /**
index bdacb7c9d8340ee26a43c9652587594d33afadb6..93640475893085adff2cf8e543fb95b662b1c214 100644 (file)
@@ -56,7 +56,7 @@ class Chapter extends Entity
     public function getExcerpt(int $length = 100)
     {
         $description = $this->text ?? $this->description;
-        return strlen($description) > $length ? substr($description, 0, $length-3) . '...' : $description;
+        return mb_strlen($description) > $length ? mb_substr($description, 0, $length-3) . '...' : $description;
     }
 
     /**
index 208aa5fa309444dabd61839a3fdc43b2d0a536b3..e6cb309e7978a9d8eafacf617797eaba4c73de68 100644 (file)
@@ -192,7 +192,7 @@ class PageRepo extends EntityRepo
         // Create an unique id for the element
         // Uses the content as a basis to ensure output is the same every time
         // the same content is passed through.
-        $contentId = 'bkmrk-' . substr(strtolower(preg_replace('/\s+/', '-', trim($element->nodeValue))), 0, 20);
+        $contentId = 'bkmrk-' . mb_substr(strtolower(preg_replace('/\s+/', '-', trim($element->nodeValue))), 0, 20);
         $newId = urlencode($contentId);
         $loopIndex = 0;
 
@@ -424,8 +424,8 @@ class PageRepo extends EntityRepo
 
         $tree = collect($headers)->map(function($header) {
             $text = trim(str_replace("\xc2\xa0", '', $header->nodeValue));
-            if (strlen($text) > 30) {
-                $text = substr($text, 0, 27) . '...';
+            if (mb_strlen($text) > 30) {
+                $text = mb_substr($text, 0, 27) . '...';
             }
 
             return [
@@ -435,7 +435,7 @@ class PageRepo extends EntityRepo
                 'text' => $text,
             ];
         })->filter(function($header) {
-            return strlen($header['text']) > 0;
+            return mb_strlen($header['text']) > 0;
         });
 
         // Normalise headers if only smaller headers have been used
index 79d69665298130643405f24a8bfff18d30d20c57..d57105b6293385c4dd6ef163196b908f9b9ac7cf 100644 (file)
@@ -142,7 +142,7 @@ class RegisterController extends Controller
 
         if ($registrationRestrict) {
             $restrictedEmailDomains = explode(',', str_replace(' ', '', $registrationRestrict));
-            $userEmailDomain = $domain = substr(strrchr($userData['email'], "@"), 1);
+            $userEmailDomain = $domain = mb_substr(mb_strrchr($userData['email'], "@"), 1);
             if (!in_array($userEmailDomain, $restrictedEmailDomains)) {
                 throw new UserRegistrationException(trans('auth.registration_email_domain_invalid'), '/register');
             }
index 0fedf2e8db30a009a805635b09544d1b2e0c1e0c..8cb3fa3f4a22be3725da7510cdf448eb6a8a7e76 100644 (file)
@@ -123,7 +123,7 @@ function baseUrl($path, $forceAppDomain = false)
     // Remove non-specified domain if forced and we have a domain
     if ($isFullUrl && $forceAppDomain) {
         if (!empty($base) && strpos($path, $base) === 0) {
-            $path = substr($path, strlen($base));
+            $path = mb_substr($path, mb_strlen($base));
         } else {
             $explodedPath = explode('/', $path);
             $path = implode('/', array_splice($explodedPath, 3));