From 50ee540b30188324198176e445330294922665fc Mon Sep 17 00:00:00 2001 From: "Alexey Ten (Lynn)" Date: Thu, 12 Nov 2015 13:10:47 +0300 Subject: [PATCH] =?UTF-8?q?=D0=AD=D0=BA=D1=80=D0=B0=D0=BD=D0=B8=D1=80?= =?UTF-8?q?=D1=83=D0=B5=D0=BC=20HTTP-=D0=B7=D0=B0=D0=B3=D0=BE=D0=BB=D0=BE?= =?UTF-8?q?=D0=B2=D0=BA=D0=B8=20=D0=B2=20=D0=BE=D1=82=D0=B2=D0=B5=D1=82?= =?UTF-8?q?=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Для обхода nodejs/node#1693 во всех HTTP-заголовках ответа делаем encodeURI для всех не-ascii символов --- lib/de.response.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/de.response.js b/lib/de.response.js index ab6be17..0efc6c0 100644 --- a/lib/de.response.js +++ b/lib/de.response.js @@ -37,22 +37,29 @@ de.Response.prototype.setRedirect = function(location) { // --------------------------------------------------------------------------------------------------------------- // +function escapeHeader(header) { + return header + .replace(/([\uD800-\uDBFF][\uDC00-\uDFFF])+/g, encodeURI) // валидные суррогатные пары + .replace(/[\uD800-\uDFFF]/g, '') // невалидные половинки суррогатных пар + .replace(/[\u0000-\u001F\u007F-\uFFFF]+/g, encodeURI); // всё остальное непечатное +} + de.Response.prototype.end = function(response, result) { var headers = this.headers; for (var header in headers) { - response.setHeader( header, headers[header] ); + response.setHeader( header, escapeHeader(headers[header]) ); } var cookies = this.cookies; var cookie = []; for (var name in cookies) { - cookie.push(name + '=' + cookies[name]); + cookie.push(escapeHeader(name + '=' + cookies[name])); } response.setHeader('Set-Cookie', cookie); // FIXME: Выставлять expire и т.д. if (this.location) { response.statusCode = 302; - response.setHeader('Location', this.location); + response.setHeader('Location', escapeHeader(this.location)); response.end(); return; }