From aa327fee54a17b3d87776f47fb31f603f1dbf065 Mon Sep 17 00:00:00 2001 From: xiaody Date: Fri, 23 Oct 2015 15:23:22 +0800 Subject: [PATCH] js/json should be utf-8 charset --- build/test.js | 4 +++- mime.js | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) 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; } };