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

jcookems opened this Issue Nov 29, 2012 · 2 comments


None yet
2 participants

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.

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.

$entity = new Entity();
$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);

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">
  <message xml:lang="en-US">0:One of the request inputs is not valid.

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) {

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