Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

TableRestProxy should use strlen instead of mb_strlen #637

Closed
jcookems opened this Issue Nov 29, 2012 · 2 comments

Comments

Projects
None yet
2 participants
Contributor

jcookems commented Nov 29, 2012

The TableRestProxy has this code:

 // Use mb_strlen instead of strlen to get the length of the string
// in bytes instead of the length in chars.
$context->addOptionalHeader(
    Resources::CONTENT_LENGTH,
     mb_strlen($body)
);

The intent of the comment is correct (should send the length of the string in bytes not characters), but the implementation is wrong (strlen gives the byte length, mb_strlen gives the character length, using mb_internal_encoding to determine what are characters).

To see the problem in action, use this code:

// Change MB, as anyone can do in their code.
mb_internal_encoding("UTF-8");

$entity = new Entity();
$entity->setPartitionKey('001');
$entity->setRowKey('batchInsertWorks');
$entity->addProperty('test2', EdmType::STRING, 
        chr(0xEB) . chr(0x8B) . chr(0xA4)); // \uB2E4 in UTF8

$bo = new BatchOperations();
$bo->addInsertEntity('mytable', $entity);
$result = $this->restProxy->batch($bo);
var_dump($result);

This outputs

class WindowsAzure\Table\Models\BatchResult#214 (1) {
  private $_entries =>
  array(0) {
  }
}

which indicates a problem; there should be an entity there. Looking at the HTTP response gives more details:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
  <code>InvalidInput</code>
  <message xml:lang="en-US">0:One of the request inputs is not valid.
RequestId:f7d6467b-49da-4b38-a9f6-a31f6aab444f
Time:2012-11-29T19:28:23.4662505Z</message>
</error>
Contributor

jcookems commented Nov 29, 2012

Changing to strlen gives this correct output:

class WindowsAzure\Table\Models\BatchResult#214 (1) {
  private $_entries =>
  array(1) {
    [0] =>
    class WindowsAzure\Table\Models\InsertEntityResult#188 (1) {
      private $_entity =>
      class WindowsAzure\Table\Models\Entity#175 (2) {
        ...
      }
    }
  }
}
Member

matt-gibbs commented Jul 29, 2014

Closing stale issues. Reactivate if it should be reconsidered.

@matt-gibbs matt-gibbs closed this Jul 29, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment