[Pkg-javascript-commits] [node-mime] 06/08: Imported Upstream version 1.2.10

Jérémy Lal kapouer-guest at alioth.debian.org
Wed Aug 14 09:50:07 UTC 2013


This is an automated email from the git hooks/post-receive script.

kapouer-guest pushed a commit to branch master
in repository node-mime.

commit 566dd8b2e5573f25cc32a9de94c12e683acb9404
Author: Jérémy Lal <kapouer at melix.org>
Date:   Wed Aug 14 11:47:04 2013 +0200

    Imported Upstream version 1.2.10
---
 README.md        |    5 ++++-
 mime.js          |    3 ++-
 package.json     |    2 +-
 test.js          |   29 +++++++++++++++++++++++++++++
 types/mime.types |    2 +-
 types/node.types |   21 +++++++++++++++++++--
 6 files changed, 56 insertions(+), 6 deletions(-)

diff --git a/README.md b/README.md
index b90552a..6ca19bd 100644
--- a/README.md
+++ b/README.md
@@ -11,7 +11,7 @@ Install with [npm](http://github.com/isaacs/npm):
 ## API - Queries
 
 ### mime.lookup(path)
-Get the mime type associated with a file. Performs a case-insensitive lookup using the extension in `path` (the substring after the last '/' or '.').  E.g.
+Get the mime type associated with a file, if no mime type is found `application/octet-stream` is returned. Performs a case-insensitive lookup using the extension in `path` (the substring after the last '/' or '.').  E.g.
 
     var mime = require('mime');
 
@@ -20,6 +20,9 @@ Get the mime type associated with a file. Performs a case-insensitive lookup usi
     mime.lookup('.TXT');                      // => 'text/plain'
     mime.lookup('htm');                       // => 'text/html'
 
+### mime.default_type
+Sets the mime type returned when `mime.lookup` fails to find the extension searched for. (Default is `application/octet-stream`.)
+
 ### mime.extension(type)
 Get the default extension for `type`
 
diff --git a/mime.js b/mime.js
index 70a6384..8a7eb09 100644
--- a/mime.js
+++ b/mime.js
@@ -78,7 +78,8 @@ Mime.prototype.lookup = function(path, fallback) {
  * Return file extension associated with a mime type
  */
 Mime.prototype.extension = function(mimeType) {
-  return this.extensions[mimeType];
+  var type = mimeType.match(/^\s*([^;\s]*)(?:;|\s|$)/)[1].toLowerCase();
+  return this.extensions[type];
 };
 
 // Default instance
diff --git a/package.json b/package.json
index 6e116b1..0f82f6b 100644
--- a/package.json
+++ b/package.json
@@ -18,5 +18,5 @@
   "main": "mime.js",
   "name": "mime",
   "repository": {"url": "https://github.com/broofa/node-mime", "type": "git"},
-  "version": "1.2.9"
+  "version": "1.2.10"
 }
diff --git a/test.js b/test.js
index cbad034..27df440 100644
--- a/test.js
+++ b/test.js
@@ -4,6 +4,7 @@
 
 var mime = require('./mime');
 var assert = require('assert');
+var path = require('path');
 
 function eq(a, b) {
   console.log('Test: ' + a + ' === ' + b);
@@ -35,14 +36,23 @@ eq('application/x-web-app-manifest+json', mime.lookup('text.webapp'));
 eq('txt', mime.extension(mime.types.text));
 eq('html', mime.extension(mime.types.htm));
 eq('bin', mime.extension('application/octet-stream'));
+eq('bin', mime.extension('application/octet-stream '));
+eq('html', mime.extension(' text/html; charset=UTF-8'));
+eq('html', mime.extension('text/html; charset=UTF-8 '));
+eq('html', mime.extension('text/html; charset=UTF-8'));
+eq('html', mime.extension('text/html ; charset=UTF-8'));
+eq('html', mime.extension('text/html;charset=UTF-8'));
+eq('html', mime.extension('text/Html;charset=UTF-8'));
 eq(undefined, mime.extension('constructor'));
 
 //
 // Test node types
 //
 
+eq('application/font-woff', mime.lookup('file.woff'));
 eq('application/octet-stream', mime.lookup('file.buffer'));
 eq('audio/mp4', mime.lookup('file.m4a'));
+eq('font/opentype', mime.lookup('file.otf'));
 
 //
 // Test charsets
@@ -52,4 +62,23 @@ eq('UTF-8', mime.charsets.lookup('text/plain'));
 eq(undefined, mime.charsets.lookup(mime.types.js));
 eq('fallback', mime.charsets.lookup('application/octet-stream', 'fallback'));
 
+//
+// Test for overlaps between mime.types and node.types
+//
+
+var apacheTypes = new mime.Mime(), nodeTypes = new mime.Mime();
+apacheTypes.load(path.join(__dirname, 'types/mime.types'));
+nodeTypes.load(path.join(__dirname, 'types/node.types'));
+
+var keys = [].concat(Object.keys(apacheTypes.types))
+             .concat(Object.keys(nodeTypes.types));
+keys.sort();
+for (var i = 1; i < keys.length; i++) {
+  if (keys[i] == keys[i-1]) {
+    console.warn('Warning: ' +
+      'node.types defines ' + keys[i] + '->' + nodeTypes.types[keys[i]] +
+      ', mime.types defines ' + keys[i] + '->' + apacheTypes.types[keys[i]]);
+  }
+}
+
 console.log('\nOK');
diff --git a/types/mime.types b/types/mime.types
index b90b165..da8cd69 100644
--- a/types/mime.types
+++ b/types/mime.types
@@ -1054,7 +1054,7 @@ application/x-font-snf				snf
 # application/x-font-sunos-news
 application/x-font-ttf				ttf ttc
 application/x-font-type1			pfa pfb pfm afm
-application/x-font-woff				woff
+application/font-woff				woff
 # application/x-font-vfont
 application/x-freearc				arc
 application/x-futuresplash			spl
diff --git a/types/node.types b/types/node.types
index 970a1bd..55b2cf7 100644
--- a/types/node.types
+++ b/types/node.types
@@ -15,11 +15,11 @@ application/x-chrome-extension  crx
 # Added by: niftylettuce
 text/x-component  htc
 
-# What: HTML5 application cache manifest
+# What: HTML5 application cache manifes ('.manifest' extension)
 # Why: De-facto standard. Required by Mozilla browser when serving HTML5 apps
 # per https://developer.mozilla.org/en/offline_resources_in_firefox
 # Added by: louisremi
-text/cache-manifest  appcache manifest
+text/cache-manifest  manifest
 
 # What: node binary buffer format
 # Why: semi-standard extension w/in the node community
@@ -58,3 +58,20 @@ application/x-lua-bytecode  luac
 # Why: http://stackoverflow.com/questions/10701983/what-is-the-mime-type-for-markdown
 # Added by: avoidwork
 text/x-markdown  markdown md mkd
+
+# What: ini files
+# Why: because they're just text files
+# Added by: Matthew Kastor
+text/plain  ini
+
+# What: DASH Adaptive Streaming manifest
+# Why: https://developer.mozilla.org/en-US/docs/DASH_Adaptive_Streaming_for_HTML_5_Video
+# Added by: eelcocramer
+application/dash+xml mdp
+
+# What: OpenType font files - http://www.microsoft.com/typography/otspec/
+# Why:  Browsers usually ignore the font MIME types and sniff the content,
+#       but Chrome, shows a warning if OpenType fonts aren't served with
+#       the `font/opentype` MIME type: http://i.imgur.com/8c5RN8M.png.
+# Added by: alrra
+font/opentype  otf

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/collab-maint/node-mime.git



More information about the Pkg-javascript-commits mailing list