breaking: core html stripping on plaintext, remove 'filter:teasers.configureStripTags' hook, remove html stripping from teaser generation

These two steps were removed because a `type` property is passed to `filter:post.parse` now, and thus plugins themselves can handle independently.

Core also now strips all html when `type` is plaintext, so plugins don't have to (or if they still pass html back).
This commit is contained in:
Julian Lam
2024-07-12 12:27:17 -04:00
parent 7bdf376971
commit c01f154937
3 changed files with 6 additions and 9 deletions

View File

@@ -100,7 +100,7 @@
"nodebb-plugin-dbsearch": "6.2.5", "nodebb-plugin-dbsearch": "6.2.5",
"nodebb-plugin-emoji": "5.1.15", "nodebb-plugin-emoji": "5.1.15",
"nodebb-plugin-emoji-android": "4.0.0", "nodebb-plugin-emoji-android": "4.0.0",
"nodebb-plugin-markdown": "13.0.0-pre.8", "nodebb-plugin-markdown": "13.0.0-pre.9",
"nodebb-plugin-mentions": "4.6.7", "nodebb-plugin-mentions": "4.6.7",
"nodebb-plugin-ntfy": "1.7.4", "nodebb-plugin-ntfy": "1.7.4",
"nodebb-plugin-spam-be-gone": "2.2.2", "nodebb-plugin-spam-be-gone": "2.2.2",

View File

@@ -126,6 +126,10 @@ module.exports = function (Posts) {
}); });
}; };
Posts.sanitizePlaintext = content => sanitize(content, {
allowedTags: [],
});
Posts.configureSanitize = async () => { Posts.configureSanitize = async () => {
// Each allowed tags should have some common global attributes... // Each allowed tags should have some common global attributes...
sanitizeConfig.allowedTags.forEach((tag) => { sanitizeConfig.allowedTags.forEach((tag) => {
@@ -143,7 +147,7 @@ module.exports = function (Posts) {
plugins.hooks.register('core', { plugins.hooks.register('core', {
hook: 'filter:parse.post', hook: 'filter:parse.post',
method: async (data) => { method: async (data) => {
data.postData.content = Posts.sanitize(data.postData.content); data.postData.content = Posts[data.type !== 'plaintext' ? 'sanitize' : 'sanitizePlaintext'](data.postData.content);
return data; return data;
}, },
}); });

View File

@@ -70,19 +70,12 @@ module.exports = function (Topics) {
}); });
await Promise.all(postData.map(p => posts.parsePost(p, 'plaintext'))); await Promise.all(postData.map(p => posts.parsePost(p, 'plaintext')));
const { tags } = await plugins.hooks.fire('filter:teasers.configureStripTags', {
tags: utils.stripTags.slice(0),
});
const teasers = topics.map((topic, index) => { const teasers = topics.map((topic, index) => {
if (!topic) { if (!topic) {
return null; return null;
} }
if (tidToPost[topic.tid]) { if (tidToPost[topic.tid]) {
tidToPost[topic.tid].index = calcTeaserIndex(teaserPost, counts[index], sortNewToOld); tidToPost[topic.tid].index = calcTeaserIndex(teaserPost, counts[index], sortNewToOld);
if (tidToPost[topic.tid].content) {
tidToPost[topic.tid].content = utils.stripHTMLTags(replaceImgWithAltText(tidToPost[topic.tid].content), tags);
}
} }
return tidToPost[topic.tid]; return tidToPost[topic.tid];
}); });