Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c7e772c

Browse files
committed
bug #16359 Use mb_detect_encoding with $strict = true (nicolas-grekas)
This PR was merged into the 2.3 branch. Discussion ---------- Use mb_detect_encoding with $strict = true | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Otherwise, UTF-8 can be returned for non-UTF8 strings... See e.g. https://3v4l.org/oMMnX Commits ------- e6c89f1 Use mb_detect_encoding with $strict = true
2 parents dd9de5b + e6c89f1 commit c7e772c

File tree

5 files changed

+6
-6
lines changed

5 files changed

+6
-6
lines changed

src/Symfony/Bridge/Doctrine/Tests/Logger/DbalLoggerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public function testLogUTF8LongString()
160160
$dbalLogger
161161
->expects($this->once())
162162
->method('log')
163-
->with('SQL', array('short' => $shortString, 'long' => mb_substr($longString, 0, DbalLogger::MAX_STRING_LENGTH - 6, mb_detect_encoding($longString)).' [...]'))
163+
->with('SQL', array('short' => $shortString, 'long' => mb_substr($longString, 0, DbalLogger::MAX_STRING_LENGTH - 6, 'UTF-8').' [...]'))
164164
;
165165

166166
$dbalLogger->startQuery('SQL', array(

src/Symfony/Component/Console/Application.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,7 @@ private function stringWidth($string)
10891089
return strlen($string);
10901090
}
10911091

1092-
if (false === $encoding = mb_detect_encoding($string)) {
1092+
if (false === $encoding = mb_detect_encoding($string, null, true)) {
10931093
return strlen($string);
10941094
}
10951095

@@ -1106,7 +1106,7 @@ private function splitStringByWidth($string, $width)
11061106
return str_split($string, $width);
11071107
}
11081108

1109-
if (false === $encoding = mb_detect_encoding($string)) {
1109+
if (false === $encoding = mb_detect_encoding($string, null, true)) {
11101110
return str_split($string, $width);
11111111
}
11121112

src/Symfony/Component/Console/Helper/Helper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ protected function strlen($string)
5353
return strlen($string);
5454
}
5555

56-
if (false === $encoding = mb_detect_encoding($string)) {
56+
if (false === $encoding = mb_detect_encoding($string, null, true)) {
5757
return strlen($string);
5858
}
5959

src/Symfony/Component/Console/Helper/TableHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ private function renderCell(array $row, $column, $cellFormat)
386386
$width = $this->getColumnWidth($column);
387387

388388
// str_pad won't work properly with multi-byte strings, we need to fix the padding
389-
if (function_exists('mb_strwidth') && false !== $encoding = mb_detect_encoding($cell)) {
389+
if (function_exists('mb_strwidth') && false !== $encoding = mb_detect_encoding($cell, null, true)) {
390390
$width += strlen($cell) - mb_strwidth($cell, $encoding);
391391
}
392392

src/Symfony/Component/Form/Extension/Core/DataTransformer/NumberToLocalizedStringTransformer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public function reverseTransform($value)
132132
throw new TransformationFailedException('I don\'t have a clear idea what infinity looks like');
133133
}
134134

135-
if (function_exists('mb_detect_encoding') && false !== $encoding = mb_detect_encoding($value)) {
135+
if (function_exists('mb_detect_encoding') && false !== $encoding = mb_detect_encoding($value, null, true)) {
136136
$length = mb_strlen($value, $encoding);
137137
$remainder = mb_substr($value, $position, $length, $encoding);
138138
} else {

0 commit comments

Comments
 (0)