Skip to content

Commit c5aa78b

Browse files
committed
fix(inboxQuery): port _createRequest from Query to prevent URI too long
1 parent a399434 commit c5aa78b

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

src/query.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ module.exports = function(AV) {
250250
return new this.objectClass();
251251
},
252252
_createRequest(params = this.toJSON(), options) {
253-
if (JSON.stringify(params).length > 2000) {
253+
if (encodeURIComponent(JSON.stringify(params)).length > 2000) {
254254
const body = {
255255
requests: [{
256256
method: 'GET',

src/status.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,27 @@ module.exports = function(AV) {
313313
_newObject: function(){
314314
return new AV.Status();
315315
},
316-
_createRequest: function(params, options){
317-
return AVRequest('subscribe/statuses', null, null, 'GET',
318-
params || this.toJSON(), options);
316+
_createRequest: function (params = this.toJSON(), options) {
317+
if (encodeURIComponent(JSON.stringify(params)).length > 2000) {
318+
const body = {
319+
requests: [{
320+
method: 'GET',
321+
path: '/1.1/subscribe/statuses',
322+
params,
323+
}],
324+
};
325+
return AVRequest('batch', null, null, 'POST', body, options)
326+
.then(response => {
327+
const result = response[0];
328+
if (result.success) {
329+
return result.success;
330+
}
331+
const error = new Error(result.error.error || 'Unknown batch error');
332+
error.code = result.error.code;
333+
throw error;
334+
});
335+
}
336+
return AVRequest('subscribe/statuses', null, null, 'GET', params, options);
319337
},
320338

321339

test/status.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ describe("AV.Status",function(){
6060
expect(response.unread).to.be.eql(0);
6161
});
6262
});
63+
it('should not cause URI too long', () => {
64+
return AV.Status.inboxQuery(user)
65+
.containsAll('arr', new Array(50).fill(AV.Object.createWithoutData('Todo', '5850f138128fe1006978f766')))
66+
.find();
67+
});
6368
});
6469

6570
describe("Status guide test.", function(){

0 commit comments

Comments
 (0)