argoncloud/ActionBSON — Issue #3: Invalid translation of ObjectID
Author: egslava
Created: 2011-10-21 14:39:00+00:00
State: open

Hi, team, for begin, sorry for my English.
There is the little bug.

I want to get string of ObjectID. It is a 24-character string contains every of 12 bytes in hex form.
For example:
"_id" : ObjectId("4e9ea2360e08a854539f8aa4")
It is contains 24 character. 12 bytes, 2 character for every byte.
But ObjectID.toString() gets me:
4e9ea236e8a854539f8aa4
But it is contains only 22 characters.

Let's separate string to our hex bytes:

Gets from mongo
4e 9e a2 36 __0__e __0__8 a8 54 53 9f 8a a4
Gets from ObjectID.toString
4e 9e a2 36 e 8 a8 54 53 9f 8a a4

As you can see, zero is lost.
I think, you should to apply a little change to this function (ObjectID.toString()):

```as3
public function toString() : String {
var str : String = "";
for ( var i : int = 0; i < 12; ++i ) {
str += rep[i].toString( 16 );
}
return str;
}
```

Instead, you should use this function:

```as3
public function toString() : String {
var str : String = "";
var byteInHex: String;
for ( var i : int = 0; i < 12; ++i ) {
byteInHex = rep[i].toString( 16 );
str += rep[i] > 15? byteInHex: "0"+byteInHex;
}
return str;
}
```