-
Notifications
You must be signed in to change notification settings - Fork 30
Closed
Labels
Description
Description
Fs::_subfolder() and Fs::_cfPrefix() call Craft::parseEnv() and pass the result directly to rtrim(). When the referenced environment variable resolves to an empty string, App::parseEnv() returns null (by design — see App::parseEnv() lines 240–241), causing a PHP TypeError:
TypeError: rtrim(): Argument #1 ($string) must be of type string, null given
The issue is on line 509 of src/Fs.php:
private function _subfolder(): string
{
if ($this->subfolder && ($subfolder = rtrim(Craft::parseEnv($this->subfolder), '/')) !== '') {
return $subfolder . '/';
}
return '';
}When subfolder is set to an env var reference (e.g. $MY_SUBFOLDER) in project config, $this->subfolder is the raw string $MY_SUBFOLDER (truthy), so it enters the if branch. Craft::parseEnv('$MY_SUBFOLDER') resolves the env var to "", which parseEnv() converts to null. Then rtrim(null, '/') throws.
The same pattern exists in _cfPrefix() on line 536.
A null-safe fix would be:
if ($this->subfolder && ($subfolder = rtrim(Craft::parseEnv($this->subfolder) ?? '', '/')) !== '') {Steps to reproduce
- Configure an S3 filesystem with
subfolder: $MY_SUBFOLDERin project config - Set
MY_SUBFOLDER=""in.env - Load any page that generates an asset URL from that filesystem
Additional info
- Craft version: 5.9.8
- PHP version: 8.2.30
- Database driver & version: N/A
- Plugins & versions: craftcms/aws-s3 2.2.4
Reactions are currently unavailable