Skip to content

Commit

Permalink
Add extensions from IANA for more MIME types
Browse files Browse the repository at this point in the history
  • Loading branch information
dougwilson committed May 14, 2022
1 parent bbca7ce commit c1b21ca
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 11 deletions.
1 change: 1 addition & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
unreleased
==========

* Add extensions from IANA for more MIME types
* Add new upstream MIME types
* Remove obsolete MIME types from IANA data

Expand Down
20 changes: 12 additions & 8 deletions db.json
Original file line number Diff line number Diff line change
Expand Up @@ -1191,7 +1191,7 @@
},
"application/pgp-signature": {
"source": "iana",
"extensions": ["asc","sig"]
"extensions": ["sig","asc"]
},
"application/pics-rules": {
"source": "apache",
Expand Down Expand Up @@ -1307,7 +1307,8 @@
},
"application/prs.xsf+xml": {
"source": "iana",
"compressible": true
"compressible": true,
"extensions": ["xsf"]
},
"application/pskc+xml": {
"source": "iana",
Expand Down Expand Up @@ -4879,7 +4880,8 @@
},
"application/vnd.pwg-xhtml-print+xml": {
"source": "iana",
"compressible": true
"compressible": true,
"extensions": ["xhtm"]
},
"application/vnd.qualcomm.brew-app-res": {
"source": "iana"
Expand Down Expand Up @@ -5387,7 +5389,7 @@
"application/vnd.uoml+xml": {
"source": "iana",
"compressible": true,
"extensions": ["uoml"]
"extensions": ["uoml","uo"]
},
"application/vnd.uplanet.alert": {
"source": "iana"
Expand Down Expand Up @@ -7106,7 +7108,7 @@
"image/bmp": {
"source": "iana",
"compressible": true,
"extensions": ["bmp"]
"extensions": ["bmp","dib"]
},
"image/cgm": {
"source": "iana",
Expand Down Expand Up @@ -7242,7 +7244,7 @@
},
"image/prs.btif": {
"source": "iana",
"extensions": ["btif"]
"extensions": ["btif","btf"]
},
"image/prs.pti": {
"source": "iana",
Expand Down Expand Up @@ -7337,7 +7339,8 @@
"source": "iana"
},
"image/vnd.mozilla.apng": {
"source": "iana"
"source": "iana",
"extensions": ["apng"]
},
"image/vnd.ms-dds": {
"compressible": true,
Expand Down Expand Up @@ -7668,7 +7671,8 @@
"extensions": ["x_t"]
},
"model/vnd.pytha.pyox": {
"source": "iana"
"source": "iana",
"extensions": ["pyo","pyox"]
},
"model/vnd.rosette.annotated-data-model": {
"source": "iana"
Expand Down
8 changes: 6 additions & 2 deletions scripts/fetch-iana.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var getRawBody = require('raw-body')
var cogent = require('cogent')
var parser = require('csv-parse')
var toArray = require('stream-to-array')
var typer = require('media-typer')
var writedb = require('./lib/write-db')

var extensionsQuotedRegExp = /^\s*(?:\d\.\s+)?File extension(?:\(s\)|s|)\s?:(?:[^'"\r\n]+)(?:"\.?([0-9a-z_-]+)"|'\.?([0-9a-z_-]+)')/im
Expand All @@ -31,7 +32,7 @@ var trimQuotesRegExp = /^"|"$/gm
var urlReferenceRegExp = /\[(https?:\/\/[^\]]+)]/gi

var CHARSET_DEFAULT_REGEXP = /(?:\bcharset\b[^.]*(?:\.\s+default\s+(?:value\s+)?is|\bdefault[^.]*(?:of|is)|\bmust\s+have\s+the\s+value|\bvalue\s+must\s+be)\s+|\bcharset\s*\(?defaults\s+to\s+|\bdefault\b[^.]*?\bchar(?:set|act[eo]r\s+set)\b[^.]*?(?:of|is)\s+|\bcharset\s+(?:must|is)\s+always\s+(?:be\s+)?)["']?([a-z0-9]+-[a-z0-9-]+)/im
var EXTENSIONS_REGEXP = /(?:^\s*(?:\d\.\s+)?|\s+[23]\.\s+)[Ff]ile [Ee]xtension(?:\(s\)|s|)\s?:\s+(?:\*\.|\.|)([0-9a-z_-]+|[0-9A-Z_-]+)(?:\s+or\s+(?:\*\.|\.|)([0-9a-z_-]+|[0-9A-Z_-]+)\s*)?(?:\s*[34]\.\s+|\s+[A-Z(]|\s*$)/m
var EXTENSIONS_REGEXP = /(?:^\s*(?:\d\.\s+)?|\s+[23]\.\s+)[Ff]ile [Ee]xtension(?:\(s\)|s|)\s?:\s+(?:\*\.|\.|)([0-9a-z_-]+|[0-9A-Z_-]+)(?:(?:\s+or|\s*,)\s+(?:\*\.|\.|)([0-9a-z_-]+|[0-9A-Z_-]+)\s*)?(?:\s*[34]\.\s+|\s+[A-Z(]|\s*$)/m
var INTENDED_USAGE_REGEXP = /^\s*(?:(?:\d{1,2}\.|o)\s+)?Intended\s+Usage\s*:\s*([0-9a-z]+)/im
var MIME_SUBTYPE_LINE_REGEXP = /^[^:\s-]*\s*(?:MIME )?(?:[Mm]edia )?(?:[Ss]ub ?type|SUB ?TYPE)(?: (?:[Nn]ame|NAME))?\s*:\s+(?:[A-Za-z]+ [Tt]ree\s+(?:- ?)?|(?:[a-z]+ )+- )?([0-9A-Za-z][0-9A-Za-z_.+-]*)(?:\s|$)/m
var MIME_TYPE_HAS_CHARSET_PARAMETER_REGEXP = /parameters\s*:[^.]*\bcharset\b/im
Expand Down Expand Up @@ -90,7 +91,10 @@ co(function * () {
}

// keep unambigious extensions
var extensions = (result.extensions || []).filter(function (ext) { return exts[ext] === 1 })
var extensions = (result.extensions || []).filter(function (ext) {
return exts[ext] === 1 || typer.parse(mime).subtype === ext
})

if (extensions.length !== 0) {
json[mime].extensions = extensions
}
Expand Down
6 changes: 6 additions & 0 deletions src/custom-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@
"application/pgp-encrypted": {
"compressible": false
},
"application/pgp-keys": {
"extensions": ["asc"],
"sources": [
"http://www.iana.org/assignments/media-types/application/pgp-keys"
]
},
"application/postscript": {
"compressible": true
},
Expand Down
13 changes: 12 additions & 1 deletion src/iana-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -1652,13 +1652,13 @@
]
},
"application/pgp-keys": {
"extensions": ["asc"],
"sources": [
"https://tools.ietf.org/rfc/rfc3156.txt",
"https://www.iana.org/assignments/media-types/application/pgp-keys"
]
},
"application/pgp-signature": {
"extensions": ["sig"],
"sources": [
"https://tools.ietf.org/rfc/rfc3156.txt",
"https://www.iana.org/assignments/media-types/application/pgp-signature"
Expand Down Expand Up @@ -1825,6 +1825,7 @@
]
},
"application/prs.xsf+xml": {
"extensions": ["xsf"],
"sources": [
"https://www.iana.org/assignments/media-types/application/prs.xsf+xml"
]
Expand Down Expand Up @@ -3535,6 +3536,7 @@
]
},
"application/vnd.dece.ttml+xml": {
"extensions": ["uvt","uvvt"],
"sources": [
"https://www.iana.org/assignments/media-types/application/vnd.dece.ttml+xml"
]
Expand Down Expand Up @@ -3855,6 +3857,7 @@
]
},
"application/vnd.eszigno3+xml": {
"extensions": ["es3","et3"],
"sources": [
"https://www.iana.org/assignments/media-types/application/vnd.eszigno3+xml"
]
Expand Down Expand Up @@ -5808,6 +5811,7 @@
]
},
"application/vnd.oma.dd2+xml": {
"extensions": ["dd2"],
"sources": [
"https://www.iana.org/assignments/media-types/application/vnd.oma.dd2+xml"
]
Expand Down Expand Up @@ -6524,6 +6528,7 @@
]
},
"application/vnd.pwg-xhtml-print+xml": {
"extensions": ["xhtm"],
"sources": [
"https://www.iana.org/assignments/media-types/application/vnd.pwg-xhtml-print+xml"
]
Expand Down Expand Up @@ -7126,6 +7131,7 @@
]
},
"application/vnd.uoml+xml": {
"extensions": ["uoml","uo"],
"sources": [
"https://www.iana.org/assignments/media-types/application/vnd.uoml+xml"
]
Expand Down Expand Up @@ -8761,6 +8767,7 @@
]
},
"image/bmp": {
"extensions": ["bmp","dib"],
"sources": [
"https://tools.ietf.org/rfc/rfc7903.txt",
"https://www.iana.org/assignments/media-types/image/bmp"
Expand Down Expand Up @@ -8948,6 +8955,7 @@
]
},
"image/prs.btif": {
"extensions": ["btif","btf"],
"sources": [
"https://www.iana.org/assignments/media-types/image/prs.btif"
]
Expand Down Expand Up @@ -9014,6 +9022,7 @@
]
},
"image/vnd.djvu": {
"extensions": ["djvu","djv"],
"sources": [
"https://www.iana.org/assignments/media-types/image/vnd.djvu"
]
Expand Down Expand Up @@ -9081,6 +9090,7 @@
]
},
"image/vnd.mozilla.apng": {
"extensions": ["apng"],
"sources": [
"https://www.iana.org/assignments/media-types/image/vnd.mozilla.apng"
]
Expand Down Expand Up @@ -9422,6 +9432,7 @@
]
},
"model/vnd.pytha.pyox": {
"extensions": ["pyo","pyox"],
"sources": [
"https://www.iana.org/assignments/media-types/model/vnd.pytha.pyox"
]
Expand Down

0 comments on commit c1b21ca

Please sign in to comment.