Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
util: Add is_numeric_string and use it for digit-string checks.
Evy Kassirer8deac1a2d3c2
diff --git a/web/src/hash_parser.ts b/web/src/hash_parser.tsindex 7542189aba1..84d980cac6a 100644--- a/web/src/hash_parser.ts+++ b/web/src/hash_parser.ts@@ -1,6 +1,7 @@// See the Zulip URL spec at https://zulip.com/api/zulip-urlsimport {type NarrowTerm, narrow_operator_schema} from "./state_data.ts";+import * as util from "./util.ts";export function get_hash_category(hash?: string): string {// given "#channels/subscribed", returns "channels"@@ -46,7 +47,7 @@ export function is_same_server_message_link(url: string): boolean {get_hash_category(url) === "narrow" &&(get_hash_section(url) === "channel" || get_hash_section(url) === "dm") &&get_nth_hash_section(url, -2) === "near" &&- /^\d+$/.test(get_nth_hash_section(url, -1))+ util.is_numeric_string(get_nth_hash_section(url, -1)));}diff --git a/web/src/hashchange.ts b/web/src/hashchange.tsindex f2c1cdcd9d8..4843dd6c61f 100644--- a/web/src/hashchange.ts+++ b/web/src/hashchange.ts@@ -35,6 +35,7 @@ import * as ui_report from "./ui_report.ts";import * as user_group_edit from "./user_group_edit.ts";import * as user_profile from "./user_profile.ts";import {user_settings} from "./user_settings.ts";+import * as util from "./util.ts";// Read https://zulip.readthedocs.io/en/latest/subsystems/hashchange-system.html// or locally: docs/subsystems/hashchange-system.md@@ -87,7 +88,7 @@ function channels_overlay_state_from_hash(): {if (hash_section === "new") {return {right_panel: "new", left_side_tab: undefined};}- if (/^\d+$/.test(hash_section)) {+ if (util.is_numeric_string(hash_section)) {return {right_panel: Number.parseInt(hash_section, 10), left_side_tab: undefined};}// validate_channels_settings_hash has already constraineddiff --git a/web/src/util.ts b/web/src/util.tsindex ebb17b79db8..94d7d12b87f 100644--- a/web/src/util.ts+++ b/web/src/util.ts@@ -284,6 +284,10 @@ export function is_channels_synonym(text: string): boolean {return text === "streams";}+export function is_numeric_string(text: string): boolean {+ return /^\d+$/.test(text);+}+export function prefix_match({value, search_term}: {value: string; search_term: string}): boolean {return filter_by_word_prefix_match([value], search_term, (s) => s).length === 1;}@@ -581,7 +585,7 @@ export function parse_youtube_start_time(url: string): number | undefined {}// t can be in seconds (e.g. 120) or in #h#m#s format (e.g. 1h2m30s)- if (/^\d+$/.test(t)) {+ if (is_numeric_string(t)) {return Number.parseInt(t, 10);}