Node.js based forum software built for the modern web
fix: more tx fixes
Barış Soner Uşaklıadfffbf5704b
diff --git a/public/language/en-GB/post-queue.json b/public/language/en-GB/post-queue.jsonindex fe2a924274..5153d1ae6f 100644--- a/public/language/en-GB/post-queue.json+++ b/public/language/en-GB/post-queue.json@@ -16,6 +16,7 @@"content": "Content","posted": "Posted","reply-to": "Reply to \"%1\"",+ "edit": "Edit","content-editable": "Click on content to edit","category-editable": "Click on category to edit","title-editable": "Click on title to edit",diff --git a/src/groups/index.js b/src/groups/index.jsindex 1e50814a79..9829a1cc6d 100644--- a/src/groups/index.js+++ b/src/groups/index.js@@ -6,6 +6,7 @@ const plugins = require('../plugins');const privileges = require('../privileges');const slugify = require('../slugify');const cache = require('../cache');+const translator = require('../translator');const Groups = module.exports;@@ -178,7 +179,7 @@ Groups.get = async function (groupName, options) {const descriptionParsed = await plugins.hooks.fire('filter:parse.raw', String(groupData.description || ''));- groupData.descriptionParsed = descriptionParsed;+ groupData.descriptionParsed = translator.escape(descriptionParsed);groupData.members = members;groupData.membersNextStart = stop + 1;groupData.isMember = isMember;diff --git a/src/views/post-queue.tpl b/src/views/post-queue.tplindex 950fec1e2f..007fd41c25 100644--- a/src/views/post-queue.tpl+++ b/src/views/post-queue.tpl@@ -141,24 +141,25 @@{{{ if posts.data.tid }}}[[post-queue:topic]]{{{ else }}}[[post-queue:title]]{{{ end }}}</span>{{{ if !posts.data.tid }}}- <button data-action="editTitle" class="btn btn-ghost btn-sm ff-secondary border text-xs">Edit</button>+ <button data-action="editTitle" class="btn btn-ghost btn-sm ff-secondary border text-xs">[[post-queue:edit]]</button>{{{ end }}}</div><span class="small topic-title text-break">{{{ if posts.data.tid }}}<div class="d-flex flex-column align-items-start gap-1">- <a href="{config.relative_path}/topic/{posts.data.tid}">{posts.topic.title}</a>+ <a href="{config.relative_path}/topic/{posts.data.tid}">{txEscape(posts.topic.title})</a><span class="badge text-body border border-gray-300 stats text-xs"><span class="text-lowercase fw-normal">[[global:lastpost]]</span><span title="{posts.topic.lastposttimeISO}" class="timeago fw-bold"></span></span></div>{{{ end }}}- <span class="title-text">{posts.data.title}</span>+ <span class="title-text">{txEscape(posts.data.title)}</span></span>{{{if !posts.data.tid}}}<div class="topic-title-editable hidden">- <input class="form-control form-control-sm" type="text" value="{posts.data.title}"/>+ FOOOOO+ <input class="form-control form-control-sm" type="text" value="{txEscape(posts.data.title)}"/></div>{{{end}}}</li>@@ -169,7 +170,7 @@[[post-queue:category]]</div>{{{ if posts.data.cid }}}- <button data-action="editCategory" class="btn btn-ghost btn-sm ff-secondary border text-xs">Edit</button>+ <button data-action="editCategory" class="btn btn-ghost btn-sm ff-secondary border text-xs">[[post-queue:edit]]</button>{{{ end }}}</div>@@ -189,7 +190,7 @@<div class="text-xs fw-semibold">[[post-queue:crosspost-to]]</div>- <button data-action="editCategory" class="btn btn-ghost btn-sm ff-secondary border text-xs">Edit</button>+ <button data-action="editCategory" class="btn btn-ghost btn-sm ff-secondary border text-xs">[[post-queue:edit]]</button></div><div class="topic-category">@@ -210,7 +211,7 @@[[post-queue:tags]]</div>- <button data-action="editTags" class="btn btn-ghost btn-sm ff-secondary border text-xs">Edit</button>+ <button data-action="editTags" class="btn btn-ghost btn-sm ff-secondary border text-xs">[[post-queue:edit]]</button></div><div class="tag-list">{{{ each posts.data.tags }}}@@ -247,12 +248,12 @@[[post-queue:content]]</div>{{{ if ./canEdit }}}- <button data-action="editContent" class="btn btn-ghost btn-sm ff-secondary border text-xs">Edit</button>+ <button data-action="editContent" class="btn btn-ghost btn-sm ff-secondary border text-xs">[[post-queue:edit]]</button>{{{ end }}}</div>- <div class="post-content mb-auto text-break px-3 py-0 h-100">{posts.data.content}</div>+ <div class="post-content mb-auto text-break px-3 py-0 h-100">{txEscape(posts.data.content)}</div><div class="post-content-editable flex-grow-1 hidden">- <textarea class="form-control w-100 h-100 p-3">{posts.data.rawContent}</textarea>+ <textarea class="form-control w-100 h-100 p-3">{txEscape(posts.data.rawContent)}</textarea></div><div component="post-queue/link-container" class="hidden border-top mx-3 py-3"><label class="text-secondary form-text mb-2">[[post-queue:links-in-this-post]]</label>diff --git a/test/groups.js b/test/groups.jsindex 9ea3106451..3f9ee81d1b 100644--- a/test/groups.js+++ b/test/groups.js@@ -16,6 +16,7 @@ const socketGroups = require('../src/socket.io/groups');const apiGroups = require('../src/api/groups');const meta = require('../src/meta');const navigation = require('../src/navigation/admin');+const translator = require('../src/translator');describe('Groups', () => {@@ -146,6 +147,21 @@ describe('Groups', () => {});});+ describe('description', () => {+ it('should not translate group description', async () => {+ const desc = '[[global:403.login, javascript:alert(document.domain)]]';+ const txEscapedDesc = translator.escape(desc);+ await Groups.create({+ name: 'tx escape',+ description: desc,+ private: 0,+ hidden: 0,+ });+ const data = await Groups.get('tx escape', {});+ assert.strictEqual(data.descriptionParsed, txEscapedDesc);+ });+ });+describe('.search()', () => {const socketGroups = require('../src/socket.io/groups');@@ -160,7 +176,7 @@ describe('Groups', () => {it('should return the groups when search query is empty', (done) => {socketGroups.search({ uid: adminUid }, { query: '' }, (err, groups) => {assert.ifError(err);- assert.equal(groups.length, 6);+ assert.equal(groups.length, 7);done();});});diff --git a/test/posts.js b/test/posts.jsindex 83f4fca899..85d7a62fdf 100644--- a/test/posts.js+++ b/test/posts.js@@ -24,6 +24,7 @@ const file = require('../src/file');const helpers = require('./helpers');const utils = require('../src/utils');const request = require('../src/request');+const translator = require('../src/translator');describe('Post\'s', () => {let voterUid;@@ -1077,6 +1078,19 @@ describe('Post\'s', () => {assert.strictEqual(postData[0].data.content, 'the moved queued post');assert.strictEqual(postData[0].data.tid, result2.tid);});++ it('should not translate queued topic title & content', async () => {+ const text = '[[global:403.login, javascript:alert(document.domain)]]';+ const textEscaped = translator.escape(text);+ const result = await apiTopics.create({ uid: uid }, {+ cid: cid,+ title: text,+ content: text,+ });+ const { body } = await request.get(`${nconf.get('url')}/post-queue/${result.id}`, { jar });+ // should not contain the translated message+ assert(body.indexOf('Perhaps you should') === -1);+ });});describe('post editors', () => {