mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 09:32:32 +01:00
SERVER-3168: Fixed hexadecimal output, added tests
This commit is contained in:
parent
8c8f5220ef
commit
403b7aa8a2
14
jstests/binData.js
Normal file
14
jstests/binData.js
Normal file
@ -0,0 +1,14 @@
|
||||
|
||||
var x = new BinData(3, "OEJTfmD8twzaj/LPKLIVkA==");
|
||||
assert.eq(x.hex(), "3842537e60fcb70cda8ff2cf28b21590", "bad hex");
|
||||
assert.eq(x.base64(), "OEJTfmD8twzaj/LPKLIVkA==", "bad base64");
|
||||
assert.eq(x.type, 3, "bad type");
|
||||
assert.eq(x.length(), 16, "bad length");
|
||||
|
||||
x = new BinData(0, "TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlzIHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2YgdGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGludWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRoZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=");
|
||||
assert.eq(x.hex(), "4d616e2069732064697374696e677569736865642c206e6f74206f6e6c792062792068697320726561736f6e2c2062757420627920746869732073696e67756c61722070617373696f6e2066726f6d206f7468657220616e696d616c732c2077686963682069732061206c757374206f6620746865206d696e642c20746861742062792061207065727365766572616e6365206f662064656c6967687420696e2074686520636f6e74696e75656420616e6420696e6465666174696761626c652067656e65726174696f6e206f66206b6e6f776c656467652c2065786365656473207468652073686f727420766568656d656e6365206f6620616e79206361726e616c20706c6561737572652e", "bad hex");
|
||||
assert.eq(x.base64(), "TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlzIHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2YgdGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGludWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRoZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=", "bad base64");
|
||||
assert.eq(x.type, 0, "bad type");
|
||||
assert.eq(x.length(), 269, "bad length");
|
||||
|
||||
|
@ -757,10 +757,12 @@ zzz
|
||||
assert( holder );
|
||||
const char *data = ( ( BinDataHolder* )( holder ) )->c_;
|
||||
stringstream ss;
|
||||
ss << hex;
|
||||
ss.setf (ios_base::hex , ios_base::basefield);
|
||||
ss.fill ('0');
|
||||
ss.setf (ios_base::right , ios_base::adjustfield);
|
||||
for( int i = 0; i < len; i++ ) {
|
||||
unsigned v = (unsigned char) data[i];
|
||||
ss << v;
|
||||
ss << setw(2) << v;
|
||||
}
|
||||
string ret = ss.str();
|
||||
return *rval = c.toval( ret.c_str() );
|
||||
|
@ -775,10 +775,12 @@ namespace mongo {
|
||||
Local<External> c = External::Cast( *(it->GetInternalField( 0 )) );
|
||||
char* data = (char*)(c->Value());
|
||||
stringstream ss;
|
||||
ss << hex;
|
||||
ss.setf (ios_base::hex , ios_base::basefield);
|
||||
ss.fill ('0');
|
||||
ss.setf (ios_base::right , ios_base::adjustfield);
|
||||
for( int i = 0; i < len; i++ ) {
|
||||
unsigned v = (unsigned char) data[i];
|
||||
ss << v;
|
||||
ss << setw(2) << v;
|
||||
}
|
||||
return v8::String::New(ss.str().c_str());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user