Actions
Bug #91710
openResolving env-Variable in Site Configuration ignores values that resolve to "false"
Status:
New
Priority:
Should have
Assignee:
-
Category:
Link Handling, Site Handling & Routing
Target version:
-
Start date:
2020-06-25
Due date:
% Done:
0%
Estimated time:
TYPO3 Version:
9
PHP Version:
7.4
Tags:
environment,env,variable,getenv,yaml,site,configuration
Complexity:
Is Regression:
Sprint Focus:
Description
- Have an environment variable like MY_VARIABLE=0 or MY_VARIABLE="0" or MY_VARIABLE="" or MY_VARIABLE=.
- Add this variable to the site configuration YAML:
myVariable: '%env(MY_VARIABLE)'
- Access this env-var in TypoScript via e.g.
myVariable = TEXT myVariable.data = site:myVariable
- When TYPO3 parses the SiteConfiguration, the YamlFileLoader will detect the \%env(...)%-Syntax and replace the value accordingly with getenv().
- However, the method getValueFromEnv in \TYPO3\CMS\Core\Configuration\Loader\YamlFileLoader will evaluate the env-value to boolean FALSE, leading to the original string being used as a fallback.
- The resulting value in the SiteConfiguration will then still be:
myVariable: '%env(MY_VARIABLE)'
- This is of course wrong. Sometimes variables specifically need to be "0" or even empty. The check for env-value should not skip false-like values, but simply check if the env-variable is set or not.
A quick fix would be to adjust the getValueFromEnv-method like this:
$matches = []; preg_match_all('/%env\([\'"]?(\w+)[\'"]?\)%/', $value, $matches); $envVars = array_combine($matches[0], $matches[1]); foreach ($envVars as $substring => $envVarName) { $envVar = getenv($envVarName); $value = $envVar !== false ? str_replace($substring, $envVar, $value) : $value; } return $value;
Note the $envVar !== false ? .... Originally this was $envVar ? ....
Updated by Philipp Seiler almost 4 years ago
I have just checked TYPO3 v10, and the same error should be present there. Check \TYPO3\CMS\Core\Configuration\Processor\Placeholder\EnvVariableProcessor and method process:
$envVar = getenv($value); if (!$envVar) { throw new \UnexpectedValueException('Value not found', 1581501124); } return $envVar;
Should probably be:
$envVar = getenv($value); if ($envVar === false) { throw new \UnexpectedValueException('Value not found', 1581501124); } return $envVar;
Actions