10000 Allow binary values in parameters. · symfony/symfony@c43ca2c · GitHub
[go: up one dir, main page]

Skip to content

Commit c43ca2c

Browse files
committed
Allow binary values in parameters.
1 parent 332ad0a commit c43ca2c

File tree

8 files changed

+21
-1
lines changed

8 files changed

+21
-1
lines changed

src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1775,7 +1775,12 @@ private function export($value)
17751775

17761776
private function doExport($value, $resolveEnv = false)
17771777
{
1778-
if (is_string($value) && false !== strpos($value, "\n")) {
1778+
if (is_string($value) && preg_match('/[\x00-\x08\x0b-\x1f\x7f-\xff]+/', $value,$matches)) {
1779+
$toHex = function (&$values, $char) {
1780+
return $values . sprintf('\\x%02x', ord($char));
1781+
};
1782+
$export = '"'.array_reduce(str_split($value), $toHex, '').'"';
1783+
} elseif (is_string($value) && false !== strpos($value, "\n")) {
17791784
$cleanParts = explode("\n", $value);
17801785
$cleanParts = array_map(function ($part) { return var_export($part, true); }, $cleanParts);
17811786
$export = implode('."\n".', $cleanParts);
10000

src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,10 @@ private function convertParameters(array $parameters, $type, \DOMElement $parent
298298
$element->setAttribute('type', 'expression');
299299
$text = $this->document->createTextNode(self::phpToXml((string) $value));
300300
$element->appendChild($text);
301+
} elseif (is_string($value) && preg_match('/[\x00-\x08\x0b-\x1f\x7f-\xff]/', $value)) {
302+
$element->setAttribute('type', 'binary');
303+
$text = $this->document->createTextNode(self::phpToXml(base64_encode($value)));
304+
$element->appendChild($text);
301305
} else {
302306
if (in_array($value, array('null', 'true', 'false'), true)) {
303307
$element->setAttribute('type', 'string');

src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,12 @@ private function getArgumentsAsPhp(\DOMElement $node, $name, $file, $lowercase =
511511
}
512512
$arguments[$key] = new TaggedIteratorArgument($arg->getAttribute('tag'));
513513
break;
514+
case 'binary':
515+
if (!preg_match('#^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)$#', $arg->nodeValue)) {
516+
throw new InvalidArgumentException(sprintf('Tag "<%s>" with type="binary" is not valid base64 encoded string', $name));
517+
}
518+
$arguments[$key] = base64_decode($arg->nodeValue);
519+
break;
514520
case 'string':
515521
$arguments[$key] = $arg->nodeValue;
516522
break;

src/Symfony/Component/DependencyInjection/Loader/schema/dic/services/services-1.0.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@
246246
<xsd:enumeration value="collection" />
247247
<xsd:enumeration value="string" />
248248
<xsd:enumeration value="constant" />
249+
<xsd:enumeration value="binary" />
249250
</xsd:restriction>
250251
</xsd:simpleType>
251252

src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container8.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
'bar' => 'foo is %%foo bar',
1010
'escape' => '@escapeme',
1111
'values' => array(true, false, null, 0, 1000.3, 'true', 'false', 'null'),
12+
'binary' => "\xf0\xf0\xf0\xf0",
1213
)));
1314

1415
return $container;

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services8.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ protected function getDefaultParameters()
135135
6 => 'false',
136136
7 => 'null',
137137
),
138+
'binary' => "\xf0\xf0\xf0\xf0",
138139
);
139140
}
140141
}

src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services8.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<parameter type="string">false</parameter>
1919
<parameter type="string">null</parameter>
2020
</parameter>
21+
<parameter key="binary" type="binary">8PDw8A==</parameter>
2122
</parameters>
2223
<services>
2324
<service id="service_container" class="Symfony\Component\DependencyInjection\ContainerInterface" public="true" synthetic="true"/>

src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services8.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ parameters:
44
bar: 'foo is %%foo bar'
55
escape: '@@escapeme'
66
values: [true, false, null, 0, 1000.3, 'true', 'false', 'null']
7+
binary: !!binary 8PDw8A==
78

89
services:
910
service_container:

0 commit comments

Comments
 (0)
0