From 55e4be0939aead37838f22fc607ab4e12c5cebce Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Fri, 8 Sep 2023 13:13:54 -0700 Subject: [PATCH] setup: Fix wildly unsafe cast in $.fn.expectOne. Signed-off-by: Anders Kaseorg --- web/src/avatar.ts | 2 +- web/src/global.d.ts | 2 +- web/src/setup.ts | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/web/src/avatar.ts b/web/src/avatar.ts index eae381c4f6..608774b7c5 100644 --- a/web/src/avatar.ts +++ b/web/src/avatar.ts @@ -72,7 +72,7 @@ function display_avatar_delete_started(): void { export function build_user_avatar_widget(upload_function: UploadFunction): void { const get_file_input = function (): JQuery { - return $("#user-avatar-upload-widget .image_file_input").expectOne(); + return $("#user-avatar-upload-widget input.image_file_input").expectOne(); }; if (page_params.avatar_source === "G") { diff --git a/web/src/global.d.ts b/web/src/global.d.ts index c7c7cb2e58..8635da6d55 100644 --- a/web/src/global.d.ts +++ b/web/src/global.d.ts @@ -23,7 +23,7 @@ declare namespace JQueryValidation { // eslint-disable-next-line @typescript-eslint/consistent-type-definitions interface JQuery { - expectOne(): JQuery; + expectOne(): this; get_offset_to_window(): DOMRect; tab(action?: string): this; // From web/third/bootstrap modal(action?: string): this; // From web/third/bootstrap diff --git a/web/src/setup.ts b/web/src/setup.ts index 008a4bdf5e..e8822fd75a 100644 --- a/web/src/setup.ts +++ b/web/src/setup.ts @@ -26,10 +26,10 @@ $(() => { return this[0].getBoundingClientRect(); }; - $.fn.expectOne = function () { + $.fn.expectOne = function () { if (blueslip && this.length !== 1) { blueslip.error("Expected one element in jQuery set", {length: this.length}); } - return this as JQuery; + return this; }; });