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

Skip to content
10000

Commit 72501cd

Browse files
committed
Merge branch '2.7' into 2.8
* 2.7: [HttpCache] Unlink tmp file on error Added LB translation for #26327 (Errors sign for people that do not see colors) [TwigBridge] Fix rendering of currency by MoneyType [HttpKernel] DumpDataCollector: do not flush when a dumper is provided
2 parents e3201b8 + 913c1fd commit 72501cd

File tree

14 files changed

+128
-7
lines changed

14 files changed

+128
-7
lines changed

src/Symfony/Bridge/Twig/Extension/FormExtension.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ public function getFilters()
8888
{
8989
return array(
9090
new TwigFilter('humanize', array($this, 'humanize')),
91+
new TwigFilter('form_encode_currency', array($this, 'encodeCurrency'), array('is_safe' => array('html'), 'needs_environment' => true)),
9192
);
9293
}
9394

@@ -166,6 +167,22 @@ public function isRootForm(FormView $formView)
166167
return null === $formView->parent;
167168
}
168169

170+
/**
171+
* @internal
172+
*/
173+
public function encodeCurrency(Environment $environment, $text, $widget = '')
174+
{
175+
if ('UTF-8' === $charset = $environment->getCharset()) {
176+
$text = htmlspecialchars($text, ENT_QUOTES | (\defined('ENT_SUBSTITUTE') ? ENT_SUBSTITUTE : 0), 'UTF-8');
177+
} else {
178+
$text = htmlentities($text, ENT_QUOTES | (\defined('ENT_SUBSTITUTE') ? ENT_SUBSTITUTE : 0), 'UTF-8');
179+
$text = iconv('UTF-8', $charset, $text);
180+
$widget = iconv('UTF-8', $charset, $widget);
181+
}
182+
183+
return str_replace('{{ widget }}', $widget, $text);
184+
}
185+
169186
/**
170187
* {@inheritdoc}
171188
*/

src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_3_layout.html.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@
2525
{% if prepend or append %}
2626
<div class="input-group">
2727
{% if prepend %}
28-
<span class="input-group-addon">{{ money_pattern|replace({ '{{ widget }}':''}) }}</span>
28+
<span class="input-group-addon">{{ money_pattern|form_encode_currency }}</span>
2929
{% endif %}
3030
{{- block('form_widget_simple') -}}
3131
{% if append %}
32-
<span class="input-group-addon">{{ money_pattern|replace({ '{{ widget }}':''}) }}</span>
32+
<span class="input-group-addon">{{ money_pattern|form_encode_currency }}</span>
3333
{% endif %}
3434
</div>
3535
{% else %}

src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@
142142
{%- endblock integer_widget -%}
143143

144144
{%- block money_widget -%}
145-
{{ money_pattern|replace({ '{{ widget }}': block('form_widget_simple') })|raw }}
145+
{{ money_pattern|form_encode_currency(block('form_widget_simple')) }}
146146
{%- endblock money_widget -%}
147147

148148
{%- block url_widget -%}

src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionBootstrap3LayoutTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,31 @@ public function testStartTagHasActionAttributeWhenActionIsZero()
8787
$this->assertSame('<form name="form" method="get" action="0">', $html);
8888
}
8989

90+
public function testMoneyWidgetInIso()
91+
{
92+
$environment = new Environment(new StubFilesystemLoader(array(
93+
__DIR__.'/../../Resources/views/Form',
94+
__DIR__.'/Fixtures/templates/form',
95+
)), array('strict_variables' => true));
96+
$environment->addExtension(new TranslationExtension(new StubTranslator()));
97+
$environment->addExtension($this->extension);
98+
$environment->setCharset('ISO-8859-1');
99+
100+
$this->extension->initRuntime($environment);
101+
102+
$view = $this->factory
103+
->createNamed('name', 'money')
104+
->createView()
105+
;
106+
107+
$this->assertSame(<<<'HTML'
108+
<div class="input-group">
109+
<span class="input-group-addon">&euro; </span>
110+
<input type="text" id="name" name="name" required="required" class="form-control" /> </div>
111+
HTML
112+
, trim($this->renderWidget($view)));
113+
}
114+
90115
protected function renderForm(FormView $view, array $vars = array())
91116
{
92117
return (string) $this->extension->renderer->renderBlock($view, 'form', $vars);

src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionDivLayoutTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,26 @@ public function testIsRootForm($expected, FormView $formView)
186186
$this->assertSame($expected, $this->extension->isRootForm($formView));
187187
}
188188

189+
public function testMoneyWidgetInIso()
190+
{
191+
$environment = new Environment(new StubFilesystemLoader(array(
192+
__DIR__.'/../../Resources/views/Form',
193+
__DIR__.'/Fixtures/templates/form',
194+
)), array('strict_variables' => true));
195+
$environment->addExtension(new TranslationExtension(new StubTranslator()));
196+
$environment->addExtension($this->extension);
197+
$environment->setCharset('ISO-8859-1');
198+
199+
$this->extension->initRuntime($environment);
200+
201+
$view = $this->factory
202+
->createNamed('name', 'money')
203+
->createView()
204+
;
205+
206+
$this->assertSame('&euro; <input type="text" id="name" name="name" required="required" />', $this->renderWidget($view));
207+
}
208+
189209
protected function renderForm(FormView $view, array $vars = array())
190210
{
191211
return (string) $this->extension->renderer->renderBlock($view, 'form', $vars);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php echo str_replace('{{ widget }}', $view['form']->block($form, 'form_widget_simple'), $money_pattern) ?>
1+
<?php echo $view['form']->formEncodeCurrency($money_pattern, $view['form']->block($form, 'form_widget_simple')) ?>

src/Symfony/Bundle/FrameworkBundle/Templating/Helper/FormHelper.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,4 +260,20 @@ public function humanize($text)
260260
{
261261
return $this->renderer->humanize($text);
262262
}
263+
264+
/**
265+
* @internal
266+
*/
267+
public function formEncodeCurrency($text, $widget = '')
268+
{
269+
if ('UTF-8' === $charset = $this->getCharset()) {
270+
$text = htmlspecialchars($text, ENT_QUOTES | (\defined('ENT_SUBSTITUTE') ? ENT_SUBSTITUTE : 0), 'UTF-8');
271+
} else {
272+
$text = htmlentities($text, ENT_QUOTES | (\defined('ENT_SUBSTITUTE') ? ENT_SUBSTITUTE : 0), 'UTF-8');
273+
$text = iconv('UTF-8', $charset, $text);
274+
$widget = iconv('UTF-8', $charset, $widget);
275+
}
276+
277+
return str_replace('{{ widget }}', $widget, $text);
278+
}
263279
}

src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/FormHelperDivLayoutTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,18 @@ public function testStartTagHasActionAttributeWhenActionIsZero()
8585
$this->assertSame('<form name="form" method="get" action="0">', $html);
8686
}
8787

88+
public function testMoneyWidgetInIso()
89+
{
90+
$this->engine->setCharset('ISO-8859-1');
91+
92+
$view = $this->factory
93+
->createNamed('name', 'money')
94+
->createView()
95+
;
96+
97+
$this->assertSame('&euro; <input type="text" id="name" name="name" required="required" />', $this->renderWidget($view));
98+
}
99+
88100
protected function renderForm(FormView $view, array $vars = array())
89101
{
90102
return (string) $this->engine->get('form')->form($view, $vars);

src/Symfony/Bundle/FrameworkBundle/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"symfony/security-core": "~2.6.13|~2.7.9|~2.8|~3.0.0",
3333
"symfony/security-csrf": "~2.6|~3.0.0",
3434
"symfony/stopwatch": "~2.3|~3.0.0",
35-
"symfony/templating": "~2.1|~3.0.0",
35+
"symfony/templating": "~2.7|~3.0.0",
3636
"symfony/translation": "~2.8",
3737
"doctrine/cache": "~1.0",
3838
"doctrine/annotations": "~1.0"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function getBlockPrefix()
9191
}
9292

9393
/**
94-
* Returns the pattern for this locale.
94+
* Returns the pattern for this locale in UTF-8.
9595
*
9696
* The pattern contains the placeholder "{{ widget }}" where the HTML tag should
9797
* be inserted

src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function dump(Data $data)
6767
if ($this->stopwatch) {
6868
$this->stopwatch->start('dump');
6969
}
70-
if ($this->isCollected) {
70+
if ($this->isCollected && !$this->dumper) {
7171
$this->isCollected = false;
7272
}
7373

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,16 +387,22 @@ private function save($key, $data)
387387

388388
$tmpFile = tempnam(dirname($path), basename($path));
389389
if (false === $fp = @fopen($tmpFile, 'wb')) {
390+
@unlink($tmpFile);
391+
390392
return false;
391393
}
392394
@fwrite($fp, $data);
393395
@fclose($fp);
394396

395397
if ($data != file_get_contents($tmpFile)) {
398+
@unlink($tmpFile);
399+
396400
return false;
397401
}
398402

399403
if (false === @rename($tmpFile, $path)) {
404+
@unlink($tmpFile);
405+
400406
return false;
401407
}
402408
}

src/Symfony/Component/HttpKernel/Tests/DataCollector/DumpDataCollectorTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\HttpFoundation\Request;
1717
use Symfony\Component\HttpFoundation\Response;
1818
use Symfony\Component\VarDumper\Cloner\Data;
19+
use Symfony\Component\VarDumper\Dumper\CliDumper;
1920

2021
/**
2122
* @author Nicolas Grekas <p@tchwork.com>
@@ -130,4 +131,24 @@ public function testFlush()
130131
$this->assertSame("\"DumpDataCollectorTest.php on line {$line}:\"\n456\n", ob_get_clean());
131132
}
132133
}
134+
135+
public function testFlushNothingWhenDataDumperIsProvided()
136+
{
137+
$data = new Data(array(array(456)));
138+
$dumper = new CliDumper('php://output');
139+
$collector = new DumpDataCollector(null, null, null, null, $dumper);
140+
141+
ob_start();
142+
$collector->dump($data);
143+
$line = __LINE__ - 1;
144+
if (\PHP_VERSION_ID >= 50400) {
145+
$this->assertSame("DumpDataCollectorTest.php on line {$line}:\n456\n", ob_get_clean());
146+
} else {
147+
$this->assertSame("\"DumpDataCollectorTest.php on line {$line}:\"\n456\n", ob_get_clean());
148+
}
149+
150+
ob_start();
151+
$collector->__destruct();
152+
$this->assertEmpty(ob_get_clean());
153+
}
133154
}

src/Symfony/Component/Validator/Resources/translations/validators.lb.xlf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,10 @@
314314
<source>This is not a valid Business Identifier Code (BIC).</source>
315315
<target>Dëst ass kee gëltege "Business Identifier Code" (BIC).</target>
316316
</trans-unit>
317+
<trans-unit id="82">
318+
<source>Error</source>
319+
<target>Feeler</target>
320+
</trans-unit>
317321
</body>
318322
</file>
319323
</xliff>

0 commit comments

Comments
 (0)
0