mirror of
https://github.com/zebrajr/express.git
synced 2025-12-06 12:19:51 +01:00
Fix error when res.set cannot add charset to Content-Type
fixes #3303 closes #3305 closes #3307
This commit is contained in:
parent
5ea2a8ff8e
commit
ae0b630ac7
|
|
@ -1,6 +1,7 @@
|
||||||
unreleased
|
unreleased
|
||||||
==========
|
==========
|
||||||
|
|
||||||
|
* Fix error when `res.set` cannot add charset to `Content-Type`
|
||||||
* deps: debug@2.6.3
|
* deps: debug@2.6.3
|
||||||
- Fix: `DEBUG_MAX_ARRAY_LENGTH`
|
- Fix: `DEBUG_MAX_ARRAY_LENGTH`
|
||||||
* deps: finalhandler@~1.0.1
|
* deps: finalhandler@~1.0.1
|
||||||
|
|
|
||||||
|
|
@ -717,9 +717,14 @@ res.header = function header(field, val) {
|
||||||
: String(val);
|
: String(val);
|
||||||
|
|
||||||
// add charset to content-type
|
// add charset to content-type
|
||||||
if (field.toLowerCase() === 'content-type' && !charsetRegExp.test(value)) {
|
if (field.toLowerCase() === 'content-type') {
|
||||||
var charset = mime.charsets.lookup(value.split(';')[0]);
|
if (Array.isArray(value)) {
|
||||||
if (charset) value += '; charset=' + charset.toLowerCase();
|
throw new TypeError('Content-Type cannot be set to an Array');
|
||||||
|
}
|
||||||
|
if (!charsetRegExp.test(value)) {
|
||||||
|
var charset = mime.charsets.lookup(value.split(';')[0]);
|
||||||
|
if (charset) value += '; charset=' + charset.toLowerCase();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setHeader(field, value);
|
this.setHeader(field, value);
|
||||||
|
|
|
||||||
|
|
@ -73,6 +73,19 @@ describe('res', function(){
|
||||||
.expect('Content-Type', 'text/html; charset=lol')
|
.expect('Content-Type', 'text/html; charset=lol')
|
||||||
.expect(200, done);
|
.expect(200, done);
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should throw when Content-Type is an array', function (done) {
|
||||||
|
var app = express()
|
||||||
|
|
||||||
|
app.use(function (req, res) {
|
||||||
|
res.set('Content-Type', ['text/html'])
|
||||||
|
res.end()
|
||||||
|
});
|
||||||
|
|
||||||
|
request(app)
|
||||||
|
.get('/')
|
||||||
|
.expect(500, /TypeError: Content-Type cannot be set to an Array/, done)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('.set(object)', function(){
|
describe('.set(object)', function(){
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user