Skip to content

Commit

Permalink
Fix #54 — LTR name escaping
Browse files Browse the repository at this point in the history
  • Loading branch information
kozalosev committed Jan 1, 2025
1 parent 6a93913 commit c2a59da
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 4 additions & 1 deletion src/domain/username.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::ops::Deref;
use derive_more::{Constructor, From};

const LTR_MARK: char = '\u{200E}';

#[derive(Debug, Clone, Constructor, From, Eq, PartialEq)]
pub struct Username(String);

Expand All @@ -14,7 +16,8 @@ impl Username {
}

pub fn escaped(&self) -> String {
teloxide::utils::html::escape(self.value_ref())
let ltr_name = format!("{LTR_MARK}{}{LTR_MARK}", self.value_ref());
teloxide::utils::html::escape(&ltr_name)
}
}

Expand Down
6 changes: 2 additions & 4 deletions src/handlers/dick.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@ use teloxide::types::{CallbackQuery, InlineKeyboardButton, InlineKeyboardMarkup,
use page::{InvalidPage, Page};

use crate::{config, metrics, repo};
use crate::domain::LanguageCode;
use crate::domain::{LanguageCode, Username};
use crate::handlers::{HandlerResult, reply_html, utils};
use crate::handlers::utils::{callbacks, Incrementor, page};
use crate::repo::{ChatIdPartiality, UID};

const TOMORROW_SQL_CODE: &str = "GD0E1";
const LTR_MARK: char = '\u{200E}';
const CALLBACK_PREFIX_TOP_PAGE: &str = "top:page:";

#[derive(BotCommands, Clone)]
Expand Down Expand Up @@ -133,8 +132,7 @@ pub(crate) async fn top_impl(repos: &repo::Repositories, config: &config::AppCon
.take(config.top_limit as usize)
.enumerate()
.map(|(i, d)| {
let ltr_name = format!("{LTR_MARK}{}{LTR_MARK}", d.owner_name);
let escaped_name = teloxide::utils::html::escape(&ltr_name);
let escaped_name = Username::new(d.owner_name).escaped();
let name = if from.id == <UID as Into<UserId>>::into(d.owner_uid) {
format!("<u>{escaped_name}</u>")
} else {
Expand Down

0 comments on commit c2a59da

Please sign in to comment.