Skip to content

Commit

Permalink
Merge pull request #513 from datacamp/entropitor/fix-encoding
Browse files Browse the repository at this point in the history
Fix html entities encoding [CT-4795]
  • Loading branch information
entropitor authored Nov 7, 2022
2 parents fd4d820 + 3792702 commit fdca3d1
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
3 changes: 3 additions & 0 deletions api/controllers/TopicController.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
var Promise = require('bluebird');
var _ = require('lodash');
var htmlEntities = require('html-entities');


module.exports = {
Expand Down Expand Up @@ -166,6 +167,8 @@ module.exports = {
else return compareValue;
});
topicJSON.dcl = dcl || (topicJSON.package_version && topicJSON.package_version.package.type_id === 4); //in the list or in base r
// We decode html entities again (as some older packages didn't have this fix in place)
topicJSON.examples = htmlEntities.decode(topicJSON.examples)
topicJSON.user_examples = userExamples;
return topicJSON;
});
Expand Down
5 changes: 3 additions & 2 deletions api/models/Topic.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
var _ = require('lodash');
var Promise = require('bluebird');
var sanitizeHtml = require('sanitize-html');
var htmlEntities = require('html-entities');

module.exports = {

Expand Down Expand Up @@ -237,10 +238,10 @@ module.exports = {
topic.description = topic.description.contents;
}

topic.examples = sanitizeHtml(topic.examples, {
topic.examples = htmlEntities.decode(sanitizeHtml(topic.examples, {
allowedTags: [],
allowedAttributes: {}
});
}));

var arrayToString = function(val) {
if (val instanceof Array) {
Expand Down
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"grunt-sass": "^2.0.0",
"grunt-sync": "0.2.4",
"grunt-version-assets": "^1.1.0",
"html-entities": "^2.3.3",
"include-all": "~0.1.6",
"lodash": "^4.13.1",
"marked": "^0.3.5",
Expand Down

0 comments on commit fdca3d1

Please sign in to comment.