Skip to content

Commit fdca3d1

Browse files
authored
Merge pull request #513 from datacamp/entropitor/fix-encoding
Fix html entities encoding [CT-4795]
2 parents fd4d820 + 3792702 commit fdca3d1

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

api/controllers/TopicController.js

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77
var Promise = require('bluebird');
88
var _ = require('lodash');
9+
var htmlEntities = require('html-entities');
910

1011

1112
module.exports = {
@@ -166,6 +167,8 @@ module.exports = {
166167
else return compareValue;
167168
});
168169
topicJSON.dcl = dcl || (topicJSON.package_version && topicJSON.package_version.package.type_id === 4); //in the list or in base r
170+
// We decode html entities again (as some older packages didn't have this fix in place)
171+
topicJSON.examples = htmlEntities.decode(topicJSON.examples)
169172
topicJSON.user_examples = userExamples;
170173
return topicJSON;
171174
});

api/models/Topic.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
var _ = require('lodash');
99
var Promise = require('bluebird');
1010
var sanitizeHtml = require('sanitize-html');
11+
var htmlEntities = require('html-entities');
1112

1213
module.exports = {
1314

@@ -237,10 +238,10 @@ module.exports = {
237238
topic.description = topic.description.contents;
238239
}
239240

240-
topic.examples = sanitizeHtml(topic.examples, {
241+
topic.examples = htmlEntities.decode(sanitizeHtml(topic.examples, {
241242
allowedTags: [],
242243
allowedAttributes: {}
243-
});
244+
}));
244245

245246
var arrayToString = function(val) {
246247
if (val instanceof Array) {

package-lock.json

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"grunt-sass": "^2.0.0",
4242
"grunt-sync": "0.2.4",
4343
"grunt-version-assets": "^1.1.0",
44+
"html-entities": "^2.3.3",
4445
"include-all": "~0.1.6",
4546
"lodash": "^4.13.1",
4647
"marked": "^0.3.5",

0 commit comments

Comments
 (0)