10000 Merge branch '2.2' into 2.3 · symfony/symfony@775a39c · GitHub
[go: up one dir, main page]

Skip to content

Commit 775a39c

Browse files
committed
Merge branch '2.2' into 2.3
* 2.2: [Locale] added support for the position argument to NumberFormatter::parse() [Locale] added some more stubs for the number formatter [Yaml] fixed typo [Yaml] fixed a test on PHP < 5.4 [DomCrawler]Crawler guess charset from html fixed PHP 5.3 compatibility [Yaml] reverted previous merge partially (refs #8897) [Security] remove unused logger [Security] fix typo [Yaml] Fixed filename in the ParseException message Conflicts: src/Symfony/Component/Console/Input/InputDefinition.php src/Symfony/Component/Locale/Stub/StubNumberFormatter.php src/Symfony/Component/Locale/Tests/Stub/StubNumberFormatterTest.php
2 parents 714d719 + 55560e0 commit 775a39c

File tree

11 files changed

+117
-70
lines changed

11 files changed

+117
-70
lines changed

src/Symfony/Bundle/SecurityBundle/Resources/config/security_listeners.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,6 @@
206206
<argument type="service" id="security.access.decision_manager" />
207207
<argument type="service" id="security.access_map" />
208208
<argument type="service" id="security.authentication.manager" />
209-
<argument type="service" id="logger" on-invalid="null" />
210209
</service>
211210
</services>
212211
</container>

src/Symfony/Component/Console/Input/InputDefinition.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111

1212
namespace Symfony\Component\Console\Input;
1313

14+
if (!defined('JSON_UNESCAPED_UNICODE')) {
15+
define('JSON_UNESCAPED_SLASHES', 64);
16+
define('JSON_UNESCAPED_UNICODE', 256);
17+
}
18+
1419
use Symfony\Component\Console\Descriptor\TextDescriptor;
1520
use Symfony\Component\Console\Descriptor\XmlDescriptor;
1621

src/Symfony/Component/DomCrawler/Crawler.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,19 +96,28 @@ public function addContent($content, $type = null)
9696
}
9797

9898
// DOM only for HTML/XML content
99-
if (!preg_match('/(x|ht)ml/i', $type, $matches)) {
99+
if (!preg_match('/(x|ht)ml/i', $type, $xmlMatches)) {
100100
return null;
101101
}
102102

103-
$charset = 'ISO-8859-1';
103+
$charset = null;
104104
if (false !== $pos = strpos($type, 'charset=')) {
105105
$charset = substr($type, $pos + 8);
106106
if (false !== $pos = strpos($charset, ';')) {
107107
$charset = substr($charset, 0, $pos);
108108
}
109109
}
110110

111-
if ('x' === $matches[1]) {
111+
if (null === $charset &&
112+
preg_match('/\<meta[^\>]+charset *= *["\']?([a-zA-Z\-0-9]+)/i', $content, $matches)) {
113+
$charset = $matches[1];
114+
}
115+
116+
if (null === $charset) {
117+
$charset = 'ISO-8859-1';
118+
}
119+
120+
if ('x' === $xmlMatches[1]) {
112121
$this->addXmlContent($content, $charset);
113122
} else {
114123
$this->addHtmlContent($content, $charset);

src/Symfony/Component/DomCrawler/Tests/CrawlerTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,10 @@ public function testAddContent()
216216
$crawler = new Crawler();
217217
$crawler->addContent('foo bar', 'text/plain');
218218
$this->assertCount(0, $crawler, '->addContent() does nothing if the type is not (x|ht)ml');
219+
220+
$crawler = new Crawler();
221+
$crawler->addContent('<html><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><span>中文</span></html>');
222+
$this->assertEquals('中文', $crawler->filterXPath('//span')->text(), '->addContent() guess wrong charset');
219223
}
220224

221225
/**

src/Symfony/Component/Intl/NumberFormatter/NumberFormatter.php

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,16 @@ class NumberFormatter
232232
'negative' => -9223372036854775808
233233
);
234234

235+
private static $enSymbols = array(
236+
self::DECIMAL => array('.', ',', ';', '%', '0', '#', '-', '+', '¤', '¤¤', '.', 'E', '', '*', '', 'NaN', '@', ','),
237+
self::CURRENCY => array('.', ',', ';', '%', '0', '#', '-', '+', '¤', '¤¤', '.', 'E', '', '*', '', 'NaN', '@', ','),
238+
);
239+
240+
private static $enTextAttributes = array(
241+
self::DECIMAL => array('', '', '-', '', '*', '', ''),
242+
self::CURRENCY => array('¤', '', '', ')', '*', ''),
243+
);
244+
235245
/**
236246
* Constructor.
237247
*
@@ -453,12 +463,10 @@ public function getPattern()
453463
* @return Boolean|string The symbol value or false on error
454464
*
455465
* @see http://www.php.net/manual/en/numberformatter.getsymbol.php
456-
*
457-
* @throws MethodNotImplementedException
458466
*/
459467
public function getSymbol($attr)
460468
{
461-
throw new MethodNotImplementedException(__METHOD__);
469+
return array_key_exists($this->style, self::$enSymbols) && array_key_exists($attr, self::$enSymbols[$this->style]) ? self::$enSymbols[$this->style][$attr] : false;
462470
}
463471

464472
/**
@@ -469,12 +477,10 @@ public function getSymbol($attr)
469477
* @return Boolean|string The attribute value or false on error
470478
*
471479
* @see http://www.php.net/manual/en/numberformatter.gettextattribute.php
472-
*
473-
* @throws MethodNotImplementedException
474480
*/
475481
public function getTextAttribute($attr)
476482
{
477-
throw new MethodNotImplementedException(__METHOD__);
483+
return array_key_exists($this->style, self::$enTextAttributes) && array_key_exists($attr, self::$enTextAttributes[$this->style]) ? self::$enTextAttributes[$this->style][$attr] : false;
478484
}
479485

480486
/**
@@ -499,44 +505,37 @@ public function parseCurrency($value, &$currency, &$position = null)
499505
* Parse a number
500506
*
501507
* @param string $value The value to parse
502-
* @param int $type Type of the formatting, one of the format type constants.
503-
* The only currently supported types are NumberFormatter::TYPE_DOUBLE,
504-
* NumberFormatter::TYPE_INT32 and NumberFormatter::TYPE_INT64.
505-
* @param int $position Not supported. Offset to begin the parsing on return this value will hold the offset at which the parsing ended
508+
* @param string $type Type of the formatting, one of the format type constants. NumberFormatter::TYPE_DOUBLE by default
509+
* @param int $position Offset to begin the parsing on return this value will hold the offset at which the parsing ended
506510
*
507511
* @return Boolean|string The parsed value of false on error
508512
*
509-
* @see http://www.php.net/manual/en/numberformatter.parse.php
510-
*
511-
* @throws MethodArgumentNotImplementedException When $position different than null, behavior not implemented
513+
* @see http://www.php.net/manual/en/numberformatter.parse.php
512514
*/
513-
public function parse($value, $type = self::TYPE_DOUBLE, &$position = null)
515+
public function parse($value, $type = self::TYPE_DOUBLE, &$position = 0)
514516
{
515517
if ($type == self::TYPE_DEFAULT || $type == self::TYPE_CURRENCY) {
516518
trigger_error(__METHOD__.'(): Unsupported format type '.$type, \E_USER_WARNING);
517519

518520
return false;
519521
}
520522

521-
// We don't calculate the position when parsing the value
522-
if (null !== $position) {
523-
throw new MethodArgumentNotImplementedException(__METHOD__, 'position');
524-
}
525-
526-
preg_match('/^([^0-9\-]{0,})(.*)/', $value, $matches);
523+
preg_match('/^([^0-9\-\.]{0,})(.*)/', $value, $matches);
527524

528525
// Any string before the numeric value causes error in the parsing
529526
if (isset($matches[1]) && !empty($matches[1])) {
530527
IntlGlobals::setError(IntlGlobals::U_PARSE_ERROR, 'Number parsing failed');
531528
$this->errorCode = IntlGlobals::getErrorCode();
532529
$this->errorMessage = IntlGlobals::getErrorMessage();
530+
$position = 0;
533531

534532
return false;
535533
}
536534

537-
// Remove everything that is not number or dot (.)
538-
$value = preg_replace('/[^0-9\.\-]/', '', $value);
535+
preg_match('/^[0-9\-\.\,]*/', $value, $matches);
536+
$value = preg_replace('/[^0-9\.\-]/', '', $matches[0]);
539537
$value = $this->convertValueDataType($value, $type);
538+
$position = strlen($matches[0]);
540539

541540
// behave like the intl extension
542541
$this->resetError();

src/Symfony/Component/Intl/Tests/NumberFormatter/AbstractNumberFormatterTest.php

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -472,14 +472,46 @@ public function testGetLocale()
472472
$this->assertEquals('en', $formatter->getLocale());
473473
}
474474

475+
public function testGetSymbol()
476+
{
477+
$decimalFormatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
478+
$currencyFormatter = $this->getNumberFormatter('en', NumberFormatter::CURRENCY);
479+
480+
$r = new \ReflectionProperty('Symfony\Component\Intl\NumberFormatter\NumberFormatter', 'enSymbols');
481+
$r->setAccessible(true);
482+
$expected = $r->getValue('Symfony\Component\Intl\NumberFormatter\NumberFormatter');
483+
484+
for ($i = 0; $i <= 17; $i++) {
485+
$this->assertSame($expected[1][$i], $decimalFormatter->getSymbol($i));
486+
$this->assertSame($expected[2][$i], $currencyFormatter->getSymbol($i));
487+
}
488+
}
489+
490+
public function testGetTextAttribute()
491+
{
492+
$decimalFormatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
493+
$currencyFormatter = $this->getNumberFormatter('en', NumberFormatter::CURRENCY);
494+
495+
$r = new \ReflectionProperty('Symfony\Component\Intl\NumberFormatter\NumberFormatter', 'enTextAttributes');
496+
$r->setAccessible(true);
497+
$expected = $r->getValue('Symfony\Component\Intl\NumberFormatter\NumberFormatter');
498+
499+
for ($i = 0; $i <= 5; $i++) {
500+
$this->assertSame($expected[1][$i], $decimalFormatter->getTextAttribute($i));
501+
$this->assertSame($expected[2][$i], $currencyFormatter->getTextAttribute($i));
502+
}
503+
}
504+
475505
/**
476506
* @dataProvider parseProvider
477507
*/
478-
public function testParse($value, $expected, $message = '')
508+
public function testParse($value, $expected, $message, $expectedPosition)
479509
{
510+
$position = 0;
480511
$formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
481-
$parsedValue = $formatter->parse($value, NumberFormatter::TYPE_DOUBLE);
512+
$parsedValue = $formatter->parse($value, NumberFormatter::TYPE_DOUBLE, $position);
482513
$this->assertSame($expected, $parsedValue, $message);
514+
$this->assertSame($expectedPosition, $position, $message);
483515

484516
if ($expected === false) {
485517
$errorCode = IntlGlobals::U_PARSE_ERROR;
@@ -500,8 +532,8 @@ public function testParse($value, $expected, $message = '')
500532
public function parseProvider()
501533
{
502534
return array(
503-
array('prefix1', false, '->parse() does not parse a number with a string prefix.'),
504-
array('1suffix', (float) 1, '->parse() parses a number with a string suffix.'),
535+
array('prefix1', false, '->parse() does not parse a number with a string prefix.', 0),
536+
array('1.4suffix', (float) 1.4, '->parse() parses a number with a string suffix.', 3),
505537
);
506538
}
507539

@@ -529,6 +561,7 @@ public function parseTypeInt32Provider()
529561
return array(
530562
array('1', 1),
531563
array('1.1', 1),
564+
array('.1', 0),
532565
array('2,147,483,647', 2147483647),
533566
array('-2,147,483,648', -2147483647 - 1),
534567
array('2,147,483,648', false, '->parse() TYPE_INT32 returns false when the number is greater than the integer positive range.'),
@@ -663,14 +696,6 @@ public function testParseTypeCurrency()
663696
$formatter->parse('1', NumberFormatter::TYPE_CURRENCY);
664697
}
665698

666-
public function testParseWithNullPositionValue()
667-
{
668-
$position = null;
669-
$formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
670-
$formatter->parse('123', NumberFormatter::TYPE_INT32, $position);
671-
$this->assertNull($position);
672-
}
673-
674699
public function testParseWithNotNullPositionValue()
675700
{
676701
$position = 1;

src/Symfony/Component/Intl/Tests/NumberFormatter/NumberFormatterTest.php

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -149,24 +149,6 @@ public function testGetPattern()
149149
$formatter->getPattern();
150150
}
151151

152-
/**
153-
* @expectedException \Symfony\Component\Intl\Exception\MethodNotImplementedException
154-
*/
155-
public function testGetSymbol()
156-
{
157-
$formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
158-
$formatter->getSymbol(null);
159-
}
160-
161-
/**
162-
* @expectedException \Symfony\Component\Intl\Exception\MethodNotImplementedException
163-
*/
164-
public function testGetTextAttribute()
165-
{
166-
$formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
167-
$formatter->getTextAttribute(null);
168-
}
169-
170152
public function testGetErrorCode()
171153
{
172154
$formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
@@ -182,14 +164,6 @@ public function testParseCurrency()
182164
$formatter->parseCurrency(null, $currency);
183165
}
184166

185-
/**
186-
* @expectedException \Symfony\Component\Intl\Exception\MethodArgumentNotImplementedException
187-
*/
188-
public function testParseWithNotNullPositionValue()
189-
{
190-
parent::testParseWithNotNullPositionValue();
191-
}
192-
193167
/**
194168
* @expectedException \Symfony\Component\Intl\Exception\MethodNotImplementedException
195169
*/

src/Symfony/Component/Security/Http/Firewall/AccessListener.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface;
1616
use Symfony\Component\Security\Http\AccessMapInterface;
1717
use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface;
18-
use Psr\Log\LoggerInterface;
1918
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
2019
use Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException;
2120
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
@@ -31,15 +30,13 @@ class AccessListener implements ListenerInterface
3130
private $accessDecisionManager;
3231
private $map;
3332
private $authManager;
34-
private $logger;
3533

36-
public function __construct(SecurityContextInterface $context, AccessDecisionManagerInterface $accessDecisionManager, AccessMapInterface $map, AuthenticationManagerInterface $authManager, LoggerInterface $logger = null)
34+
public function __construct(SecurityContextInterface $context, AccessDecisionManagerInterface $accessDecisionManager, AccessMapInterface $map, AuthenticationManagerInterface $authManager)
3735
{
3836
$this->context = $context;
3937
$this->accessDecisionManager = $accessDecisionManager;
4038
$this->map = $map;
4139
$this->authManager = $authManager;
42-
$this->logger = $logger;
4340
}
4441

4542
/**

src/Symfony/Component/Security/Http/FirewallMapInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ interface FirewallMapInterface
2424
* Returns the authentication listeners, and the exception listener to use
2525
* for the given request.
2626
*
27-
* If there are no authentication listeners, the first inner are must be
27+
* If there are no authentication listeners, the first inner array must be
2828
* empty.
2929
*
3030
* If there is no exception listener, the second element of the outer array

src/Symfony/Component/Yaml/Exception/ParseException.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111

1212
namespace Symfony\Component\Yaml\Exception;
1313

14+
if (!defined('JSON_UNESCAPED_UNICODE')) {
15+
define('JSON_UNESCAPED_SLASHES', 64);
16+
define('JSON_UNESCAPED_UNICODE', 256);
17+
}
18+
1419
/**
1520
* Exception class thrown when an error occurs during parsing.
1621
*
@@ -125,7 +130,7 @@ private function updateRepr()
125130
}
126131

127132
if (null !== $this->parsedFile) {
128-
$this->message .= sprintf(' in %s', json_encode($this->parsedFile));
133+
$this->message .= sprintf(' in %s', json_encode($this->parsedFile, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
129134
}
130135

131136
if ($this->parsedLine >= 0) {
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Yaml\Tests;
13+
14+
use Symfony\Component\Yaml\Exception\ParseException;
15+
use Symfony\Component\Yaml\Yaml;
16+
17+
class ParseExceptionTest extends \PHPUnit_Framework_TestCase
18+
{
19+
public function testGetMessage()
20+
{
21+
$exception = new ParseException('Error message', 42, 'foo: bar', '/var/www/app/config.yml');
22+
if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
23+
$message = 'Error message in "/var/www/app/config.yml" at line 42 (near "foo: bar")';
24+
} else {
25+
$message = 'Error message in "\\/var\\/www\\/app\\/config.yml" at line 42 (near "foo: bar")';
26+
}
27+
28+
$this->assertEquals($message, $exception->getMessage());
29+
}
30+
}

0 commit comments

Comments
 (0)
0