Menu

URL encode bug in 0.7.2

Help
2010-03-31
2013-04-29
  • Jordan Snodgrass

    Hi there, found another small bug.  You're using rawurlencode() for the query params and signature, however, rawurlencode() follows RFC 1738, not RFC 3986 as required by Amazon.  The only difference between them is the tilde character (~).  So if you attempt to use a var name or value with a tilde in it, you will receive the following error:

    SignatureDoesNotMatch: The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.

    I have created a function to get around this.  It simply un-urlecodes the tilde character.  Here is the code:

    /**
    * URL encode the parameters as per http://docs.amazonwebservices.com/AWSECommerceService/latest/DG/index.html?Query_QueryAuth.html
    * PHP's rawurlencode() follows RFC 1738, not RFC 3986 as required by Amazon.  The only difference is the tilde (~), so convert it back after rawurlencode
    * See: http://www.morganney.com/blog/API/AWS-Product-Advertising-API-Requires-a-Signed-Request.php
    * 
    *  @param string $var String to encode
    *  @return string
    */
    public function __customUrlEncode($var) {
        return str_replace('%7E', '~', rawurlencode($var));
    }
    

    Then simply replace all occurrences of rawurlencode() with a call to SimpleDBRequest::__customUrlEncode() and SDB will no longer barf when using a tilde.

    This was a very difficult bug to track down because the tilde character is rarely used.  But it is used often in URLs so if you are trying to post URLs to SDB you will probably come across this!  I forsee a 0.7.3 release in your future.  :)

     
  • Dan Myers

    Dan Myers - 2010-03-31

    Thanks!  You're awesome.  If you're ever in Seattle I'll buy you a cookie :)

    I too forsee a 0.7.3 release in the near future.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.