From da0728363c5608c7479fa90c3aede3d253d1c78d Mon Sep 17 00:00:00 2001 From: Alexander Tesfamichael Date: Fri, 29 Nov 2024 15:09:24 +0100 Subject: [PATCH] feat(demotion_monitor): use safer escape_str --- src/phoenix/alerts/telegram.rs | 16 ---------------- src/phoenix/demotion_monitor.rs | 3 ++- 2 files changed, 2 insertions(+), 17 deletions(-) diff --git a/src/phoenix/alerts/telegram.rs b/src/phoenix/alerts/telegram.rs index c31aadd..66a6784 100644 --- a/src/phoenix/alerts/telegram.rs +++ b/src/phoenix/alerts/telegram.rs @@ -22,22 +22,6 @@ pub fn escape_str(input: &str) -> String { output } -// Used to escape characters inside markdown code blocks -// https://core.telegram.org/bots/api#markdownv2-style -pub fn escape_code_block(input: &str) -> String { - let mut output = String::new(); - for c in input.chars() { - match c { - '`' | '\\' => { - output.push('\\'); - } - _ => {} - } - output.push(c); - } - output -} - /// Formats a message to be compatible with the Telegram bot API. /// Respect escaping as described in: https://core.telegram.org/bots/api#markdownv2-style /// Respect character limit of 4096. diff --git a/src/phoenix/demotion_monitor.rs b/src/phoenix/demotion_monitor.rs index 3133e62..c03af23 100644 --- a/src/phoenix/demotion_monitor.rs +++ b/src/phoenix/demotion_monitor.rs @@ -112,7 +112,8 @@ fn format_demotion_message(demotion: &BuilderDemotion) -> String { let builder_id = demotion.builder_id.as_deref().unwrap_or("unknown"); let escaped_builder_id = telegram::escape_str(builder_id); let builder_pubkey = &demotion.builder_pubkey; - let error = telegram::escape_code_block(&demotion.sim_error); + // it seems escape_code_block is not safe enough here. + let error = telegram::escape_str(&demotion.sim_error); let slot = &demotion.slot; let geo = &demotion.geo; formatdoc!(