Skip to content

Commit

Permalink
Make sure object prototype properties are not matched
Browse files Browse the repository at this point in the history
  • Loading branch information
mlegenhausen committed Jun 1, 2023
1 parent 413c8a2 commit 13c9b30
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions test/unit/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ describe("index", () => {
})

it("matchX allow undefined value", () => {
type T = Member<"A"> | Member<"B">
type T = Member<"A"> | Member<"B"> | Member<"toString">
const T = create<T>()

const f = T.matchX({
Expand All @@ -95,6 +95,9 @@ describe("index", () => {

expect(f(T.mk.A)).toBe(undefined)
expect(f(T.mk.B)).toBe(undefined)
// Check that `toString` does not match an object prototype function
// This check would fail when the `in` operator is used instead of `hasOwnProperty`.
expect(f(T.mk.toString)).toBe(undefined)
})

it("matchXW", () => {
Expand All @@ -113,7 +116,7 @@ describe("index", () => {
})

it("matchXW allow undefined value", () => {
type T = Member<"A"> | Member<"B">
type T = Member<"A"> | Member<"B"> | Member<"toString">
const T = create<T>()

const f = T.matchXW({
Expand All @@ -123,6 +126,9 @@ describe("index", () => {

expect(f(T.mk.A)).toBe(undefined)
expect(f(T.mk.B)).toBe(undefined)
// Check that `toString` does not match an object prototype function.
// This check would fail when the `in` operator is used instead of `hasOwnProperty`.
expect(f(T.mk.toString)).toBe(undefined)
})
})
})
Expand Down

0 comments on commit 13c9b30

Please sign in to comment.