summaryrefslogtreecommitdiffstats
path: root/js
diff options
context:
space:
mode:
authorKohei Yoshino <kohei.yoshino@gmail.com>2018-10-01 17:43:45 +0200
committerDylan William Hardison <dylan@hardison.net>2018-10-01 17:43:45 +0200
commit0497ad51f61619b615a76d458c42f46eab28f499 (patch)
tree00f3492623a937f2fc11dc887b2637c7c63147e3 /js
parent2fde460927e475d9f55cefde4eebf53e643a4edc (diff)
downloadbugzilla-0497ad51f61619b615a76d458c42f46eab28f499.tar.gz
bugzilla-0497ad51f61619b615a76d458c42f46eab28f499.tar.xz
Bug 1421032 - Detect Markdown attachment files as text/plain so Firefox can display the content
Diffstat (limited to 'js')
-rw-r--r--js/attachment.js17
1 files 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 {
* `<input type="file">`.
*/
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);