Skip to content

feat: add tg-time tag support to HTML stream parser#60

Merged
KnightNiwrem merged 4 commits into
grammyjs:masterfrom
KnightNiwrem:master
May 21, 2026
Merged

feat: add tg-time tag support to HTML stream parser#60
KnightNiwrem merged 4 commits into
grammyjs:masterfrom
KnightNiwrem:master

Conversation

@KnightNiwrem

Copy link
Copy Markdown
Member

No description provided.

@KnightNiwrem

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a35c1e3db6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +261 to +263
const unixAttr = workingTag.attrs.get("unix");
if (!unixAttr || isNaN(parseInt(unixAttr, 10))) {
return false;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject partially numeric unix attribute values

Treating unix as valid when parseInt can read only a numeric prefix causes malformed <tg-time> tags (for example unix="1773412200abc" or unix="1e6") to be accepted and converted into a different timestamp instead of remaining literal text like other invalid tags. This silently changes user input and emits incorrect date_time entities; validate that the whole attribute is an integer string before parsing.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e4c09947a9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +353 to +355
const formatAttr = openTag.attrs.get("format");
const date_time_format = (formatAttr ??
"") as MessageEntity.DateTimeMessageEntity["date_time_format"];

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Validate tg-time format against Telegram grammar

tg-time currently copies any format attribute directly into date_time_format, but Telegram requires this string to match the date-time grammar (r|w?[dD]?[tT]?, with empty allowed). Inputs like <tg-time unix="1647531900" format="yyyy-MM-dd">…</tg-time> are therefore converted into a date_time entity that the Bot API can reject at send time, instead of being treated as invalid markup like other malformed tags.

Useful? React with 👍 / 👎.

if (!unixAttr || !/^-?\d+$/.test(unixAttr)) {
return undefined;
}
const unixTime = parseInt(unixAttr, 10);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject out-of-range tg-time unix values before parseInt

The numeric check accepts arbitrarily long digit strings, and parseInt can produce non-finite values (Infinity) for very large inputs. That yields unix_time: Infinity in the entity (which serializes to null in JSON), causing malformed outbound payloads instead of preserving the original tag text as invalid input.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5917d0bc34

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +265 to +267
const unixTime = parseInt(unixAttr, 10);
if (!Number.isFinite(unixTime)) {
return false;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject unsafe-size tg-time unix values

The current validation only checks Number.isFinite(parseInt(unixAttr, 10)), which still accepts integers outside JavaScript’s safe integer range. For inputs like unix="9007199254740993", parseInt produces a rounded value (9007199254740992), so the parser silently emits a date_time entity with the wrong timestamp instead of preserving the original markup as invalid text. This can corrupt user-provided dates for large unix values; add a safe-integer/range check before accepting the tag.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is technically true. But given that raw entity tag implementation also suffers from the same precision issue, we can allow this for now for feature parity.

@KnightNiwrem
KnightNiwrem merged commit 7654a46 into grammyjs:master May 21, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant