Skip to content

Commit d4effad

Browse files
authored
Merge pull request #225 from gpembark/master
Correctly encoding arrays for GET requests
2 parents 2845fca + ccb27f5 commit d4effad

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

spec/amadeus/client/request.test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,15 @@ describe('Request', () => {
102102
request.params = null;
103103
expect(request.fullQueryPath()).toBe('/foo/bar?');
104104
});
105+
106+
it('should serialize array params as comma-separated values', () => {
107+
request.verb = 'GET';
108+
request.params = {
109+
amenities: ['bar', 'baz'],
110+
ratings: [4, 5],
111+
};
112+
expect(request.fullQueryPath()).toBe('/foo/bar?amenities=bar%2Cbaz&ratings=4%2C5');
113+
});
105114
});
106115

107116
describe('.body', () => {

src/amadeus/client/request.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class Request {
115115
*/
116116
fullQueryPath() {
117117
if (this.verb === 'POST') { return this.path; }
118-
else { return `${this.path}?${qs.stringify(this.params)}`; }
118+
else { return `${this.path}?${qs.stringify(this.params, { arrayFormat: 'comma' })}`; }
119119
}
120120

121121
/**

0 commit comments

Comments
 (0)