support: Fix scrubbing realms if string_id is a number.

This bug made it impossible to scrub realms where the string_id was a
number, e.g. 123.zulipchat.com because
confirmed_string_id === actual_string_id comparison failed due to one
being a string and the other a number.

Per http://api.jquery.com/data/#data-html5:
Every attempt is made to convert the attribute's string value to a
JavaScript value (this includes booleans, numbers, objects, arrays, and
null).
To retrieve a data-* attribute value as an unconverted string, use the
attr() method.
This commit is contained in:
Mateusz Mandera 2023-03-24 23:28:19 +01:00 committed by Tim Abbott
parent 505c217db5
commit ca0869eb01
2 changed files with 3 additions and 3 deletions

View File

@ -7,7 +7,7 @@ $(() => {
e.preventDefault(); e.preventDefault();
const message = const message =
"Confirm the string_id of the realm you want to scrub.\n\n WARNING! This action is irreversible!"; "Confirm the string_id of the realm you want to scrub.\n\n WARNING! This action is irreversible!";
const actual_string_id = $(this).data("string-id"); const actual_string_id = $(this).attr("data-string-id");
// eslint-disable-next-line no-alert // eslint-disable-next-line no-alert
const confirmed_string_id = window.prompt(message); const confirmed_string_id = window.prompt(message);
if (confirmed_string_id === actual_string_id) { if (confirmed_string_id === actual_string_id) {

View File

@ -24,8 +24,8 @@ run_test("scrub_realm", () => {
const click_handler = $("body").get_on_handler("click", ".scrub-realm-button"); const click_handler = $("body").get_on_handler("click", ".scrub-realm-button");
const $fake_this = $.create("fake-.scrub-realm-button"); const $fake_this = $.create("fake-.scrub-realm-button");
$fake_this.data = (name) => { $fake_this.attr = (name) => {
assert.equal(name, "string-id"); assert.equal(name, "data-string-id");
return "zulip"; return "zulip";
}; };