Skip to content

Commit

Permalink
Merge pull request #145 from Esri/bug/salvage-falsy-params
Browse files Browse the repository at this point in the history
fix(request): ensure falsy request parameters like zero are passed through
  • Loading branch information
patrickarlt committed Mar 3, 2018
2 parents 4b1544f + 3c69a10 commit d657b57
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
@@ -0,0 +1,3 @@
{
"editor.tabSize": 2
}
25 changes: 24 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -68,7 +68,7 @@
},
"lint-staged": {
"*.ts": [
"prettier --write --parser typescript",
"prettier --write --parser typescript --tab-width 2 --use-tabs false",
"tslint",
"git add"
]
Expand Down
6 changes: 3 additions & 3 deletions packages/arcgis-rest-request/src/utils/process-params.ts
@@ -1,5 +1,5 @@
/* Copyright (c) 2017 Environmental Systems Research Institute, Inc.
* Apache-2.0 */
* Apache-2.0 */

/**
* Checks parameters to see if we should use FormData to send the request
Expand Down Expand Up @@ -47,7 +47,7 @@ export function processParams(params: any): any {

Object.keys(params).forEach(key => {
const param = params[key];
if (!param) {
if (!param && param !== 0) {
return;
}
const type = param.constructor.name;
Expand Down Expand Up @@ -80,7 +80,7 @@ export function processParams(params: any): any {
value = param;
break;
}
if (value) {
if (value || value === 0) {
newParams[key] = value;
}
});
Expand Down
11 changes: 8 additions & 3 deletions packages/arcgis-rest-request/test/utils/process-params.test.ts
Expand Up @@ -89,13 +89,18 @@ describe("processParams", () => {
expect(processParams(params)).toEqual(expected);
});

it("should exclude null and undefined", () => {
it("should exclude null and undefined, but not a zero", () => {
const params: any = {
foo: null,
bar: undefined
bar: undefined,
baz: 0
};

expect(processParams(params)).toEqual({});
const expected = {
baz: 0
};

expect(processParams(params)).toEqual(expected);
});

it("should not require form data for simple requests", () => {
Expand Down

0 comments on commit d657b57

Please sign in to comment.