Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5356dbb

Browse filesBrowse files
committed
bug #18540 Replace iconv_*() uses by mb_*(), add mbstring polyfill when required (nicolas-grekas)
This PR was merged into the 2.8 branch. Discussion ---------- Replace iconv_*() uses by mb_*(), add mbstring polyfill when required | Q | A | ------------- | --- | Branch? | 2.8 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #18539 | License | MIT | Doc PR | - Looks like `iconv_*()` functions can be really slow (see #18539). Commits ------- 27f5f81 Replace iconv_*() uses by mb_*(), add mbstring polyfill when required
2 parents db31b56 + 27f5f81 commit 5356dbb
Copy full SHA for 5356dbb

File tree

Expand file treeCollapse file tree

6 files changed

+12
-13
lines changed
Filter options
Expand file treeCollapse file tree

6 files changed

+12
-13
lines changed

‎src/Symfony/Bridge/Doctrine/Logger/DbalLogger.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/Logger/DbalLogger.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ private function normalizeParams(array $params)
9595
}
9696

9797
// detect if the too long string must be shorten
98-
if (self::MAX_STRING_LENGTH < iconv_strlen($params[$index], 'UTF-8')) {
99-
$params[$index] = iconv_substr($params[$index], 0, self::MAX_STRING_LENGTH - 6, 'UTF-8').' [...]';
98+
if (self::MAX_STRING_LENGTH < mb_strlen($params[$index], 'UTF-8')) {
99+
$params[$index] = mb_substr($params[$index], 0, self::MAX_STRING_LENGTH - 6, 'UTF-8').' [...]';
100100
continue;
101101
}
102102
}

‎src/Symfony/Bridge/Doctrine/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/composer.json
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
],
1818
"require": {
1919
"php": ">=5.3.9",
20-
"doctrine/common": "~2.4"
20+
"doctrine/common": "~2.4",
21+
"symfony/polyfill-mbstring": "~1.0"
2122
},
2223
"require-dev": {
2324
"symfony/stopwatch": "~2.2|~3.0.0",

‎src/Symfony/Component/Validator/Constraints/LengthValidator.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/LengthValidator.php
+2-5Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,10 @@ public function validate($value, Constraint $constraint)
4040

4141
$stringValue = (string) $value;
4242

43-
if ('UTF8' === $charset = strtoupper($constraint->charset)) {
44-
$charset = 'UTF-8'; // iconv on Windows requires "UTF-8" instead of "UTF8"
43+
if (!$invalidCharset = !@mb_check_encoding($stringValue, $constraint->charset)) {
44+
$length = mb_strlen($stringValue, $constraint->charset);
4545
}
4646

47-
$length = @iconv_strlen($stringValue, $charset);
48-
$invalidCharset = false === $length;
49-
5047
if ($invalidCharset) {
5148
if ($this->context instanceof ExecutionContextInterface) {
5249
$this->context->buildViolation($constraint->charsetMessage)

‎src/Symfony/Component/Validator/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/composer.json
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
],
1818
"require": {
1919
"php": ">=5.3.9",
20+
"symfony/polyfill-mbstring": "~1.0",
2021
"symfony/translation": "~2.4|~3.0.0"
2122
},
2223
"require-dev": {

‎src/Symfony/Component/VarDumper/Cloner/VarCloner.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Cloner/VarCloner.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,12 @@ protected function doClone($var)
102102
} else {
103103
$stub->value = $v;
104104
}
105-
} elseif (0 <= $maxString && isset($v[1 + ($maxString >> 2)]) && 0 < $cut = iconv_strlen($v, 'UTF-8') - $maxString) {
105+
} elseif (0 <= $maxString && isset($v[1 + ($maxString >> 2)]) && 0 < $cut = mb_strlen($v, 'UTF-8') - $maxString) {
106106
$stub = new Stub();
107107
$stub->type = Stub::TYPE_STRING;
108108
$stub->class = Stub::STRING_UTF8;
109109
$stub->cut = $cut;
110-
$stub->value = iconv_substr($v, 0, $maxString, 'UTF-8');
110+
$stub->value = mb_substr($v, 0, $maxString, 'UTF-8');
111111
}
112112
break;
113113

‎src/Symfony/Component/VarDumper/Dumper/CliDumper.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Dumper/CliDumper.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public function dumpString(Cursor $cursor, $str, $bin, $cut)
169169
$this->dumpLine($cursor->depth, true);
170170
} else {
171171
$attr = array(
172-
'length' => 0 <= $cut ? iconv_strlen($str, 'UTF-8') + $cut : 0,
172+
'length' => 0 <= $cut ? mb_strlen($str, 'UTF-8') + $cut : 0,
173173
'binary' => $bin,
174174
);
175175
$str = explode("\n", $str);
@@ -195,8 +195,8 @@ public function dumpString(Cursor $cursor, $str, $bin, $cut)
195195
if ($i < $m) {
196196
$str .= "\n";
197197
}
198-
if (0 < $this->maxStringWidth && $this->maxStringWidth < $len = iconv_strlen($str, 'UTF-8')) {
199-
$str = iconv_substr($str, 0, $this->maxStringWidth, 'UTF-8');
198+
if (0 < $this->maxStringWidth && $this->maxStringWidth < $len = mb_strlen($str, 'UTF-8')) {
199+
$str = mb_substr($str, 0, $this->maxStringWidth, 'UTF-8');
200200
$lineCut = $len - $this->maxStringWidth;
201201
}
202202
if ($m && 0 < $cursor->depth) {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.