diff --git a/api/controllers/TopicController.js b/api/controllers/TopicController.js index e14c62f4..a59074a9 100644 --- a/api/controllers/TopicController.js +++ b/api/controllers/TopicController.js @@ -6,6 +6,7 @@ */ var Promise = require('bluebird'); var _ = require('lodash'); +var htmlEntities = require('html-entities'); module.exports = { @@ -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; }); diff --git a/api/models/Topic.js b/api/models/Topic.js index 2b71df04..87295c78 100644 --- a/api/models/Topic.js +++ b/api/models/Topic.js @@ -8,6 +8,7 @@ var _ = require('lodash'); var Promise = require('bluebird'); var sanitizeHtml = require('sanitize-html'); +var htmlEntities = require('html-entities'); module.exports = { @@ -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) { diff --git a/package-lock.json b/package-lock.json index 7b9dacb9..06f238f9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5639,6 +5639,11 @@ "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.5.0.tgz", "integrity": "sha512-pNgbURSuab90KbTqvRPsseaTxOJCZBD0a7t+haSN33piP9cCM4l0CqdzAif2hUqm716UovKB2ROmiabGAKVXyg==" }, + "html-entities": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/html-entities/-/html-entities-2.3.3.tgz", + "integrity": "sha512-DV5Ln36z34NNTDgnz0EWGBLZENelNAtkiFA4kyNOG2tDI6Mz1uSWiq1wAKdyjnJwyDiDO7Fa2SO1CTxPXL8VxA==" + }, "htmlparser2": { "version": "3.8.3", "resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-3.8.3.tgz", diff --git a/package.json b/package.json index ae63443f..5522e2ae 100644 --- a/package.json +++ b/package.json @@ -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",