Skip to content

Commit fcf8b33

Browse files
Merge branch '3.1' into 3.2
* 3.1: [ci] Update travis/appveyor [HttpFoundation] Validate/cast cookie expire time
2 parents c29f895 + e3e1cce commit fcf8b33

File tree

5 files changed

+28
-13
lines changed

5 files changed

+28
-13
lines changed

.travis.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ install:
8686
- if [[ ! $skip && $deps ]]; then export SYMFONY_DEPRECATIONS_HELPER=weak; fi
8787
- if [[ ! $skip && $deps ]]; then mv composer.json.phpunit composer.json; fi
8888
- if [[ ! $skip ]]; then composer update; fi
89-
- if [[ ! $skip ]]; then COMPOSER_ROOT_VERSION= ./phpunit install; fi
89+
- if [[ ! $skip ]]; then ./phpunit install; fi
9090
- if [[ ! $skip && ! $PHP = hhvm* ]]; then php -i; else hhvm --php -r 'print_r($_SERVER);print_r(ini_get_all());'; fi
9191

9292
script:
@@ -95,7 +95,7 @@ script:
9595
- if [[ ! $deps && ! $PHP = hhvm* ]]; then echo -e "\\nRunning tests requiring tty"; $PHPUNIT --group tty; fi
9696
- if [[ ! $deps && $PHP = hhvm* ]]; then $PHPUNIT --exclude-group benchmark,intl-data; fi
9797
- if [[ ! $deps && $PHP = ${MIN_PHP%.*} ]]; then echo -e "1\\n0" | xargs -I{} sh -c 'echo "\\nPHP --enable-sigchild enhanced={}" && ENHANCE_SIGCHLD={} php-$MIN_PHP/sapi/cli/php .phpunit/phpunit-4.8/phpunit --colors=always src/Symfony/Component/Process/'; fi
98-
- if [[ $deps = high ]]; then echo "$COMPONENTS" | parallel --gnu -j10% 'cd {}; composer update --no-progress --ansi; $PHPUNIT --exclude-group tty,benchmark,intl-data'$LEGACY; fi
99-
- if [[ $deps = low ]]; then echo "$COMPONENTS" | parallel --gnu -j10% 'cd {}; composer update --no-progress --ansi --prefer-lowest --prefer-stable; $PHPUNIT --exclude-group tty,benchmark,intl-data'; fi
98+
- if [[ $deps = high ]]; then echo "$COMPONENTS" | parallel --gnu -j10% 'cd {}; composer update --no-progress --ansi; $PHPUNIT --exclude-group tty,benchmark,intl-data'$LEGACY' && echo -e "\\e[33mOK\\e[0m {}" || (echo -e "\\e[41mKO\\e[0m {}" && $(exit 1))'; fi
99+
- if [[ $deps = low ]]; then echo "$COMPONENTS" | parallel --gnu -j10% 'cd {}; composer update --no-progress --ansi --prefer-lowest --prefer-stable; $PHPUNIT --exclude-group tty,benchmark,intl-data && echo -e "\\e[33mOK\\e[0m {}" || (echo -e "\\e[41mKO\\e[0m {}" && $(exit 1))'; fi
100100
# Test the PhpUnit bridge using the original phpunit script
101101
- if [[ $deps = low ]]; then (cd src/Symfony/Bridge/PhpUnit && phpenv global 5.3 && php --version && composer update && phpunit); fi

appveyor.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ clone_depth: 1
33
clone_folder: c:\projects\symfony
44

55
cache:
6-
- c:\projects\symfony\composer.phar
6+
- composer.phar
77
- .phpunit -> phpunit
88

99
init:
@@ -46,13 +46,12 @@ install:
4646
- echo curl.cainfo=c:\php\cacert.pem >> php.ini-max
4747
- copy /Y php.ini-max php.ini
4848
- cd c:\projects\symfony
49-
- IF NOT EXIST composer.phar (appveyor DownloadFile https://getcomposer.org/download/1.2.1/composer.phar)
49+
- IF NOT EXIST composer.phar (appveyor DownloadFile https://getcomposer.org/download/1.3.0/composer.phar)
5050
- php composer.phar self-update
5151
- copy /Y .composer\* %APPDATA%\Composer\
5252
- php .github/build-packages.php "HEAD^" src\Symfony\Bridge\PhpUnit
5353
- IF %APPVEYOR_REPO_BRANCH%==master (SET COMPOSER_ROOT_VERSION=dev-master) ELSE (SET COMPOSER_ROOT_VERSION=%APPVEYOR_REPO_BRANCH%.x-dev)
5454
- php composer.phar update --no-progress --ansi
55-
- SET COMPOSER_ROOT_VERSION=
5655
- php phpunit install
5756

5857
test_script:

phpunit

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/usr/bin/env php
22
<?php
33

4+
// Cache-Id: https://github.com/symfony/phpunit-bridge/commit/89cd0aab376105fb34e773e3dff641f68e3f9645
5+
46
if (!file_exists(__DIR__.'/vendor/symfony/phpunit-bridge/bin/simple-phpunit')) {
57
echo "Unable to find the `simple-phpunit` script in `vendor/symfony/phpunit-bridge/bin/`.\nPlease run `composer update` before running this command.\n";
68
exit(1);

src/Symfony/Component/HttpFoundation/Cookie.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,15 @@ public function __construct($name, $value = null, $expire = 0, $path = '/', $dom
6363
} elseif (!is_numeric($expire)) {
6464
$expire = strtotime($expire);
6565

66-
if (false === $expire || -1 === $expire) {
66+
if (false === $expire) {
6767
throw new \InvalidArgumentException('The cookie expiration time is not valid.');
6868
}
6969
}
7070

7171
$this->name = $name;
7272
$this->value = $value;
7373
$this->domain = $domain;
74-
$this->expire = $expire;
74+
$this->expire = 0 < $expire ? (int) $expire : 0;
7575
$this->path = empty($path) ? '/' : $path;
7676
$this->secure = (bool) $secure;
7777
$this->httpOnly = (bool) $httpOnly;
@@ -98,7 +98,7 @@ public function __toString()
9898
} else {
9999
$str .= $this->isRaw() ? $this->getValue() : urlencode($this->getValue());
100100

101-
if ($this->getExpiresTime() !== 0) {
101+
if (0 !== $this->getExpiresTime()) {
102102
$str .= '; expires='.gmdate('D, d-M-Y H:i:s T', $this->getExpiresTime());
103103
}
104104
}

src/Symfony/Component/HttpFoundation/Tests/CookieTest.php

+18-4
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,14 @@ public function testInstantiationThrowsExceptionIfCookieNameContainsInvalidChara
5252
*/
5353
public function testInvalidExpiration()
5454
{
55-
$cookie = new Cookie('MyCookie', 'foo', 'bar');
55+
new Cookie('MyCookie', 'foo', 'bar');
56+
}
57+
58+
public function testNegativeExpirationIsNotPossible()
59+
{
60+
$cookie = new Cookie('foo', 'bar', -100);
61+
62+
$this->assertSame(0, $cookie->getExpiresTime());
5663
}
5764

5865
public function testGetValue()
@@ -77,6 +84,13 @@ public function testGetExpiresTime()
7784
$this->assertEquals(3600, $cookie->getExpiresTime(), '->getExpiresTime() returns the expire date');
7885
}
7986

87+
public function testGetExpiresTimeIsCastToInt()
88+
{
89+
$cookie = new Cookie('foo', 'bar', 3600.9);
90+
91+
$this->assertSame(3600, $cookie->getExpiresTime(), '->getExpiresTime() returns the expire date as an integer');
92+
}
93+
8094
public function testConstructorWithDateTime()
8195
{
8296
$expire = new \DateTime();
@@ -143,13 +157,13 @@ public function testCookieIsCleared()
143157
public function testToString()
144158
{
145159
$cookie = new Cookie('foo', 'bar', strtotime('Fri, 20-May-2011 15:25:52 GMT'), '/', '.myfoodomain.com', true);
146-
$this->assertEquals('foo=bar; expires=Fri, 20-May-2011 15:25:52 GMT; path=/; domain=.myfoodomain.com; secure; httponly', $cookie->__toString(), '->__toString() returns string representation of the cookie');
160+
$this->assertEquals('foo=bar; expires=Fri, 20-May-2011 15:25:52 GMT; path=/; domain=.myfoodomain.com; secure; httponly', (string) $cookie, '->__toString() returns string representation of the cookie');
147161

148162
$cookie = new Cookie('foo', null, 1, '/admin/', '.myfoodomain.com');
149-
$this->assertEquals('foo=deleted; expires='.gmdate('D, d-M-Y H:i:s T', time() - 31536001).'; path=/admin/; domain=.myfoodomain.com; httponly', $cookie->__toString(), '->__toString() returns string representation of a cleared cookie if value is NULL');
163+
$this->assertEquals('foo=deleted; expires='.gmdate('D, d-M-Y H:i:s T', time() - 31536001).'; path=/admin/; domain=.myfoodomain.com; httponly', (string) $cookie, '->__toString() returns string representation of a cleared cookie if value is NULL');
150164

151165
$cookie = new Cookie('foo', 'bar', 0, '/', '');
152-
$this->assertEquals('foo=bar; path=/; httponly', $cookie->__toString());
166+
$this->assertEquals('foo=bar; path=/; httponly', (string) $cookie);
153167
}
154168

155169
public function testRawCookie()

0 commit comments

Comments
 (0)