Repository navigation
Conversation
❌ PR checklist incompleteThis PR cannot be merged until the following are addressed on its linked issue:
The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically. Maintainers can bypass this check by adding the |
| void aLinkTargetKeepsItsNonAsciiCharacters() { | ||
| String html = "<a href=\"https://example.com/café x\">text</a>"; | ||
|
|
||
| String markdown = ADAPTER.adapt(html).strip(); | ||
|
|
||
| assertEquals("[text](https://example.com/café x)", markdown); | ||
| } |
There was a problem hiding this comment.
⚠️ Bug: Non-ASCII link test expects a raw space the encoder now escapes
encodeLinkTarget percent-encodes every c <= ' ', so href="https://example.com/café x" is rendered as [text](https://example.com/café%20x). aLinkTargetKeepsItsNonAsciiCharacters asserts [text](https://example.com/café x) with a literal space, so the test fails every run. It also contradicts aLinkTargetCannotStartANewLine, which expects a%20b. Fix the expected value so the test checks what it means to check: non-ASCII characters are left alone while the space is encoded.
Expect the space to be encoded and the 'é' to be kept:
assertEquals("[text](https://example.com/café%20x)", markdown);
Was this helpful? React with 👍 / 👎
| public static final int MAX_MARKDOWN_CHARS = 50_000; | ||
| public static final long MAX_TABLE_CELLS = 50_000L; | ||
| public static final int MAX_HTML_CHARS = 200_000; | ||
| public static final int MAX_HTML_DEPTH = 48; |
There was a problem hiding this comment.
⚠️ Quality: New render budgets and fail-and-continue rule are not recorded
This PR adds new limits that were judgment calls, and docs/decisions/ has no record covering them. Nothing in the record set mentions alert rendering budgets. Per the repository's decision-record policy, the record would state: "Chat notification rendering refuses HTML longer than 200,000 characters, flattens elements nested deeper than 48 levels, refuses tables whose padded size or whose parsed Markdown cells exceed 50,000, and a refused notification throws RenderBudgetExceededException, so the event is recorded as failed and the alert moves on to the next event." The source is the description: "HTML longer than 200,000 characters is refused and elements nested deeper than 48 levels are flattened", "refused before parsing if its tables could hold more than 50,000 cells", and "the event is recorded as failed and the alert moves on to the next event". The repo squash-merges, so the rationale ("limits are above what Slack, Teams and Google Chat accept") would otherwise be lost. Add one record under docs/decisions/ and cite it from RenderLimits as ADR:<date>-<slug>.
Was this helpful? React with 👍 / 👎
Code Review
|
| Compact |
|
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source
| for (String line : markdown.lines().toList()) { | ||
| boolean blank = line.isBlank(); | ||
| cells += blank ? linesInRun * widestRow : 0; | ||
| linesInRun = blank ? 0 : linesInRun + 1; | ||
| widestRow = blank ? 0 : Math.max(widestRow, pipesIn(line) + 1L); | ||
| } | ||
| cells += linesInRun * widestRow; | ||
| if (cells > RenderLimits.MAX_TABLE_CELLS) { |
There was a problem hiding this comment.
requireTableCellsWithinBudget counts pipes inside fenced code as table columns. A fenced block containing one line of 250 pipes followed by 200 lines of x is under 700 characters, but its estimate exceeds 50,000 cells. The adapter preserves this code, so the chat notification now throws and is not sent, even though it contains no table.
Exclude fenced code from the estimate and add a regression test for this case.
|
Folded into PR #36279, which now carries all the alerting bounds in one change. |
What was wrong
Slack, Microsoft Teams and Google Chat alerts turn the notification's HTML into Markdown and then parse that Markdown. Neither step had a size limit:
~~~~could end the block early. Whatever followed was then read as Markdown, including tables.The only limit, 50,000 characters, was checked after the conversion had already been done in memory.
What this changes
Everything stays in the renderer (
alerting/content/render), with the numbers in one place,RenderLimits:_,+and-.When a budget is exceeded, rendering throws
RenderBudgetExceededException(anIllegalArgumentException). The event is recorded as failed with that reason, and the alert moves on to the next event. That is what already happens today for Markdown over 50,000 characters. Every other conversion error behaves as before.What users see
Nothing, for normal notifications. Slack, Teams and Google Chat all reject messages far smaller than these limits, so nothing that could have been delivered is refused. A notification over the budget shows up in the alert's failed events with a reason that names the budget.
Tests
RenderBudgetTest(unit): 12 cases. 9 failed on main before this change (for example, 500 nested quotes rendered 8,007,000 characters). The others check that an ordinary 20 x 10 table, normal pipe characters and non-ASCII link targets render exactly as before.ChatRenderBudgetIT(integration): a Slack alert receives an oversized table, records one failed event naming the budget, and still delivers the next event.AlertTickOutcomesIT,DispatchScenariosIT,AlertDeliveryIT,NotificationTemplateResourceITandTemplateTestSendITon MySQL.A backport to 2.0 follows in a separate PR, with the same code in
notifications/channels.Fix the table estimate before merging so small notifications containing fenced code are not dropped.
Findings
Summary
Adds limits while chat notifications are converted and parsed.
Diagram
%%{init: {'theme': 'neutral'}}%% flowchart TD H[Notification HTML] --> B[Check HTML size and limit depth] B --> C[Convert to Markdown] C --> T[Check Markdown length and estimated cells] T -->|Within budget| P[Parse and render chat message] B -->|Over budget| F[Record event delivery failure] C -->|Table over budget| F T -->|Over budget| F F --> N[Continue with next event]Reviews (1) · Last reviewed commit: "fix(alerts): bound the size of chat noti..." · Reviewed by Greptile