Skip to content

Commit b95a301

Browse files
authored
fix: decode ACL correctly (#449)
1 parent cf7351f commit b95a301

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/av.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,9 @@ AV._decode = function(value, key) {
282282
if (value instanceof AV.ACL) {
283283
return value;
284284
}
285+
if (key === 'ACL') {
286+
return new AV.ACL(value);
287+
}
285288
if (value.__op) {
286289
return AV.Op._decode(value);
287290
}
@@ -331,12 +334,7 @@ AV._decode = function(value, key) {
331334
file._finishFetch(v);
332335
return file;
333336
}
334-
return _.mapObject(value, function(v, k) {
335-
if (k === "ACL") {
336-
return new AV.ACL(v);
337-
}
338-
return AV._decode(v, k);
339-
});
337+
return _.mapObject(value, AV._decode);
340338
};
341339

342340
AV._encodeObjectOrArray = function(value) {

test/av.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ describe('AV utils', () => {
3434
AV._decode('false').should.be.exactly('false');
3535
});
3636

37+
it('should decode ACL', () => {
38+
AV._decode(new AV.ACL(), 'ACL').should.be.instanceof(AV.ACL);
39+
AV._decode({ '*': { read: true, write: true } }, 'ACL').should.be.instanceof(AV.ACL);
40+
AV._decode({ '*': { read: true, write: true } }).should.not.be.instanceof(AV.ACL);
41+
});
42+
3743
it('should decode File', () => {
3844
const fileId = '1111111';
3945
const json = { "mime_type": "image/png", "updatedAt": "2016-12-30T06:55:43.561Z", "key": "d7aaab5c477b289980fc.png", "name": "lc.png", "objectId": fileId, "createdAt": "2016-12-30T06:55:43.561Z", "__type": "File", "url": "", "bucket": "rYAutyUJ" };

0 commit comments

Comments
 (0)