diff --git a/build/test.js b/build/test.js index 58b9ba7c..c83a3d1f 100644 --- a/build/test.js +++ b/build/test.js @@ -51,7 +51,9 @@ assert.equal('font/opentype', mime.lookup('file.otf')); // assert.equal('UTF-8', mime.charsets.lookup('text/plain')); -assert.equal(undefined, mime.charsets.lookup(mime.types.js)); +assert.equal('UTF-8', mime.charsets.lookup(mime.types.js)); +assert.equal('UTF-8', mime.charsets.lookup(mime.types.json)); +assert.equal(undefined, mime.charsets.lookup(mime.types.xml)); assert.equal('fallback', mime.charsets.lookup('application/octet-stream', 'fallback')); console.log('\nAll tests passed'); diff --git a/mime.js b/mime.js index 341b6a5c..a401abf7 100644 --- a/mime.js +++ b/mime.js @@ -101,7 +101,7 @@ mime.Mime = Mime; mime.charsets = { lookup: function(mimeType, fallback) { // Assume text types are utf8 - return (/^text\//).test(mimeType) ? 'UTF-8' : fallback; + return (/^text\/|^application\/(javascript|json)/).test(mimeType) ? 'UTF-8' : fallback; } };