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

Skip to content

[DI] Allow binary values in parameters. #25928

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,10 @@ private function convertParameters(array $parameters, $type, \DOMElement $parent
$element->setAttribute('type', 'expression');
$text = $this->document->createTextNode(self::phpToXml((string) $value));
$element->appendChild($text);
} elseif (\is_string($value) && !preg_match('/^[^\x00-\x08\x0B\x0E-\x1A\x1C-\x1F\x7F]*+$/u', $value)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need the u modifier here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, to ensure string is a valid UTF8 string for XML file.

$element->setAttribute('type', 'binary');
$text = $this->document->createTextNode(self::phpToXml(base64_encode($value)));
$element->appendChild($text);
} else {
if (in_array($value, array('null', 'true', 'false'), true)) {
$element->setAttribute('type', 'string');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,12 @@ private function getArgumentsAsPhp(\DOMElement $node, $name, $file, $lowercase =
}
$arguments[$key] = new TaggedIteratorArgument($arg->getAttribute('tag'));
break;
case 'binary':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It this really legitimate? I mean: if !!binary is a core yaml feature, it should be transparent. Yaml tagged-values are only for custom tags, not core ones AFAIK.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked for a way to indicate in a XML file (which should be a valid UTF-8 file) that a value was base64_encoded(). I though this was the exact same purpose as in yaml file. I did not knew that !!binary was part of the yaml specification.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO using the same term here is legitimate. I would keep it as is.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, sorry, I misread the code, all good here

if (false === $value = base64_decode($arg->nodeValue)) {
throw new InvalidArgumentException(sprintf('Tag "<%s>" with type="binary" is not a valid base64 encoded string.', $name));
}
$arguments[$key] = $value;
break;
case 'string':
$arguments[$key] = $arg->nodeValue;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@
<xsd:enumeration value="collection" />
<xsd:enumeration value="string" />
<xsd:enumeration value="constant" />
<xsd:enumeration value="binary" />
</xsd:restriction>
</xsd:simpleType>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
'bar' => 'foo is %%foo bar',
'escape' => '@escapeme',
'values' => array(true, false, null, 0, 1000.3, 'true', 'false', 'null'),
'binary' => "\xf0\xf0\xf0\xf0",
'binary-control-char' => "This is a Bell char \x07",
)));

return $container;
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ protected function getDefaultParameters()
6 => 'false',
7 => 'null',
),
'binary' => '����',
'binary-control-char' => 'This is a Bell char ',
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
<parameter type="string">false</parameter>
<parameter type="string">null</parameter>
</parameter>
<parameter key="binary" type="binary">8PDw8A==</parameter>
<parameter key="binary-control-char" type="binary">VGhpcyBpcyBhIEJlbGwgY2hhciAH</parameter>
</parameters>
<services>
<service id="service_container" class="Symfony\Component\DependencyInjection\ContainerInterface" public="true" synthetic="true"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ parameters:
bar: 'foo is %%foo bar'
escape: '@@escapeme'
values: [true, false, null, 0, 1000.3, 'true', 'false', 'null']
binary: !!binary 8PDw8A==
binary-control-char: !!binary VGhpcyBpcyBhIEJlbGwgY2hhciAH

services:
service_container:
Expand Down