Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
common: Report missing password visibility toggle without crashing.
Evy Kassirer525a96ce2574
diff --git a/web/src/common.ts b/web/src/common.tsindex 300f4e953f6..a866f476091 100644--- a/web/src/common.ts+++ b/web/src/common.ts@@ -1,8 +1,8 @@import {$} from "jquery";import * as tippy from "tippy.js";+import * as blueslip from "./blueslip.ts";import {$t} from "./i18n.ts";-import * as util from "./util.ts";export const status_classes = "alert-error alert-success alert-info alert-warning";@@ -119,7 +119,13 @@ function set_password_toggle_label(): void {$(password_selector).attr("aria-label", label);if (tippy_tooltips) {- const element: tippy.ReferenceElement = util.the($(password_selector));+ const element: tippy.ReferenceElement | undefined = $(password_selector)[0];+ if (element === undefined) {+ // Report the missing toggle without throwing, so that+ // callers still run cleanup like clearing password inputs.+ blueslip.error("Password visibility toggle not found", {password_selector});+ return;+ }const tippy_instance = element._tippy ?? tippy.default(element);tippy_instance.setContent(label);} else {diff --git a/web/tests/common.test.cjs b/web/tests/common.test.cjsindex d577195fa9e..3cd24942823 100644--- a/web/tests/common.test.cjs+++ b/web/tests/common.test.cjs@@ -4,6 +4,7 @@ const assert = require("node:assert/strict");const {mock_esm, set_global, zrequire} = require("./lib/namespace.cjs");const {run_test, noop} = require("./lib/test.cjs");+const blueslip = require("./lib/zblueslip.cjs");const {$} = require("./lib/zjquery.cjs");mock_esm("tippy.js", {@@ -159,6 +160,17 @@ run_test("adjust_mac_hotkey_hints mac random", ({override}) => {}});+run_test("reset password toggle icons with missing toggle", () => {+ // Password manager extensions can rearrange the DOM around+ // password inputs such that the toggle selector matches nothing.+ const password_selector = "#mangled_password ~ .password_visibility_toggle";+ $.create(password_selector, {elements: []});++ blueslip.expect("error", "Password visibility toggle not found");+ common.reset_password_toggle_icons("#mangled_password", password_selector);+ assert.equal($("#mangled_password").attr("type"), "password");+});+run_test("show password", () => {const password_selector = "#id_password ~ .password_visibility_toggle";