From 0497ad51f61619b615a76d458c42f46eab28f499 Mon Sep 17 00:00:00 2001 From: Kohei Yoshino Date: Mon, 1 Oct 2018 11:43:45 -0400 Subject: Bug 1421032 - Detect Markdown attachment files as text/plain so Firefox can display the content --- js/attachment.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/js/attachment.js b/js/attachment.js index 86b10bf24..5266c3d5e 100644 --- a/js/attachment.js +++ b/js/attachment.js @@ -412,12 +412,17 @@ Bugzilla.AttachmentForm = class AttachmentForm { * ``. */ process_file(file, transferred = true) { - // Check for patches which should have the `text/plain` MIME type + // Detect patches that should have the `text/plain` MIME type const is_patch = !!file.name.match(/\.(?:diff|patch)$/) || !!file.type.match(/^text\/x-(?:diff|patch)$/); - // Check for text files which may have no MIME type or `application/*` MIME type - const is_text = !!file.name.match(/\.(?:cpp|es|h|js|json|markdown|md|rs|rst|sh|toml|ts|tsx|xml|yaml|yml)$/); - // Reassign the MIME type - const type = is_patch || (is_text && !file.type) ? 'text/plain' : (file.type || 'application/octet-stream'); + // Detect Markdown files that should have `text/plain` instead of `text/markdown` due to Firefox Bug 1421032 + const is_markdown = !!file.name.match(/\.(?:md|mkdn?|mdown|markdown)$/); + // Detect common source files that may have no MIME type or `application/*` MIME type + const is_source = !!file.name.match(/\.(?:cpp|es|h|js|json|rs|rst|sh|toml|ts|tsx|xml|yaml|yml)$/); + // Detect any plaintext file + const is_text = file.type.startsWith('text/') || is_patch || is_markdown || is_source; + // Reassign the MIME type: use `text/plain` for most text files and `application/octet-stream` as a fallback + const type = (is_patch || is_markdown || (is_source && !file.type)) ? + 'text/plain' : (file.type || 'application/octet-stream'); if (this.check_file_size(file.size)) { this.$data.required = transferred; @@ -435,7 +440,7 @@ Bugzilla.AttachmentForm = class AttachmentForm { } this.update_validation(); - this.show_preview(file, file.type.startsWith('text/') || is_patch || is_text); + this.show_preview(file, is_text); this.update_text(); this.update_content_type(type); this.update_ispatch(is_patch); -- cgit v1.2.3-24-g4f1b