Page MenuHomePhabricator
Authored By
Arlolra
Oct 31 2016, 6:28 PM
Size
3 KB
Referenced Files
None
Subscribers
None

0001-T149504.patch

From fdcd4d7fc9635dab8a4c62e5db284364fb2c1c21 Mon Sep 17 00:00:00 2001
From: Arlo Breault <abreault@wikimedia.org>
Date: Mon, 31 Oct 2016 10:35:19 -0700
Subject: [PATCH] T149504
Change-Id: I850e3fe756cb1f9d754b16c9c2be2996eaef4e9c
---
lib/api/apiUtils.js | 15 +++++++++------
lib/api/routes.js | 6 +++---
2 files changed, 12 insertions(+), 9 deletions(-)
diff --git a/lib/api/apiUtils.js b/lib/api/apiUtils.js
index 5996352..9ab25d4 100644
--- a/lib/api/apiUtils.js
+++ b/lib/api/apiUtils.js
@@ -9,6 +9,7 @@ var contentType = require('content-type');
var Diff = require('../utils/Diff.js').Diff;
var DU = require('../utils/DOMUtils.js').DOMUtils;
+var Util = require('../utils/Util.js').Util;
var PegTokenizer = require('../wt2html/tokenizer.js').PegTokenizer;
var Promise = require('../utils/promise.js');
var PHPParseRequest = require('../mw/ApiRequest.js').PHPParseRequest;
@@ -67,13 +68,11 @@ apiUtils.setHeader = function(res, env, name, value) {
* @method
* @param {Response} res The response object from our routing function.
* @param {MWParserEnvironment} env
- * @param {Buffer|String|Array|Object} body
- * Buffers are sent with Content-Type application/octet-stream.
- * Strings are sent with Content-Type text/html.
- * Arrays and Objects are JSON-encoded.
+ * @param {String} body
* @param {Number} [status] HTTP status code
+ * @param {Boolean} [omitEscape] Be explicit about omitting escaping.
*/
-apiUtils.sendResponse = function(res, env, body, status) {
+apiUtils.sendResponse = function(res, env, body, status, omitEscape) {
if (env.responseSent) {
return;
} else {
@@ -81,6 +80,10 @@ apiUtils.sendResponse = function(res, env, body, status) {
if (status) {
res.status(status);
}
+ body = String(body);
+ if (!omitEscape) {
+ body = Util.entityEncodeAll(body);
+ }
res.send(body);
}
};
@@ -511,6 +514,6 @@ apiUtils.wt2htmlRes = function(env, res, html, pb) {
apiUtils.jsonResponse(res, env, response);
} else {
apiUtils.setHeader(res, env, 'content-type', apiUtils.htmlContentType(env));
- apiUtils.sendResponse(res, env, html);
+ apiUtils.sendResponse(res, env, html, undefined, true);
}
};
diff --git a/lib/api/routes.js b/lib/api/routes.js
index 92fbad5..6d03264 100644
--- a/lib/api/routes.js
+++ b/lib/api/routes.js
@@ -31,7 +31,7 @@ module.exports = function(parsoidConfig, processLogger) {
err.httpStatus = httpStatus || 404;
err.suppressLoggingStack = true;
processLogger.log('fatal/request', err);
- apiUtils.sendResponse(res, {}, text, err.httpStatus);
+ apiUtils.sendResponse(res, { log: function() {} }, text, err.httpStatus);
};
// Middlewares
@@ -670,7 +670,7 @@ module.exports = function(parsoidConfig, processLogger) {
}
apiUtils.logTime(env, res, 'serializing');
apiUtils.setHeader(res, env, 'content-type', apiUtils.wikitextContentType(env));
- apiUtils.sendResponse(res, env, output);
+ apiUtils.sendResponse(res, env, output, undefined, true);
});
});
@@ -716,7 +716,7 @@ module.exports = function(parsoidConfig, processLogger) {
return apiUtils.redirectToOldid(req, res);
}
apiUtils.setHeader(res, env, 'content-type', apiUtils.wikitextContentType(env));
- apiUtils.sendResponse(res, env, env.page.src);
+ apiUtils.sendResponse(res, env, env.page.src, undefined, true);
});
} else {
p = wt2html(req, res);
--
2.10.2

File Metadata

Mime Type
text/x-diff
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
4108151
Default Alt Text
0001-T149504.patch (3 KB)

Event Timeline