Skip to content

Commit

Permalink
Fix rjsf-team#1233 : Exclude File object from isObject detection
Browse files Browse the repository at this point in the history
  • Loading branch information
oterral committed Mar 26, 2019
1 parent 9104a71 commit 309fa46
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,9 @@ export function getUiOptions(uiSchema) {
}

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

export function mergeObjects(obj1, obj2, concatArrays = false) {
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 @@ -517,6 +517,17 @@ describe("utils", () => {
expect(mergeObjects(obj1, obj2)).eql(expected);
});

it("shouldn't recursively merge File object", () => {
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 309fa46

Please sign in to comment.