Skip to content

AsyncAws S3: Replace special characters by XML entity codes #1868

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

Open
wants to merge 2 commits into
base: 3.x
Choose a base branch
from

Conversation

stevenrombauts
Copy link
Contributor

When calling deleteDirectory(), we want to make sure that special characters (', ", &, < and >) are replaced by their XML entity code. If not, the following code will result in the error below:

$client = new AsyncAws\S3\S3Client([
    'accessKeyId' => '...',
    'accessKeySecret' => '...',
    'region' => 'eu-west-1',
]);

$adapter = new League\Flysystem\AsyncAwsS3\AsyncAwsS3Adapter($client, 'urlencode-test');
$filesystem = new League\Flysystem\Filesystem($adapter);

$filesystem->write('dir-to-delete/\'"&<>.json', '{"foo": "bar"}');
$filesystem->deleteDirectory('dir-to-delete');

This will result in:

Warning: DOMDocument::createElement(): unterminated entity reference         <>.json in flysystem/vendor/async-aws/s3/src/ValueObject/ObjectIdentifier.php on line 124

Fatal error: Uncaught AsyncAws\Core\Exception\Http\ClientException: HTTP 400 returned for "https://urlencode-test.s3.eu-west-3.amazonaws.com/?delete=".

Code:    UserKeyMustBeSpecified
Message: User key must be specified.

Also see AWS docs here: https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-keys.html#object-key-xml-related-constraints

@stevenrombauts stevenrombauts changed the title AsyncS3: Replace special characters by XML entity codes AsyncAws S3: Replace special characters by XML entity codes May 19, 2025
@frankdejonge
Copy link
Member

@stevenrombauts can you add a test case that verifies the error so we prevent regressions? The rest looks good 👍

@stevenrombauts
Copy link
Contributor Author

stevenrombauts commented May 21, 2025

@frankdejonge Do you mean to verify the exception that can be thrown by this new code, or do you mean something else?

@frankdejonge
Copy link
Member

@stevenrombauts yes, verify that the guard works. Essentially a test that fails when the check is removed.

@stevenrombauts
Copy link
Contributor Author

@frankdejonge Thanks, got it. I've added that test now, let me know if that works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants