Bug #91710
closedResolving env-Variable in Site Configuration ignores values that resolve to "false"
100%
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 about 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;
Updated by Gerrit Code Review about 1 month ago
- Status changed from New to Under Review
Patch set 1 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/84442
Updated by Gerrit Code Review about 1 month ago
Patch set 2 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/84442
Updated by Gerrit Code Review about 1 month ago
Patch set 1 for branch 12.4 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/84453
Updated by Garvin Hicking about 1 month ago
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
Applied in changeset 5564286e50f082e9694c48a476eed3d4166e9768.