Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

bots: Extract shared frontend bot short_name validation helper.

saiyam0211699cc3384502
diff --git a/web/src/bot_helper.ts b/web/src/bot_helper.ts
index e0e7149bc48..940db1c3a56 100644
--- a/web/src/bot_helper.ts
+++ b/web/src/bot_helper.ts
@@ -8,6 +8,11 @@ import * as channel from "./channel.ts";
import {show_copied_confirmation} from "./copied_tooltip.ts";
import {realm} from "./state_data.ts";
+export function validate_bot_short_name(value: string): boolean {
+ // Adapted from Django's EmailValidator
+ return /^[\w!#$%&'*+/=?^`{|}~-]+(\.[\w!#$%&'*+/=?^`{|}~-]+)*$/i.test(value);
+}
+
export function generate_zuliprc_url(bot_id: number): string {
const bot = bot_data.get(bot_id);
assert(bot !== undefined);
diff --git a/web/src/settings_bots.ts b/web/src/settings_bots.ts
index f1e816397ee..9781aa64b12 100644
--- a/web/src/settings_bots.ts
+++ b/web/src/settings_bots.ts
@@ -111,11 +111,6 @@ const your_bots_section: BotSettingsSection = {
list_widget: undefined,
};
-function is_local_part(value: string): boolean {
- // Adapted from Django's EmailValidator
- return /^[\w!#$%&'*+/=?^`{|}~-]+(\.[\w!#$%&'*+/=?^`{|}~-]+)*$/i.test(value);
-}
-
function sort_bot_email(a: BotInfo, b: BotInfo): number {
function email(bot: BotInfo): string {
return (bot.display_email ?? "").toLowerCase();
@@ -355,7 +350,7 @@ export function add_a_new_bot(): void {
function validate_input(): boolean {
const bot_short_name = $<HTMLInputElement>("input#create_bot_short_name").val()!;
- if (is_local_part(bot_short_name)) {
+ if (bot_helper.validate_bot_short_name(bot_short_name)) {
return true;
}
ui_report.error(