forked from rjsf-team/react-jsonschema-form
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Short-circuit File and Date constructor access in isObject (rjsf…
…-team#4413) * fix: short-circuit File and Date constructor access in isObject if thing is missing required property * chore: update changelog with isObject short-circuiting fix --------- Co-authored-by: Jonathan Sun <jonathan.sun@mujin.co.jp>
- Loading branch information
Showing
3 changed files
with
49 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,22 @@ | ||
/** Determines whether a `thing` is an object for the purposes of RSJF. In this case, `thing` is an object if it has | ||
/** Determines whether a `thing` is an object for the purposes of RJSF. In this case, `thing` is an object if it has | ||
* the type `object` but is NOT null, an array or a File. | ||
* | ||
* @param thing - The thing to check to see whether it is an object | ||
* @returns - True if it is a non-null, non-array, non-File object | ||
*/ | ||
export default function isObject(thing: any) { | ||
if (typeof File !== 'undefined' && thing instanceof File) { | ||
if (typeof thing !== 'object' || thing === null) { | ||
return false; | ||
} | ||
if (typeof Date !== 'undefined' && thing instanceof Date) { | ||
// lastModified is guaranteed to be a number on a File instance | ||
// as per https://w3c.github.io/FileAPI/#dfn-lastModified | ||
if (typeof thing.lastModified === 'number' && typeof File !== 'undefined' && thing instanceof File) { | ||
return false; | ||
} | ||
return typeof thing === 'object' && thing !== null && !Array.isArray(thing); | ||
// getMonth is guaranteed to be a method on a Date instance | ||
// as per https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.getmonth | ||
if (typeof thing.getMonth === 'function' && typeof Date !== 'undefined' && thing instanceof Date) { | ||
return false; | ||
} | ||
return !Array.isArray(thing); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters