8000 Merge branch '2.7' into 2.8 · symfony/symfony@e8e7ff2 · GitHub
[go: up one dir, main page]

Skip to content

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 e8e7ff2

Browse files
committed
Merge branch '2.7' into 2.8
* 2.7: fixed Twig URL Don't assume that file binary exists on *nix OS Fix that ESI/SSI processing can turn a \"private\" response \"public\" [Form] Fixed trimming choice values
2 parents 32c04bd + f981f7a commit e8e7ff2

File tree

7 files changed

+101
-7
lines changed

7 files changed

+101
-7
lines changed

src/Symfony/Bridge/Twig/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Twig Bridge
22
===========
33

4-
Provides integration for [Twig](http://twig.sensiolabs.org/) with various
4+
Provides integration for [Twig](https://twig.symfony.com/) with various
55
Symfony components.
66

77
Resources

src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ public function configureOptions(OptionsResolver $resolver)
421421
// See https://github.com/symfony/symfony/pull/5582
422422
'data_class' => null,
423423
'choice_translation_domain' => true,
424+
'trim' => false,
424425
));
425426

426427
$resolver->setNormalizer('choices', $choicesNormalizer);

src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2567,4 +2567,59 @@ public function testStripLeadingUnderscoresAndDigitsFromId()
25672567
$this->assertEquals('_09name', $view->vars['name']);
25682568
$this->assertEquals('_09name', $view->vars['full_name']);
25692569
}
2570+
2571+
/**
2572+
* @dataProvider provideTrimCases
2573+
*/
2574+
public function testTrimIsDisabled($multiple, $expanded)
2575+
{
2576+
$form = $this->factory->create(static::TESTED_TYPE, null, array(
2577+
'multiple' => $multiple,
2578+
'expanded' => $expanded,
2579+
'choices' => array(
2580+
'a' => '1',
2581+
),
2582+
'choices_as_values' => true,
2583+
));
2584+
2585+
$submittedData = ' 1';
2586+
2587+
$form->submit($multiple ? (array) $submittedData : $submittedData);
2588+
2589+
// When the choice does not exist the transformation fails
2590+
$this->assertFalse($form->isSynchronized());
2591+
$this->assertNull($form->getData());
2592+
}
2593+
2594+
/**
2595+
* @dataProvider provideTrimCases
2596+
*/
2597+
public function testSubmitValueWithWhiteSpace($multiple, $expanded)
2598+
{
2599+
$valueWhitWhiteSpace = '1 ';
2600+
2601+
$form = $this->factory->create(static::TESTED_TYPE, null, array(
2602+
'multiple' => $multiple,
2603+
'expanded' => $expanded,
2604+
'choices' => array(
2605+
'a' => $valueWhitWhiteSpace,
2606+
),
2607+
'choices_as_values' => true,
2608+
));
2609+
2610+
$form->submit($multiple ? (array) $valueWhitWhiteSpace : $valueWhitWhiteSpace);
2611+
2612+
$this->assertTrue($form->isSynchronized());
2613+
$this->assertSame($multiple ? (array) $valueWhitWhiteSpace : $valueWhitWhiteSpace, $form->getData());
2614+
}
2615+
2616+
public function provideTrimCases()
2617+
{
2618+
return array(
2619+
'Simple' => array(false, false),
2620+
'Multiple' => array(true, false),
2621+
'Simple expanded' => array(false, true),
2622+
'Multiple expanded' => array(true, true),
2623+
);
2624+
}
25702625
}

src/Symfony/Component/HttpFoundation/File/MimeType/FileBinaryMimeTypeGuesser.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,21 @@ public function __construct($cmd = 'file -b --mime %s 2>/dev/null')
4343
*/
4444
public static function isSupported()
4545
{
46-
return '\\' !== DIRECTORY_SEPARATOR && function_exists('passthru') && function_exists('escapeshellarg');
46+
static $supported = null;
47+
48+
if (null !== $supported) {
49+
return $supported;
50+
}
51+
52+
if ('\\' === DIRECTORY_SEPARATOR || !function_exists('passthru') || !function_exists('escapeshellarg')) {
53+
return $supported = false;
54+
}
55+
56+
ob_start();
57+
passthru('command -v file', $exitStatus);
58+
$binPath = trim(ob_get_clean());
59+
60+
return $supported = 0 === $exitStatus && '' !== $binPath;
4761
}
4862

4963
/**

src/Symfony/Component/HttpFoundation/Response.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -513,13 +513,19 @@ public function getCharset()
513513
}
514514

515515
/**
516-
* Returns true if the response is worth caching under any circumstance.
516+
* Returns true if the response may safely be kept in a shared (surrogate) cache.
517517
*
518518
* Responses marked "private" with an explicit Cache-Control directive are
519519
* considered uncacheable.
520520
*
521521
* Responses with neither a freshness lifetime (Expires, max-age) nor cache
522-
* validator (Last-Modified, ETag) are considered uncacheable.
522+
* validator (Last-Modified, ETag) are considered uncacheable because there is
523+
* no way to tell when or how to remove them from the cache.
524+
*
525+
* Note that RFC 7231 and RFC 7234 possibly allow for a more permissive implementation,
526+
* for example "status codes that are defined as cacheable by default [...]
527+
* can be reused by a cache with heuristic expiration unless otherwise indicated"
528+
* (https://tools.ietf.org/html/rfc7231#section-6.1)
523529
*
524530
* @return bool true if the response is worth caching, false otherwise
525531
*/

src/Symfony/Component/HttpKernel/HttpCache/ResponseCacheStrategy.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function update(Response $response)
7272
$response->setLastModified(null);
7373
}
7474

75-
if (!$response->isFresh()) {
75+
if (!$response->isFresh() || !$response->isCacheable()) {
7676
$this->cacheable = false;
7777
}
7878

src/Symfony/Component/HttpKernel/Tests/HttpCache/ResponseCacheStrategyTest.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,26 @@ public function testEmbeddingPrivateResponseMakesMainResponsePrivate()
175175
$cacheStrategy->update($masterResponse);
176176

177177
$this->assertTrue($masterResponse->headers->hasCacheControlDirective('private'));
178-
// Not sure if we should pass "max-age: 60" in this case, as long as the response is private and
179-
// that's the more conservative of both the master and embedded response...?
178+
$this->assertFalse($masterResponse->headers->hasCacheControlDirective('public'));
179+
}
180+
181+
public function testEmbeddingPublicResponseDoesNotMakeMainResponsePublic()
182+
{
183+
$cacheStrategy = new ResponseCacheStrategy();
184+
185+
$masterResponse = new Response();
186+
$masterResponse->setPrivate(); // this is the default, but let's be explicit
187+
$masterResponse->setMaxAge(100);
188+
189+
$embeddedResponse = new Response();
190+
$embeddedResponse->setPublic();
191+
$embeddedResponse->setSharedMaxAge(100);
192+
193+
$cacheStrategy->add($embeddedResponse);
194+
$cacheStrategy->update($masterResponse);
195+
196+
$this->assertTrue($masterResponse->headers->hasCacheControlDirective('private'));
197+
$this->assertFalse($masterResponse->headers->hasCacheControlDirective('public'));
180198
}
181199

182200
public function testResponseIsExiprableWhenEmbeddedResponseCombinesExpiryAndValidation()

0 commit comments

Comments
 (0)
0