Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 527dc6a

Browse files
committed
Set $escapeFormulas to false by default
1 parent e254fcb commit 527dc6a

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

src/Symfony/Component/Serializer/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ CHANGELOG
1111
* added an optional `string $format = null` argument to `AbstractNormalizer::instantiateObject`
1212
* added an optional `array $context = array()` to `Serializer::supportsNormalization`, `Serializer::supportsDenormalization`,
1313
`Serializer::supportsEncoding` and `Serializer::supportsDecoding`
14-
* added optional `bool $escapeFormulas = true` argument to `CsvEncoder::__construct`
14+
* added optional `bool $escapeFormulas = false` argument to `CsvEncoder::__construct`
1515

1616
3.4.0
1717
-----

src/Symfony/Component/Serializer/Encoder/CsvEncoder.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ class CsvEncoder implements EncoderInterface, DecoderInterface
2727
const ESCAPE_CHAR_KEY = 'csv_escape_char';
2828
const KEY_SEPARATOR_KEY = 'csv_key_separator';
2929
const HEADERS_KEY = 'csv_headers';
30-
const FORMULAS_START_CHARACTERS = array('=', '-', '+', '@');
3130

3231
private $delimiter;
3332
private $enclosure;
3433
private $escapeChar;
3534
private $keySeparator;
3635
private $escapeFormulas;
36+
private $formulasStartCharacters = array('=', '-', '+', '@');
3737

3838
/**
3939
* @param string $delimiter
@@ -42,7 +42,7 @@ class CsvEncoder implements EncoderInterface, DecoderInterface
4242
* @param string $keySeparator
4343
* @param bool $escapeFormulas
4444
*/
45-
public function __construct($delimiter = ',', $enclosure = '"', $escapeChar = '\\', $keySeparator = '.', $escapeFormulas = true)
45+
public function __construct($delimiter = ',', $enclosure = '"', $escapeChar = '\\', $keySeparator = '.', $escapeFormulas = false)
4646
{
4747
$this->delimiter = $delimiter;
4848
$this->enclosure = $enclosure;
@@ -190,7 +190,7 @@ private function flatten(array $array, array &$result, $keySeparator, $parentKey
190190
if (is_array($value)) {
191191
$this->flatten($value, $result, $keySeparator, $parentKey.$key.$keySeparator);
192192
} else {
193-
if ($this->escapeFormulas && \in_array(mb_substr($value, 0, 1), self::FORMULAS_START_CHARACTERS, true)) {
193+
if ($this->escapeFormulas && \in_array(mb_substr($value, 0, 1), $this->formulasStartCharacters, true)) {
194194
$result[$parentKey.$key] = "\t".$value;
195195
} else {
196196
$result[$parentKey.$key] = $value;

src/Symfony/Component/Serializer/Tests/Encoder/CsvEncoderTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -175,28 +175,30 @@ public function testEncodeCustomHeaders()
175175

176176
public function testEncodeFormulaValues()
177177
{
178-
$this->assertEquals(<<<'CSV'
178+
$this->encoder = new CsvEncoder(',', '"', '\\', '.', true);
179+
180+
$this->assertSame(<<<'CSV'
179181
0
180182
" =2+3"
181183

182184
CSV
183185
, $this->encoder->encode(array('=2+3'), 'csv'));
184186

185-
$this->assertEquals(<<<'CSV'
187+
$this->assertSame(<<<'CSV'
186188
0
187189
" -2+3"
188190

189191
CSV
190192
, $this->encoder->encode(array('-2+3'), 'csv'));
191193

192-
$this->assertEquals(<<<'CSV'
194+
$this->assertSame(<<<'CSV'
193195
0
194196
" +2+3"
195197

196198
CSV
197199
, $this->encoder->encode(array('+2+3'), 'csv'));
198200

199-
$this->assertEquals(<<<'CSV'
201+
$this->assertSame(<<<'CSV'
200202
0
201203
" @MyDataColumn"
202204

@@ -206,30 +208,28 @@ public function testEncodeFormulaValues()
206208

207209
public function testDoNotEncodeFormulaValues()
208210
{
209-
$this->encoder = new CsvEncoder(',', '"', '\\', '.', false);
210-
211-
$this->assertEquals(<<<'CSV'
211+
$this->assertSame(<<<'CSV'
212212
0
213213
=2+3
214214

215215
CSV
216216
, $this->encoder->encode(array('=2+3'), 'csv'));
217217

218-
$this->assertEquals(<<<'CSV'
218+
$this->assertSame(<<<'CSV'
219219
0
220220
-2+3
221221

222222
CSV
223223
, $this->encoder->encode(array('-2+3'), 'csv'));
224224

225-
$this->assertEquals(<<<'CSV'
225+
$this->assertSame(<<<'CSV'
226226
0
227227
+2+3
228228

229229
CSV
230230
, $this->encoder->encode(array('+2+3'), 'csv'));
231231

232-
$this->assertEquals(<<<'CSV'
232+
$this->assertSame(<<<'CSV'
233233
0
234234
@MyDataColumn
235235

0 commit comments

Comments
 (0)