-
-
Notifications
You must be signed in to change notification settings - Fork 364
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix data corruption when storing binary data #386
Conversation
Pull Request Test Coverage Report for Build 584
💛 - Coveralls |
@peecky Shouldn't this include some tests as well? |
@fishcharlie Thanks. :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You reported this as a bug in Dynamoose. So the broken version should be made into a separate (new) test. Without your fix this test should fail. With your fix the test should pass. It should be a 100% fully unique test.
test/Model.js
Outdated
@@ -18,6 +18,10 @@ var Cats = {}; | |||
var ONE_YEAR = 365*24*60*60; // 1 years in seconds | |||
var NINE_YEARS = 9*ONE_YEAR; // 9 years in seconds | |||
|
|||
var imageData = Buffer.from([0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0xd3, 0x61, 0x60, 0x60]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two lines should be included within a test and not globally scoped.
test/Model.js
Outdated
@@ -319,6 +325,7 @@ describe('Model', function (){ | |||
model.should.have.property('id', 1); | |||
model.should.have.property('name', 'Fluffy'); | |||
model.should.have.property('vet', { address: '12 somewhere', name: 'theVet' }); | |||
model.should.have.property('profileImage', imageData); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This whole section should probably be included in a separate test, not this one.
@peecky Thanks for this! Just submitted a review with some more changes 😃 |
@peecky This looks good to me. My only other concern is that this could be a breaking change to some users. What are your thoughts on this? |
I can’t imagine any cases that the current version is useful or works well but new version breaks the working. Strictly speaking, however, it is a breaking change. It might be better to apply this change to the next major version. The bug is still avoidable on the current version by setting const schema = new dynamoose.Schema({
key: { type: String },
value: { type: Buffer, toDynamo: x => ({ B: x }) }
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM to be released in v1.0
@peecky We will get this in for version 1.0. Thanks! |
Hello, I fixed a bug of storing corrupted binary data.
For example, following code did not properly store the value.
Because not every binary data can be converted to UTF-8 string, also the AWS SDK supports both
Buffer
andstring
for typeB
, it is better not to convert the value to string when the type isB
and the value isBuffer
instance.