Skip to content

Bug 2030581 - Pass is_markdown when adding comment via attachment update REST API#2591

Merged
dklawren merged 4 commits intomozilla-bteam:masterfrom
ChunMinChang:fix-attachment-comment-markdown
Apr 14, 2026
Merged

Bug 2030581 - Pass is_markdown when adding comment via attachment update REST API#2591
dklawren merged 4 commits intomozilla-bteam:masterfrom
ChunMinChang:fix-attachment-comment-markdown

Conversation

@ChunMinChang
Copy link
Copy Markdown
Contributor

When using PUT /rest/bug/attachment/{id} with a 'comment' field, the resulting comment is always rendered as plain text, even when the system has use_markdown enabled.

Root cause: the update_attachment method in Bugzilla/WebService/Bug.pm does not pass is_markdown to $bug->add_comment(). The web UI path in attachment.cgi correctly sets is_markdown based on Bugzilla->params->{use_markdown}.

This means there is no way via the REST API to get a Markdown-rendered comment when updating an attachment (e.g. for sec-approval requests where both the questionnaire comment and the sec-approval? flag need to appear as a single entry).

Fix: accept an optional is_markdown parameter in update_attachment, default to the system use_markdown setting when not provided (matching attachment.cgi behavior), and pass it through to $bug->add_comment().

Steps to reproduce:

  1. PUT /rest/bug/attachment/{id} with {"comment": "### Heading\n* bold: text", "flags": [...]}
  2. The comment is stored and displayed as plain text, not Markdown

Expected: The comment should respect is_markdown (or default to the system use_markdown setting).

Actual: is_markdown is never passed to add_comment(); passing it as a top-level parameter causes: "The requested method 'Bugzilla::Attachment::set_is_markdown' was not found."

What this patch does

The update_attachment WebService method does not pass is_markdown to add_comment(), so comments added through PUT /rest/bug/attachment/{id} are always rendered as plain text. The web UI path in attachment.cgi correctly sets is_markdown based on the system use_markdown parameter.

This patch:

  • Accepts an optional is_markdown parameter in update_attachment
  • Defaults to the system use_markdown setting when not provided (matching attachment.cgi behavior)
  • Passes it through to $bug->add_comment()
  • Documents the new parameter in the REST API docs

…ate REST API

The update_attachment WebService method does not pass is_markdown to
add_comment(), so comments added through PUT /rest/bug/attachment/{id}
are always rendered as plain text. The web UI path in attachment.cgi
correctly sets is_markdown based on the system use_markdown parameter.

This patch:
- Accepts an optional is_markdown parameter in update_attachment
- Defaults to the system use_markdown setting when not provided
  (matching attachment.cgi behavior)
- Passes it through to $bug->add_comment()
- Documents the new parameter in the REST API docs
Copy link
Copy Markdown
Collaborator

@dklawren dklawren left a comment

Choose a reason for hiding this comment

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

While we are working on this, we should go ahead and fix other comment related methods that do not handle markdown params correctly.

The add_comment WebService method (line 1224-1225) defaults is_markdown to 0 when not provided:
is_markdown => (defined $params->{is_markdown} ? $params->{is_markdown} : 0)

But this PR defaults update_attachment to Bugzilla->params->{use_markdown}. This means the same API caller gets different markdown behavior depending on whether they're using POST /rest/bug/{id}/comment vs PUT /rest/bug/attachment/{id}. The PR
description justifies it as "matching attachment.cgi behavior", which is correct.

Would you be able to make the other places honor the Bugzilla->params->{use_markdown} value as well?

Comment thread Bugzilla/WebService/Bug.pm Outdated
Copy link
Copy Markdown
Collaborator

@dklawren dklawren left a comment

Choose a reason for hiding this comment

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

After this requested change, we should be good to go.

Comment thread Bugzilla/WebService/Bug.pm
@dklawren dklawren merged commit 5cd679c into mozilla-bteam:master Apr 14, 2026
8 checks passed
@dklawren
Copy link
Copy Markdown
Collaborator

Thanks for the work!

@ChunMinChang ChunMinChang deleted the fix-attachment-comment-markdown branch April 15, 2026 20:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants