10000 Rely on iconv and symfony/polyfill-* by nicolas-grekas · Pull Request #16317 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Rely on iconv and symfony/polyfill-* #16317

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 28, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@
"twig/twig": "~1.20|~2.0",
"psr/log": "~1.0",
"symfony/security-acl": "~2.7",
"paragonie/random_compat": "~1.0"
"symfony/polyfill-intl-icu": "~1.0",
"symfony/polyfill-mbstring": "~1.0",
"symfony/polyfill-php54": "~1.0",
"symfony/polyfill-php55": "~1.0",
"symfony/polyfill-php56": "~1.0",
"symfony/polyfill-php70": "~1.0",
"symfony/polyfill-util": "~1.0"
},
"replace": {
"symfony/asset": "self.version",
Expand Down Expand Up @@ -77,7 +83,6 @@
"doctrine/orm": "~2.4,>=2.4.5",
"doctrine/doctrine-bundle": "~1.2",
"monolog/monolog": "~1.11",
"ircmaxell/password-compat": "~1.0",
"ocramius/proxy-manager": "~0.4|~1.0",
"egulias/email-validator": "~1.2",
"phpdocumentor/reflection": "^1.0.7"
Expand All @@ -96,10 +101,8 @@
"Symfony\\Component\\": "src/Symfony/Component/"
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this file should be removed actually

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, removed

"classmap": [
"src/Symfony/Component/HttpFoundation/Resources/stubs",
"src/Symfony/Component/Intl/Resources/stubs"
],
"files": [ "src/Symfony/Component/Intl/Resources/stubs/functions.php" ]
]
},
"minimum-stability": "dev",
"extra": {
Expand Down
13 changes: 3 additions & 10 deletions src/Symfony/Bridge/Doctrine/Logger/DbalLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,9 @@ private function normalizeParams(array $params)
}

// detect if the too long string must be shorten
if (function_exists('mb_strlen')) {
if (self::MAX_STRING_LENGTH < mb_strlen($params[$index], 'UTF-8')) {
$params[$index] = mb_substr($params[$index], 0, self::MAX_STRING_LENGTH - 6, 'UTF-8').' [...]';
continue;
}
} else {
if (self::MAX_STRING_LENGTH < strlen($params[$index])) {
$params[$index] = substr($params[$index], 0, self::MAX_STRING_LENGTH - 6).' [...]';
continue;
}
if (self::MAX_STRING_LENGTH < iconv_strlen($params[$index], 'UTF-8')) {
$params[$index] = iconv_substr($params[$index], 0, self::MAX_STRING_LENGTH - 6, 'UTF-8').' [...]';
continue;
}
}

Expand Down
5 changes: 1 addition & 4 deletions src/Symfony/Bridge/Doctrine/Tests/Logger/DbalLoggerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,6 @@ public function testLogLongString()
));
}

/**
* @requires extension mbstring
*/
public function testLogUTF8LongString()
{
$logger = $this->getMock('Psr\\Log\\LoggerInterface');
Expand All @@ -160,7 +157,7 @@ public function testLogUTF8LongString()
$dbalLogger
->expects($this->once())
->method('log')
->with('SQL', array('short' => $shortString, 'long' => mb_substr($longString, 0, DbalLogger::MAX_STRING_LENGTH - 6, mb_detect_encoding($longString)).' [...]'))
->with('SQL', array('short' => $shortString, 'long' => iconv_substr($longString, 0, DbalLogger::MAX_STRING_LENGTH - 6, 'UTF-8').' [...]'))
;

$dbalLogger->startQuery('SQL', array(
Expand Down
1 change: 0 additions & 1 deletion src/Symfony/Bridge/PhpUnit/SymfonyTestsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class SymfonyTestsListener extends \PHPUnit_Framework_BaseTestListener
private $skippedFile = false;
private $wasSkipped = array();
private $isSkipped = array();
private $testsStack = array();

public function __destruct()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Twig/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"symfony/finder": "~2.3|~3.0.0",
"symfony/form": "~2.8",
"symfony/http-kernel": "~2.8|~3.0.0",
"symfony/intl": "~2.3|~3.0.0",
"symfony/polyfill-intl-icu": "~1.0",
"symfony/routing": "~2.2|~3.0.0",
"symfony/templating": "~2.1|~3.0.0",
"symfony/translation": "~2.7|~3.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ private function sanitizeString($string, $length = 40)
{
$string = trim(preg_replace('/\s+/', ' ', $string));

if (function_exists('mb_strlen') && false !== $encoding = mb_detect_encoding($string)) {
if (false !== $encoding = mb_detect_encoding($string, null, true)) {
if (mb_strlen($string, $encoding) > $length) {
return mb_substr($string, 0, $length - 3, $encoding).'...';
}
Expand Down
3 changes: 2 additions & 1 deletion src/Symfony/Bundle/FrameworkBundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"symfony/event-dispatcher": "~2.8|~3.0.0",
"symfony/http-foundation": "~2.4.9|~2.5,>=2.5.4|~3.0.0",
"symfony/http-kernel": "~2.8",
"symfony/polyfill-mbstring": "~1.0",
"symfony/filesystem": "~2.3|~3.0.0",
"symfony/routing": "~2.8|~3.0.0",
"symfony/security-core": "~2.6|~3.0.0",
Expand All @@ -40,7 +41,7 @@
"symfony/css-selector": "~2.0,>=2.0.5|~3.0.0",
"symfony/dom-crawler": "~2.0,>=2.0.5|~3.0.0",
"symfony/finder": "~2.0,>=2.0.5|~3.0.0",
"symfony/intl": "~2.3|~3.0.0",
"symfony/polyfill-intl-icu": "~1.0",
"symfony/security": "~2.6|~3.0.0",
"symfony/form": "~2.8",
"symfony/expression-language": "~2.6|~3.0.0",
Expand Down
4 changes: 1 addition & 3 deletions src/Symfony/Bundle/SecurityBundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
},
"require-dev": {
"symfony/browser-kit": "~2.4|~3.0.0",
"symfony/config": "~2.8|~3.0.0",
"symfony/console": "~2.7|~3.0.0",
"symfony/css-selector": "~2.0,>=2.0.5|~3.0.0",
"symfony/dom-crawler": "~2.0,>=2.0.5|~3.0.0",
Expand All @@ -37,8 +36,7 @@
"symfony/yaml": "~2.0,>=2.0.5|~3.0.0",
"symfony/expression-language": "~2.6|~3.0.0",
"doctrine/doctrine-bundle": "~1.2",
"twig/twig": "~1.20|~2.0",
"ircmaxell/password-compat": "~1.0"
"twig/twig": "~1.20|~2.0"
},
"autoload": {
"psr-4": { "Symfony\\Bundle\\SecurityBundle\\": "" }
Expand Down
12 changes: 2 additions & 10 deletions src/Symfony/Component/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -1077,11 +1077,7 @@ public function setDefaultCommand($commandName)

private function stringWidth($string)
{
if (!function_exists('mb_strwidth')) {
return strlen($string);
}

if (false === $encoding = mb_detect_encoding($string)) {
if (false === $encoding = mb_detect_encoding($string, null, true)) {
return strlen($string);
}

Expand All @@ -1094,11 +1090,7 @@ private function splitStringByWidth($string, $width)
// additionally, array_slice() is not enough as some character has doubled width.
// we need a function to split string not by character count but by string width

if (!function_exists('mb_strwidth')) {
return str_split($string, $width);
}

if (false === $encoding = mb_detect_encoding($string)) {
if (false === $encoding = mb_detect_encoding($string, null, true)) {
return str_split($string, $width);
}

Expand Down
6 changes: 1 addition & 5 deletions src/Symfony/Component/Console/Helper/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,7 @@ public function getHelperSet()
*/
public static function strlen($string)
{
if (!function_exists('mb_strwidth')) {
return strlen($string);
}

if (false === $encoding = mb_detect_encoding($string)) {
if (false === $encoding = mb_detect_encoding($string, null, true)) {
return strlen($string);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Console/Helper/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ private function renderCell(array $row, $column, $cellFormat)
}

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

Expand Down
3 changes: 0 additions & 3 deletions src/Symfony/Component/Console/Tests/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -558,9 +558,6 @@ public function testRenderException()
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception4.txt', $tester->getDisplay(true), '->renderException() wraps messages when they are bigger than the terminal');
}

/**
* @requires extension mbstring
*/
public function testRenderExceptionWithDoubleWidthCharacters()
{
$application = $this->getMock('Symfony\Component\Console\Application', array('getTerminalWidth'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ public function testFormatBlock()
);
}

/**
* @requires extension mbstring
*/
public function testFormatBlockWithDiacriticLetters()
{
$formatter = new FormatterHelper();
Expand All @@ -68,9 +65,6 @@ public function testFormatBlockWithDiacriticLetters()
);
}

/**
* @requires extension mbstring
*/
public function testFormatBlockWithDoubleWidthDiacriticLetters()
{
$formatter = new FormatterHelper();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,6 @@ public function testRedrawFrequency()
$progress->advance(1);
}

/**
* @requires extension mbstring
*/
public function testMultiByteSupport()
{
$progress = new ProgressHelper();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,6 @@ public function testRenderProvider()
);
}

/**
* @requires extension mbstring
*/
public function testRenderMultiByte()
{
$table = new TableHelper();
Expand All @@ -282,9 +279,6 @@ public function testRenderMultiByte()
$this->assertEquals($expected, $this->getOutputContent($output));
}

/**
* @requires extension mbstring
*/
public function testRenderFullWidthCharacters()
{
$table = new TableHelper();
10000 Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,6 @@ public function testRedrawFrequency()
$bar->advance(1);
}

/**
* @requires extension mbstring
*/
public function testMultiByteSupport()
{
$bar = new ProgressBar($output = $this->getOutputStream());
Expand Down Expand Up @@ -541,9 +538,6 @@ public function testMultilineFormat()
);
}

/**
* @requires extension mbstring
*/
public function testAnsiColorsAndEmojis()
{
$bar = new ProgressBar($output = $this->getOutputStream(), 15);
Expand Down
3 changes: 0 additions & 3 deletions src/Symfony/Component/Console/Tests/Helper/TableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -464,9 +464,6 @@ public function testRenderProvider()
);
}

/**
* @requires extension mbstring
*/
public function testRenderMultiByte()
{
$table = new Table($output = $this->getOutputStream());
Expand Down
3 changes: 2 additions & 1 deletion src/Symfony/Component/Console/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
}
],
"require": {
"php": ">=5.3.9"
"php": ">=5.3.9",
"symfony/polyfill-mbstring": "~1.0"
},
"require-dev": {
"symfony/event-dispatcher": "~2.1|~3.0.0",
Expand Down
29 changes: 1 addition & 28 deletions src/Symfony/Component/DomCrawler/Crawler.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,34 +173,7 @@ public function addHtmlContent($content, $charset = 'UTF-8')

try {
// Convert charset to HTML-entities to work around bugs in DOMDocument::loadHTML()

if (function_exists('mb_convert_encoding')) {
$content = mb_convert_encoding($content, 'HTML-ENTITIES', $charset);
} elseif (function_exists('iconv')) {
$content = preg_replace_callback(
'/[\x80-\xFF]+/',
function ($m) {
$m = unpack('C*', $m[0]);
$i = 1;
$entities = '';

while (isset($m[$i])) {
if (0xF0 <= $m[$i]) {
$c = (($m[$i++] - 0xF0) << 18) + (($m[$i++] - 0x80) << 12) + (($m[$i++] - 0x80) << 6) + $m[$i++] - 0x80;
} elseif (0xE0 <= $m[$i]) {
$c = (($m[$i++] - 0xE0) << 12) + (($m[$i++] - 0x80) << 6) + $m[$i++] - 0x80;
} else {
$c = (($m[$i++] - 0xC0) << 6) + $m[$i++] - 0x80;
}

$entities .= '&#'.$c.';';
}

return $entities;
},
iconv($charset, 'UTF-8', $content)
);
}
$content = mb_convert_encoding($content, 'HTML-ENTITIES', $charset);
} catch (\Exception $e) {
}

Expand Down
2 changes: 0 additions & 2 deletions src/Symfony/Component/DomCrawler/Tests/CrawlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ public function testAddHtmlContentWithBaseTag()

/**
* @covers Symfony\Component\DomCrawler\Crawler::addHtmlContent
* @requires extension mbstring
*/
public function testAddHtmlContentCharset()
{
Expand Down Expand Up @@ -137,7 +136,6 @@ public function testAddHtmlContentUnsupportedCharset()

/**
* @covers Symfony\Component\DomCrawler\Crawler::addHtmlContent
* @requires extension mbstring
*/
public function testAddHtmlContentCharsetGbk()
{
Expand Down
3 changes: 2 additions & 1 deletion src/Symfony/Component/DomCrawler/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
}
],
"require": {
"php": ">=5.3.9"
"php": ">=5.3.9",
"symfony/polyfill-mbstring": "~1.0"
},
"require-dev": {
"symfony/css-selector": "~2.8|~3.0.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public function reverseTransform($value)
throw new TransformationFailedException('I don\'t have a clear idea what infinity looks like');
}

if (function_exists('mb_detect_encoding') && false !== $encoding = mb_detect_encoding($value)) {
if (false !== $encoding = mb_detect_encoding($value, null, true)) {
$length = mb_strlen($value, $encoding);
$remainder = mb_substr($value, $position, $length, $encoding);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,6 @@ public function testReverseTransformWithGrouping($to, $from, $locale)

/**
* @see https://github.com/symfony/symfony/issues/7609
*
* @requires extension mbstring
*/
public function testReverseTransformWithGroupingAndFixedSpaces()
{
Expand Down Expand Up @@ -583,7 +581,6 @@ public function testReverseTransformDisallowsCenteredExtraCharacters()
/**
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
* @expectedExceptionMessage The number contains unrecognized characters: "foo8"
* @requires extension mbstring
*/
public function testReverseTransformDisallowsCenteredExtraCharactersMultibyte()
{
Expand All @@ -600,7 +597,6 @@ public function testReverseTransformDisallowsCenteredExtraCharactersMultibyte()
/**
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
* @expectedExceptionMessage The number contains unrecognized characters: "foo8"
* @requires extension mbstring
*/
public function testReverseTransformIgnoresTrailingSpacesInExceptionMessage()
{
Expand Down Expand Up @@ -628,7 +624,6 @@ public function testReverseTransformDisallowsTrailingExtraCharacters()
/**
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
* @expectedExceptionMessage The number contains unrecognized characters: "foo"
* @requires extension mbstring
*/
public function testReverseTransformDisallowsTrailingExtraCharactersMultibyte()
{
Expand Down
1 change: 0 additions & 1 deletion src/Symfony/Component/Form/Tests/Util/StringUtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public function testTrim()

/**
* @dataProvider spaceProvider
* @requires extension mbstring
*/
public function testTrimUtf8Separators($hex)
{
Expand Down
Loading
0