aws / aws-sdk-php

Official repository of the AWS SDK for PHP (@awsforphp)
http://aws.amazon.com/sdkforphp
Apache License 2.0
6.02k stars 1.22k forks source link

Special Chars in S3 Key Names Causes Errors #169

Closed slatem closed 11 years ago

slatem commented 11 years ago

Having an item like: posts/attachments/000/001/133/large_thumbnail/2013_2_17_18_03_19_0_LA

in a bucket causes errors when listing the bucket or deleting the key. XML parser fails.

PHP Warning: SimpleXMLElement::construct(): Entity: line 2: parser error : xmlParseCharRef: invalid xmlChar value 27 in /storage/src/vendor/guzzle/guzzle/src/Guzzle/Http/Message/Response.php on line 884 PHP Warning: SimpleXMLElement::construct(): posts/attachments/000/001/133/large/2013_2_17_18_03_19_0_LA in /storage/src/vendor/guzzle/guzzle/src/Guzzle/Http/Message/Response.php on line 884 PHP Warning: SimpleXMLElement::construct(): ^ in /storage/src/vendor/guzzle/guzzle/src/Guzzle/Http/Message/Response.php on line 884 PHP Warning: SimpleXMLElement::construct(): Entity: line 2: parser error : xmlParseCharRef: invalid xmlChar value 27 in /storage/src/vendor/guzzle/guzzle/src/Guzzle/Http/Message/Response.php on line 884 PHP Warning: SimpleXMLElement::construct(): posts/attachments/000/001/133/large_thumbnail/2013_2_17_18_03_19_0_LA in /storage/src/vendor/guzzle/guzzle/src/Guzzle/Http/Message/Response.php on line 884 PHP Warning: SimpleXMLElement::construct(): ^ in /storage/src/vendor/guzzle/guzzle/src/Guzzle/Http/Message/Response.php on line 884 PHP Warning: SimpleXMLElement::construct(): Entity: line 2: parser error : xmlParseCharRef: invalid xmlChar value 27 in /storage/src/vendor/guzzle/guzzle/src/Guzzle/Http/Message/Response.php on line 884 PHP Warning: SimpleXMLElement::construct(): Contents>posts/attachments/000/001/133/medium/2013_2_17_18_03_19_0_LA in /storage/src/vendor/guzzle/guzzle/src/Guzzle/Http/Message/Response.php on line 884 PHP Warning: SimpleXMLElement::construct(): ^ in /storage/src/vendor/guzzle/guzzle/src/Guzzle/Http/Message/Response.php on line 884 PHP Warning: SimpleXMLElement::construct(): Entity: line 2: parser error : xmlParseCharRef: invalid xmlChar value 27 in /storage/src/vendor/guzzle/guzzle/src/Guzzle/Http/Message/Response.php on line 884 PHP Warning: SimpleXMLElement::construct(): Key>posts/attachments/000/001/133/medium_thumbnail/2013_2_17_18_03_19_0_LA in /storage/src/vendor/guzzle/guzzle/src/Guzzle/Http/Message/Response.php on line 884 PHP Warning: SimpleXMLElement::construct(): ^ in /storage/src/vendor/guzzle/guzzle/src/Guzzle/Http/Message/Response.php on line 884 PHP Warning: SimpleXMLElement::construct(): Entity: line 2: parser error : xmlParseCharRef: invalid xmlChar value 27 in /storage/src/vendor/guzzle/guzzle/src/Guzzle/Http/Message/Response.php on line 884 PHP Warning: SimpleXMLElement::construct(): ntents>posts/attachments/000/001/133/original/2013_2_17_18_03_19_0_LA in /storage/src/vendor/guzzle/guzzle/src/Guzzle/Http/Message/Response.php on line 884 PHP Warning: SimpleXMLElement::construct(): ^ in /storage/src/vendor/guzzle/guzzle/src/Guzzle/Http/Message/Response.php on line 884 PHP Warning: SimpleXMLElement::construct(): Entity: line 2: parser error : xmlParseCharRef: invalid xmlChar value 27 in /storage/src/vendor/guzzle/guzzle/src/Guzzle/Http/Message/Response.php on line 884 PHP Warning: SimpleXMLElement::construct(): tents>posts/attachments/000/001/133/thumbnail/2013_2_17_18_03_19_0_LA in /storage/src/vendor/guzzle/guzzle/src/Guzzle/Http/Message/Response.php on line 884 PHP Warning: SimpleXMLElement::construct(): ^ in /storage/src/vendor/guzzle/guzzle/src/Guzzle/Http/Message/Response.php on line 884 PHP Warning: SimpleXMLElement::construct(): Entity: line 2: parser error : xmlParseCharRef: invalid xmlChar value 27 in /storage/src/vendor/guzzle/guzzle/src/Guzzle/Http/Message/Response.php on line 884 PHP Warning: SimpleXMLElement::__construct(): s>posts/attachments/000/001/133/web/2013_2_17_18_03_19_0_LA in /storage/src/vendor/guzzle/guzzle/src/Guzzle/Http/Message/Response.php on line 884 PHP Warning: SimpleXMLElement::construct(): ^ in /storage/src/vendor/guzzle/guzzle/src/Guzzle/Http/Message/Response.php on line 884 PHP Fatal error: Uncaught exception 'Guzzle\Common\Exception\RuntimeException' with message 'Unable to parse response body into XML: String could not be parsed as XML' in /storage/src/vendor/guzzle/guzzle/src/Guzzle/Http/Message/Response.php:888 Stack trace:

0 /storage/src/vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Response/XmlVisitor.php(17): Guzzle\Http\Message\Response->xml()

1 /storage/src/vendor/guzzle/guzzle/src/Guzzle/Service/Command/OperationResponseParser.php(134): Guzzle\Service\Command\LocationVisitor\Response\XmlVisitor->before(Object(Aws\S3\Command\S3Command), Array)

2 /storage/src/vendor/guzzle/guzzle/src/Guzzle/Service/Command/OperationResponseParser.php(86): Guzzle\Service\Command\OperationResponseParser->visitResult(Object(Guzzle\Service\Description\Parameter), Object(Aws\S3\Command\S3Command), Object(Guzzle\Http\Message\Response))

3 /storage/src/vendor/guzzle/guzzle/src/Guzzle/Service/Command/DefaultResponseParser.php(39): Guzzle\Service\Command\OperationResponseParser->handleParsing in /storage/src/vendor/guzzle/guzzle/src/Guzzle/Http/Message/Response.php on line 888

mtdowling commented 11 years ago

Unless copying and pasting into GitHub stripped some special characters, the example you called out should work because it doesn't have any special characters:

posts/attachments/000/001/133/large_thumbnail/2013_2_17_18_03_19_0_LA

However, I see in your stack trace that you have keys that contain the ">" character. While Amazon S3 allows keys to be stored using reserved XML characters, attempting to parse and XML document that contains these characters results in a parsing error. This is a known issue with the Amazon S3 service and not something that can be fixed by the client (the AWS SDK for PHP). Customer feedback is used to help prioritize development schedules, so it would be great if you could let the Amazon S3 team know that this is important to you by posting to their forum: https://forums.aws.amazon.com/forum.jspa?forumID=24

slatem commented 11 years ago

The key in question had the following characters:

&#;
slatem commented 11 years ago

I was able to delete the keys using Cloudberry S3 Explorer PRO, but could not list the keys or delete them using the PHP API

slatem commented 11 years ago

The

>

character was not in the key.

mtdowling commented 11 years ago

Thanks for clarifying. Those characters didn't show up in the stack trace for some reason.

An XML parsing exception due to unescaped XML characters in the XML response is a server side issue that cannot be fixed by the SDK. This error can occur when attempting to list objects in a bucket where an object contains a reserved XML character.

Deleting an object with special characters would not cause an XML parsing error. What specific error do you receive when attempting to delete a key that contains a special character?

slatem commented 11 years ago

Ok. Guess we can leave this closed. I can't duplicate this and since I already deleted the keys in question I'll let you know if it pops up again.