Skip to content

Commit

Permalink
Merge branch '2.7' into 2.8
Browse files Browse the repository at this point in the history
* 2.7:
  [Validator] added magic method __isset()  to File Constraint class
  [DI] Fix possible incorrect php-code when dumped strings contains newlines
  [Translation] minor: remove unused variable in test
  never match invalid IP addresses
  • Loading branch information
nicolas-grekas committed Oct 13, 2017
2 parents e71c4f7 + 2059609 commit d04c0ea
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 2 deletions.
Expand Up @@ -1587,6 +1587,13 @@ private function export($value)
return $dirname;
}

if (is_string($value) && false !== strpos($value, "\n")) {
$cleanParts = explode("\n", $value);
$cleanParts = array_map(function ($part) { return var_export($part, true); }, $cleanParts);

return implode('."\n".', $cleanParts);
}

return var_export($value, true);
}
}
Expand Up @@ -55,6 +55,7 @@ public function testDumpOptimizationString()
'optimize concatenation with empty string' => 'string1%empty_value%string2',
'optimize concatenation from the start' => '%empty_value%start',
'optimize concatenation at the end' => 'end%empty_value%',
'new line' => "string with \nnew line",
));

$container = new ContainerBuilder();
Expand Down
Expand Up @@ -56,7 +56,7 @@ public function isFrozen()
*/
protected function getTestService()
{
return $this->services['test'] = new \stdClass(array('only dot' => '.', 'concatenation as value' => '.\'\'.', 'concatenation from the start value' => '\'\'.', '.' => 'dot as a key', '.\'\'.' => 'concatenation as a key', '\'\'.' => 'concatenation from the start key', 'optimize concatenation' => 'string1-string2', 'optimize concatenation with empty string' => 'string1string2', 'optimize concatenation from the start' => 'start', 'optimize concatenation at the end' => 'end'));
return $this->services['test'] = new \stdClass(array('only dot' => '.', 'concatenation as value' => '.\'\'.', 'concatenation from the start value' => '\'\'.', '.' => 'dot as a key', '.\'\'.' => 'concatenation as a key', '\'\'.' => 'concatenation from the start key', 'optimize concatenation' => 'string1-string2', 'optimize concatenation with empty string' => 'string1string2', 'optimize concatenation from the start' => 'start', 'optimize concatenation at the end' => 'end', 'new line' => 'string with '."\n".'new line'));
}

/**
Expand Down
4 changes: 4 additions & 0 deletions src/Symfony/Component/HttpFoundation/IpUtils.php
Expand Up @@ -87,6 +87,10 @@ public static function checkIp4($requestIp, $ip)
$netmask = 32;
}

if (false === ip2long($address)) {
return self::$checkedIps[$cacheKey] = false;
}

return self::$checkedIps[$cacheKey] = 0 === substr_compare(sprintf('%032b', ip2long($requestIp)), sprintf('%032b', ip2long($address)), 0, $netmask);
}

Expand Down
17 changes: 17 additions & 0 deletions src/Symfony/Component/HttpFoundation/Tests/IpUtilsTest.php
Expand Up @@ -82,4 +82,21 @@ public function testAnIpv6WithOptionDisabledIpv6()

IpUtils::checkIp('2a01:198:603:0:396e:4789:8e99:890f', '2a01:198:603:0::/65');
}

/**
* @dataProvider invalidIpAddressData
*/
public function testInvalidIpAddressesDoNotMatch($requestIp, $proxyIp)
{
$this->assertFalse(IpUtils::checkIp4($requestIp, $proxyIp));
}

public function invalidIpAddressData()
{
return array(
'invalid proxy wildcard' => array('192.168.20.13', '*'),
'invalid proxy missing netmask' => array('192.168.20.13', '0.0.0.0'),
'invalid request IP with invalid proxy wildcard' => array('0.0.0.0', '*'),
);
}
}
2 changes: 1 addition & 1 deletion src/Symfony/Component/Translation/Tests/TranslatorTest.php
Expand Up @@ -25,7 +25,7 @@ class TranslatorTest extends TestCase
*/
public function testConstructorInvalidLocale($locale)
{
$translator = new Translator($locale, new MessageSelector());
new Translator($locale, new MessageSelector());
}

/**
Expand Down
9 changes: 9 additions & 0 deletions src/Symfony/Component/Validator/Constraints/File.php
Expand Up @@ -88,6 +88,15 @@ public function __get($option)
return parent::__get($option);
}

public function __isset($option)
{
if ('maxSize' === $option) {
return true;
}

return parent::__isset($option);
}

private function normalizeBinaryFormat($maxSize)
{
$sizeInt = (int) $maxSize;
Expand Down

0 comments on commit d04c0ea

Please sign in to comment.