You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In certain situations, compare fails to calculate a valid JSON patch and throws a TypeError with this message instead:
obj.hasOwnProperty is not a function
In my case, this happens when running objects created by GraphQL's graphql method through fast-json-patch. One location where this error originates is this line in json-patch-duplex.js:
In fact, this error will be thrown whenever custom objects are used that do not have Object in their prototype hierarchy, such as plain maps created with Object.create(null).
I propose to replace all calls to special Object methods with Object.prototype calls such as this:
In certain situations,
compare
fails to calculate a valid JSON patch and throws aTypeError
with this message instead:obj.hasOwnProperty is not a function
In my case, this happens when running objects created by GraphQL's
graphql
method through fast-json-patch. One location where this error originates is this line in json-patch-duplex.js:In fact, this error will be thrown whenever custom objects are used that do not have Object in their prototype hierarchy, such as plain maps created with
Object.create(null)
.I propose to replace all calls to special Object methods with Object.prototype calls such as this:
This ensures that no exception is thrown in case objects without the Object prototype are used.
One may certainly argue that this seems like a pretty far-fetched corner case, but e.g. ESLint has a special rule against this type of Object prototype builtins: Disallow use of Object.prototypes builtins directly (no-prototype-builtins), see their rationale.
I would be willing to prepare a pull request for the required changes.
The text was updated successfully, but these errors were encountered: