Skip to content

PM-5863: keep request body line breaks in the support Slack notification - #8

Open
jmgasper wants to merge 1 commit into
developfrom
PM-5863-1
Open

PM-5863: keep request body line breaks in the support Slack notification#8
jmgasper wants to merge 1 commit into
developfrom
PM-5863-1

Conversation

@jmgasper

Copy link
Copy Markdown
Contributor

What was broken

The Slack post for a new support ticket published the member's request body as a
single run-on line. Every newline the member typed was collapsed into a space, so
paragraphs and list items merged into one sentence. A request written as:

Steps I tried:
- Chrome, incognito
- Firefox

rendered in Slack as Steps I tried: Chrome, incognito Firefox, which reads as a
single item and loses the fact that two separate browsers were tried.

PM-5863 asked for the notification content to be on multiple lines and for the
body of the request to be included. The surrounding message lines (headline,
challenge link, ticket link) were already multi-line, but the request body — the
part of the message that most needs its own line structure — was not.

Root cause

markdownNotificationPreview was written for email template data, where the
email template controls layout, so its final sanitization step collapsed all
whitespace with /\s+/g to a single space. When the Slack request-body preview
was added, it reused that same helper and inherited the newline collapsing along
with the wanted markdown and URL stripping.

What was changed

  • Split the shared sanitization out of markdownNotificationPreview into a
    sanitizeMarkdown helper that strips markdown syntax, HTML tags, link
    targets, and HTML entities while leaving line breaks intact, plus
    previewLimit and boundPreview helpers for the bound normalization and
    code-point-safe truncation that both previews already needed.
  • Added markdownNotificationBlockPreview, which collapses only horizontal
    whitespace, trims each line, and reduces runs of blank lines to a single
    paragraph break. Embedded URLs and raw markdown are still never published and
    the preview is still bounded, so the existing sanitization guarantees are
    unchanged.
  • deliverSlack now builds the new-ticket request body with
    markdownNotificationBlockPreview instead of the single-line preview.
  • markdownNotificationPreview keeps its exact previous output and remains the
    helper used for every email template field, so email content is untouched.
  • Updated the deliverSlack and slackMessage documentation and the README
    notification section to state that the body preview keeps the author's line
    and paragraph breaks.

The Slack message now renders as:

New support ticket opened by member_one.
Challenge: <https://work.topcoder.com/challenges/30012345|30012345>
Ticket: https://support.topcoder.com/tickets/abc-123
Request:
My submission failed to upload.

Steps I tried:
Chrome, incognito
Firefox

The error was "500 Internal Server Error".

Any added/updated tests

  • notification-outbox.service.spec.ts: a delivery test asserting the opened
    Slack message carries the request body as its own lines, including the blank
    paragraph separators and the two list items on separate lines.
  • notification-outbox.service.spec.ts: unit tests for
    markdownNotificationBlockPreview covering CRLF input, markdown heading and
    list marker removal, link targets being stripped, blank-line runs collapsing
    to one, and bounding that does not split a Unicode code point.

Commands run: pnpm prisma:generate, pnpm lint, pnpm build,
pnpm test --runInBand — 8 suites / 63 tests pass; lint and build are clean.

No database migration is needed for this change.

Scope note

The other PM-5863 requirements — the challenge ID as a link to
https://work.topcoder.com/challenges/{challengeId}, multi-line message
content, the request body being included at all, and a Slack notification when a
ticket is assigned to a Support Team member — were delivered in #6 and are
already merged to develop. This PR is the remaining gap in that work.

🤖 Generated with Claude Code

What was broken
The Slack post for a new support ticket published the member's request body as a
single run-on line. Every newline the member typed was collapsed into a space,
so paragraphs and list items merged into one sentence: a request written as
"Steps I tried:", "- Chrome, incognito", "- Firefox" rendered as
"Steps I tried: Chrome, incognito Firefox", which reads as one item and loses
the fact that two separate browsers were tried. PM-5863 asked for the
notification content to be on multiple lines and for the body of the request to
be included, and the body is the part of the message that most needs its own
line structure.

Root cause
markdownNotificationPreview was written for email template data, where the
template controls layout, so its final sanitization step collapsed all
whitespace with /\s+/g -> ' '. When the Slack request-body preview was added it
reused that same helper, inheriting the newline collapsing along with the
wanted markdown and URL stripping.

What was changed
- Split the shared sanitization out of markdownNotificationPreview into a
  sanitizeMarkdown helper that strips markdown syntax, HTML tags, link targets,
  and HTML entities while leaving line breaks intact, plus previewLimit and
  boundPreview helpers for the bound normalization and code-point-safe
  truncation both previews already needed.
- Added markdownNotificationBlockPreview, which collapses only horizontal
  whitespace, trims each line, and reduces runs of blank lines to a single
  paragraph break. Embedded URLs and raw markdown are still never published and
  the preview is still bounded, so the sanitization guarantees are unchanged.
- deliverSlack now builds the new-ticket request body with
  markdownNotificationBlockPreview instead of the single-line preview.
- markdownNotificationPreview keeps its exact previous output and remains the
  helper used for every email template field, so email content is untouched.
- Updated the deliverSlack and slackMessage documentation and the README
  notification section to state that the body preview keeps the author's line
  and paragraph breaks.

Any added/updated tests
- notification-outbox.service.spec.ts: a delivery test asserting the opened
  Slack message carries the request body as its own lines, including the blank
  paragraph separators and the two list items on separate lines.
- notification-outbox.service.spec.ts: unit tests for
  markdownNotificationBlockPreview covering CRLF input, markdown heading and
  list marker removal, link targets being stripped, blank-line runs collapsing
  to one, and bounding that does not split a Unicode code point.
- Commands run: pnpm prisma:generate, pnpm lint, pnpm build,
  pnpm test --runInBand (63 tests, 8 suites passing).

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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