fix(miniapp): strip HTML tags from web app promo error messages

Localized promo errors carry Telegram-style <code> markup, which the
web app rendered as literal text. Strip tags and unescape entities
before returning the message in the JSON error.
This commit is contained in:
3252a8
2026-06-03 09:53:41 +03:00
parent 1605be0dfa
commit 0a294b8bf8
+10 -1
View File
@@ -5,6 +5,15 @@ from bot.app.web.webapp.cache_helpers import invalidate_webapp_user_caches
from db.dal import message_log_dal from db.dal import message_log_dal
_HTML_TAG_RE = re.compile(r"<[^>]+>")
def _plain_text_message(value: Any) -> str:
"""Strip Telegram-style HTML markup from a localized message for the web app."""
text = _HTML_TAG_RE.sub("", str(value))
return html.unescape(text).strip()
def _billing_iso_datetime(value: Optional[Any]) -> Optional[str]: def _billing_iso_datetime(value: Optional[Any]) -> Optional[str]:
if not value: if not value:
return None return None
@@ -69,7 +78,7 @@ async def apply_promo_route(request: web.Request) -> web.Response:
) )
if not success: if not success:
await session.commit() await session.commit()
return _json_error(400, "promo_apply_failed", str(result)) return _json_error(400, "promo_apply_failed", _plain_text_message(result))
await session.commit() await session.commit()
end_date = result if isinstance(result, datetime) else None end_date = result if isinstance(result, datetime) else None
return web.json_response( return web.json_response(