Skip to content

Features/600394/al mime type consolidation#8418

Draft
jhejlsberg wants to merge 5 commits into
mainfrom
features/600394/al-mime-type-consolidation
Draft

Features/600394/al mime type consolidation#8418
jhejlsberg wants to merge 5 commits into
mainfrom
features/600394/al-mime-type-consolidation

Conversation

@jhejlsberg
Copy link
Copy Markdown
Contributor

@jhejlsberg jhejlsberg commented Jun 2, 2026

What & why

Linked work

Fixes #

How I validated this

  • I read the full diff and it contains only changes I intended.
  • I built the affected app(s) locally with no new analyzer warnings.
  • I ran the change in Business Central and confirmed it behaves as expected.
  • I added or updated tests for the new behavior, or explained below why none are needed.

What I tested and the outcome (required — be specific: scenarios, commands, screenshots for UI changes)

Risk & compatibility

@jhejlsberg jhejlsberg requested review from a team as code owners June 2, 2026 10:33
@jhejlsberg jhejlsberg marked this pull request as draft June 2, 2026 10:34
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 2, 2026

Could not find a linked ADO work item. Please link one by using the pattern 'AB#' followed by the relevant work item number. You may use the 'Fixes' keyword to automatically resolve the work item when the pull request is merged. E.g. 'Fixes AB#1234'

if LowerCaseFileName.EndsWith('.graphql') or LowerCaseFileName.EndsWith('.gql') then
exit('application/graphql');
if LowerCaseFileName.EndsWith('.js') then
exit('application/javascript');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

$\textbf{🟡\ Medium\ Severity\ —\ Style} \quad \color{gray}{\texttt{\small Iteration\ 1}}$

Wrong MIME types for image extensions

The hardcoded overrides for .gif, .jpeg, .jpg, and .png use application/* prefixes (application/gif, application/jpeg, application/jpg, application/png). These are non-standard; the correct registered types are image/gif, image/jpeg, and image/png. These incorrect values will be returned instead of what MimeTypeUtility would correctly return, potentially breaking HTTP clients or email consumers that validate MIME types.

Recommendation:

  • Remove these four override lines and let MimeTypeUtility.GetMimeType() return the correct image/* types. If .ogg and .mpeg overrides are kept for backward-compatibility reasons, the image overrides should similarly be corrected or dropped.
Suggested change
exit('application/javascript');
// Remove these lines and rely on MimeTypeUtility:
// if LowerCaseFileName.EndsWith('.gif') then exit('application/gif');
// if LowerCaseFileName.EndsWith('.jpeg') then exit('application/jpeg');
// if LowerCaseFileName.EndsWith('.jpg') then exit('application/jpg');
// if LowerCaseFileName.EndsWith('.png') then exit('application/png');
exit(CopyStr(MimeTypeUtility.GetMimeType(FileName), 1, 250));

👍 useful · ❤️ especially valuable · 👎 wrong - reply with why

if FileName.EndsWith('.js') then
exit('application/javascript');
if FileName.EndsWith('.json') then
exit('application/json');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

$\textbf{🟡\ Medium\ Severity\ —\ Style} \quad \color{gray}{\texttt{\small Iteration\ 1}}$

Wrong MIME types for image extensions in Email

The same application/gif, application/jpeg, application/jpg, application/png non-standard MIME types are retained as hardcoded overrides. Email clients are strict about Content-Type headers; sending application/gif instead of image/gif as an attachment MIME type can cause attachments to not render inline or to fail virus-scanning gateways.

Recommendation:

  • Remove the four incorrect image-type overrides and rely on MimeTypeUtility.GetMimeType(), which should return the correct image/* values.
Suggested change
exit('application/json');
// Remove the four application/* image overrides; keep only those that differ from MimeTypeUtility:
if LowerCaseFileName.EndsWith('.js') then exit('application/javascript');
if LowerCaseFileName.EndsWith('.mpeg') then exit('audio/mpeg');
if LowerCaseFileName.EndsWith('.ogg') then exit('audio/ogg');
if LowerCaseFileName.EndsWith('.php') then exit('text/php');
exit(CopyStr(MimeTypeUtility.GetMimeType(FileName), 1, 250));

👍 useful · ❤️ especially valuable · 👎 wrong - reply with why

'image/jpeg':
exit('jpeg');
end;
exit(MimeTypeUtility.GetExtension(MimeType));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Move this exist into case .. else.
It's clearer that way.

'text/html':
exit('.html');
end;
Ext := MimeTypeUtility.GetExtension(BaseType);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This isn't a 1:1 replacement, are we confident in this?

Fx In the platform CU, image/gif is a missing mimetype.

exit;
end;
end;
ContentType := CopyStr(MimeTypeUtility.GetMimeType('x.' + Rec."File Extension"), 1, 100);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Similar, move into else

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants