Skip to content

Navigation Menu

Sign in
Appearance settings

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 bd9dc7c

Browse filesBrowse files
committed
feature #35029 [DI] allow "." and "-" in env processor lines (nicolas-grekas)
This PR was merged into the 5.1-dev branch. Discussion ---------- [DI] allow "." and "-" in env processor lines | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | Fix #34864 | License | MIT | Doc PR | - As explained in the linked issue, this is especially usefull with the `key` processor. Commits ------- 231c505 [DI] allow "." and "-" in env processor lines
2 parents 40c1351 + 231c505 commit bd9dc7c
Copy full SHA for bd9dc7c

File tree

3 files changed

+10
-3
lines changed
Filter options

3 files changed

+10
-3
lines changed

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1360,7 +1360,7 @@ private function registerSecretsConfiguration(array $config, ContainerBuilder $c
13601360
}
13611361

13621362
if ($config['decryption_env_var']) {
1363-
if (!preg_match('/^(?:\w*+:)*+\w++$/', $config['decryption_env_var'])) {
1363+
if (!preg_match('/^(?:[-.\w]*+:)*+\w++$/', $config['decryption_env_var'])) {
13641364
throw new InvalidArgumentException(sprintf('Invalid value "%s" set as "decryption_env_var": only "word" characters are allowed.', $config['decryption_env_var']));
13651365
}
13661366

‎src/Symfony/Component/DependencyInjection/ParameterBag/EnvPlaceholderParameterBag.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/ParameterBag/EnvPlaceholderParameterBag.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ public function get(string $name)
4444
return $placeholder; // return first result
4545
}
4646
}
47-
if (!preg_match('/^(?:\w*+:)*+\w++$/', $env)) {
47+
if (!preg_match('/^(?:[-.\w]*+:)*+\w++$/', $env)) {
4848
throw new InvalidArgumentException(sprintf('Invalid %s name: only "word" characters are allowed.', $name));
4949
}
5050
if ($this->has($name) && null !== ($defaultValue = parent::get($name)) && !\is_string($defaultValue)) {
5151
throw new RuntimeException(sprintf('The default value of an env() parameter must be a string or null, but "%s" given to "%s".', \gettype($defaultValue), $name));
5252
}
5353

5454
$uniqueName = md5($name.'_'.self::$counter++);
55-
$placeholder = sprintf('%s_%s_%s', $this->getEnvPlaceholderUniquePrefix(), str_replace(':', '_', $env), $uniqueName);
55+
$placeholder = sprintf('%s_%s_%s', $this->getEnvPlaceholderUniquePrefix(), strtr($env, ':-.', '___'), $uniqueName);
5656
$this->envPlaceholders[$env][$placeholder] = $placeholder;
5757

5858
return $placeholder;

‎src/Symfony/Component/DependencyInjection/Tests/ParameterBag/EnvPlaceholderParameterBagTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/ParameterBag/EnvPlaceholderParameterBagTest.php
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,4 +187,11 @@ public function testDefaultToNullAllowed()
187187
$bag->resolve();
188188
$this->assertNotNull($bag->get('env(default::BAR)'));
189189
}
190+
191+
public function testExtraCharsInProcessor()
192+
{
193+
$bag = new EnvPlaceholderParameterBag();
194+
$bag->resolve();
195+
$this->assertStringMatchesFormat('env_%s_key_a_b_c_FOO_%s', $bag->get('env(key:a.b-c:FOO)'));
196+
}
190197
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.