Skip to content

Commit

Permalink
Fix #1233 : Exclude File object from isObject detection (#1234)
Browse files Browse the repository at this point in the history
* Fix #1233 : Exclude File object from isObject detection

* Update test name

Co-Authored-By: oterral <[email protected]>
  • Loading branch information
oterral authored and epicfaace committed Mar 27, 2019
1 parent 3afb5f9 commit de79e37
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,9 @@ export function getUiOptions(uiSchema) {
}

export function isObject(thing) {
if (thing instanceof File) {
return false;
}
return typeof thing === "object" && thing !== null && !Array.isArray(thing);
}

Expand Down
1 change: 1 addition & 0 deletions test/setup-jsdom.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ if (!global.hasOwnProperty("window")) {
global.document = jsdom.jsdom("<!doctype html><html><body></body></html>");
global.window = document.defaultView;
global.navigator = global.window.navigator;
global.File = global.window.File;
}

// atob
Expand Down
11 changes: 11 additions & 0 deletions test/utils_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,17 @@ describe("utils", () => {
expect(mergeObjects(obj1, obj2)).eql(expected);
});

it("should recursively merge File objects", () => {
const file = new File(["test"], "test.txt");
const obj1 = {
a: {},
};
const obj2 = {
a: file,
};
expect(mergeObjects(obj1, obj2).a).instanceOf(File);
});

describe("concatArrays option", () => {
it("should not concat arrays by default", () => {
const obj1 = { a: [1] };
Expand Down

0 comments on commit de79e37

Please sign in to comment.