Skip to content

Commit 21a08f1

Browse files
committed
Special-case html charset to prevent possible breaking change
1 parent 7eaeb9e commit 21a08f1

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

lib/middleware.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ module.exports = function wrapper(context) {
7272

7373
let contentType = mime.getType(filename);
7474
const mimeInfo = mimeDb[contentType];
75-
const charset = mimeInfo && mimeInfo.charset;
75+
const charset = (mimeInfo && mimeInfo.charset)
76+
// Special-cased to prevent possible breaking change
77+
|| (contentType === 'text/html' && 'UTF-8');
7678

7779
if (charset) {
7880
contentType += `; charset=${charset}`;

test/tests/server.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ describe('Server', () => {
9696

9797
it('request to directory', (done) => {
9898
request(app).get('/public/')
99-
.expect('Content-Type', 'text/html')
99+
.expect('Content-Type', 'text/html; charset=UTF-8')
100100
.expect('Content-Length', '10')
101101
.expect(200, /My Index\./, done);
102102
});
@@ -167,7 +167,6 @@ describe('Server', () => {
167167

168168
it('request to directory', (done) => {
169169
request(app).get('/')
170-
.expect('Content-Type', 'text/html; charset=utf-8')
171170
.expect(404, done);
172171
});
173172
});
@@ -240,7 +239,7 @@ describe('Server', () => {
240239
it('request to Index.phtml', (done) => {
241240
request(app).get('/')
242241
.expect('welcome')
243-
.expect('Content-Type', /text\/html/)
242+
.expect('Content-Type', 'text/html; charset=UTF-8')
244243
.expect(200, done);
245244
});
246245

0 commit comments

Comments
 (0)