Skip to content

Commit 295058d

Browse files
fix: use Object.prototype.hasOwnProperty.call for safe property checks (calcom#27661)
The error 'TypeError: value.hasOwnProperty is not a function' can occur when objects are created without the standard Object prototype (e.g., via Object.create(null) or certain parsing methods). Using Object.prototype.hasOwnProperty.call() is the safe way to check for property existence on any object. Fixed in: - GetSlotsInputPipe (isById, isByUsernameAndEventTypeSlug, isByTeamSlugAndEventTypeSlug) - CancelBookingInputPipe (isCancelSeatedBookingInput) - CreateBookingInputPipe (isRecurringBookingInput, isInstantBookingInput) Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 parent 2e9191f commit 295058d

3 files changed

Lines changed: 14 additions & 6 deletions

File tree

packages/platform/types/bookings/2024-08-13/inputs/cancel-booking-input.pipe.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,6 @@ export class CancelBookingInputPipe implements PipeTransform {
7777
private isCancelSeatedBookingInput(
7878
value: CancelBookingInput
7979
): value is CancelSeatedBookingInput_2024_08_13 {
80-
return value.hasOwnProperty("seatUid");
80+
return Object.prototype.hasOwnProperty.call(value, "seatUid");
8181
}
8282
}

packages/platform/types/bookings/2024-08-13/inputs/create-booking-input.pipe.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,12 @@ export class CreateBookingInputPipe implements PipeTransform {
102102
private isRecurringBookingInput(
103103
value: CreateBookingInput
104104
): value is CreateRecurringBookingInput_2024_08_13 {
105-
return value.hasOwnProperty("recurrenceCount");
105+
return Object.prototype.hasOwnProperty.call(value, "recurrenceCount");
106106
}
107107

108108
private isInstantBookingInput(value: CreateBookingInput): value is CreateInstantBookingInput_2024_08_13 {
109-
return value.hasOwnProperty("instant") && "instant" in value && value.instant === true;
109+
return (
110+
Object.prototype.hasOwnProperty.call(value, "instant") && "instant" in value && value.instant === true
111+
);
110112
}
111113
}

packages/platform/types/slots/slots-2024-09-04/inputs/get-slots-input.pipe.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,18 +131,24 @@ export class GetSlotsInputPipe implements PipeTransform {
131131
}
132132

133133
private isById(value: GetSlotsInput_2024_09_04): value is ById_2024_09_04 {
134-
return value.hasOwnProperty("eventTypeId");
134+
return Object.prototype.hasOwnProperty.call(value, "eventTypeId");
135135
}
136136

137137
private isByUsernameAndEventTypeSlug(
138138
value: GetSlotsInput_2024_09_04
139139
): value is ByUsernameAndEventTypeSlug_2024_09_04 {
140-
return value.hasOwnProperty("username") && value.hasOwnProperty("eventTypeSlug");
140+
return (
141+
Object.prototype.hasOwnProperty.call(value, "username") &&
142+
Object.prototype.hasOwnProperty.call(value, "eventTypeSlug")
143+
);
141144
}
142145

143146
private isByTeamSlugAndEventTypeSlug(
144147
value: GetSlotsInput_2024_09_04
145148
): value is ByTeamSlugAndEventTypeSlug_2024_09_04 {
146-
return value.hasOwnProperty("teamSlug") && value.hasOwnProperty("eventTypeSlug");
149+
return (
150+
Object.prototype.hasOwnProperty.call(value, "teamSlug") &&
151+
Object.prototype.hasOwnProperty.call(value, "eventTypeSlug")
152+
);
147153
}
148154
}

0 commit comments

Comments
 (0)