mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #6492] [MERGED] fix(tgbot): render the add-client draft as HTML and escape its values #6305
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#6305
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/MHSanaei/3x-ui/pull/6492
Author: @BlindMaster24
Created: 9/12/2026
Status: ✅ Merged
Merged: 9/13/2026
Merged by: @MHSanaei
Base:
main← Head:fix/tgbot-draft-html-render📝 Commits (1)
5668ab4fix(tgbot): render the add-client draft as HTML and escape its values📊 Changes
3 files changed (+157 additions, -8 deletions)
View changed files
📝
internal/web/service/tgbot/tgbot_client.go(+6 -5)➕
internal/web/service/tgbot/tgbot_draft_render_test.go(+148 -0)📝
internal/web/service/tgbot/tgbot_router.go(+3 -3)📄 Description
Summary
The wizard's other two text steps — the email and comment prompts, which echo the
same draft values and delete the card before they are sent — are escaped too, so
the flow cannot end on an empty screen.
BuildClientDraftMessage— the card the bot shows while an admin fills in a newclient — was written in Markdown but is sent with
ParseMode: "HTML", and itsadmin-supplied values went into the message unescaped. The card now uses the
same markup as every other message and escapes the values it interpolates.
Why
addClientrenders the draft throughSendMsgToTgbot/editMessageTgBot, andboth set
ParseMode: "HTML"(tgbot_send.go:151,tgbot_send.go:238). Thedraft's title and email were written for Markdown instead:
What the operator sees
On every card, always. The title renders as
*New client draft*— literalasterisks — and the email as
`a@b.c`with literal backticks, while the restof the bot (the client info card, the subscription links, every paged report)
renders its emphasis and its monospace values correctly through
<b>/<code>.The add-client flow is the one screen written for the other parser.
On some cards, nothing at all. The values interpolated into the draft come
straight from what the admin typed: the comment, the TG id, the email, and — on
the
Attached:line — the remarks of the inbounds the client is being attachedto. Telegram's HTML parser refuses the whole message when it meets an unescaped
reserved character, and an ampersand is enough:
Ali & Co(orpaid <10 GB>, or attaches an inbound remarkedA&B).400 Bad Request: can't parse entities, andSendMsgToTgbotlogs onewarning and gives up (
tgbot_send.go:154).later step that re-renders the same text fails the same way. The only way out
is to change the comment to something without
&,<or>, which nothingtells them.
The same mistake sat in the TG-id prompt of the same wizard
(
tgbot_router.go:1081), which is plain text with Markdown backticks around-,noneand the current value; it is rendered through the same HTML parsemode.
The sibling prompts
Two steps of the same wizard echo a draft value and delete the card before the
prompt goes out:
add_client_ch_default_emailandadd_client_ch_default_comment(tgbot_router.go:1057,:1067). Bothinterpolated that value raw into an HTML-parsed prompt, so the symptom was the
same as the card's: an admin who kept a comment of
Ali & Co, or typed an emailwith a
<, lost the prompt after the card was gone, with no error shown. Bothnow escape the value they echo, exactly like the TG-id prompt in the same
wizard.
Type of change
Areas affected
How was this tested?
internal/web/service/tgbot/tgbot_draft_render_test.gosets the draft's ownfields to values that expose both halves — a comment of
<b>promo</b> & <10 GB>— and asserts on the emitted string: the title is<b>New client draft</b>, no*or backtick marker survives anywhere in themessage, the raw comment markup does not reach it, and the escaped form
does. Both assertions fail on the old code.
TestAddClientPromptsEscapeDraftValuescovers the two sibling prompts the sameway: it drives both wizard callbacks through
answerCallbackagainst a mockedAPI with the draft set to
long<name>@example.com/promo <b>tag</b>, andasserts the prompt that reached Telegram carries the escaped form and not the raw
one. That assertion fails on the old code.
The remaining draft fields (traffic, expiry, IP limit) are generated by the bot
itself and are left unescaped on purpose; only the values an admin or an inbound
remark can carry are escaped.
I could not build or run the test locally: this machine has no C compiler, and
the CGo SQLite driver makes every package importing
internal/database— thisone included — fail to compile without one (
CONTRIBUTING.mddocuments theMinGW-w64 install).
gofmtis clean; CI is the build here.Screenshots / recordings
N/A — bot messages, no UI. The change is textual:
*New client draft*becomesNew client draft,
`email`becomesemailin monospace, and a commentof
Ali & Conow delivers the card instead of being refused.Breaking changes
None. Same cards, same fields, same buttons; only the markup they are written in
changes, and a comment that used to break the message now renders.
Checklist
go build ./...and the test suite pass locally. — same reason as above.npm run lint,npm run typecheck, andnpm run buildpass. — no frontend files touched.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.