Skip to content

Commit 210b5b6

Browse files
committed
pkp/pkp-lib#9408 Permit escaping of mixed content when localizing strings
1 parent c742c09 commit 210b5b6

File tree

3 files changed

+31
-14
lines changed

3 files changed

+31
-14
lines changed

src/components/ListPanel/announcements/AnnouncementsListPanel.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,11 @@ export default {
199199
cancelLabel: this.__('common.no'),
200200
modalName: 'delete',
201201
title: this.deleteAnnouncementLabel,
202-
message: this.replaceLocaleParams(this.confirmDeleteMessage, {
203-
title: this.localize(announcement.title)
204-
}),
202+
message: this.replaceLocaleParams(
203+
this.confirmDeleteMessage,
204+
{title: this.localize(announcement.title)},
205+
{htmlEscaping: true}
206+
),
205207
callback: () => {
206208
var self = this;
207209
$.ajax({

src/components/ListPanel/emailTemplates/EmailTemplatesListItem.vue

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,29 @@
2727
<list>
2828
<list-item>
2929
{{
30-
replaceLocaleParams(this.subjectLabel, {
31-
subject: item.subject
32-
})
30+
replaceLocaleParams(
31+
this.subjectLabel,
32+
{subject: item.subject},
33+
{htmlEscaping: true}
34+
)
3335
}}
3436
</list-item>
3537
<list-item v-if="item.fromRoleId">
3638
{{
37-
replaceLocaleParams(this.fromLabel, {
38-
value: getRoleLabel(item.fromRoleId)
39-
})
39+
replaceLocaleParams(
40+
this.fromLabel,
41+
{value: getRoleLabel(item.fromRoleId)},
42+
{htmlEscaping: true}
43+
)
4044
}}
4145
</list-item>
4246
<list-item v-if="item.toRoleId">
4347
{{
44-
replaceLocaleParams(this.toLabel, {
45-
value: getRoleLabel(item.toRoleId)
46-
})
48+
replaceLocaleParams(
49+
this.toLabel,
50+
{value: getRoleLabel(item.toRoleId)},
51+
{htmlEscaping: true}
52+
)
4753
}}
4854
</list-item>
4955
<list-item

src/mixins/global.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,20 @@ export default {
146146
*
147147
* @param {String} str String to replace params in
148148
* @param {Object} params Key/value hash of params to replace
149+
* @param {Object} [options={}]
150+
* @param {boolean} [options.htmlEscaping=false] - Set to `true` to escape HTML content in param values.
149151
* @return {String}
150152
*/
151-
replaceLocaleParams(str, params) {
153+
replaceLocaleParams(str, params, options = {}) {
154+
const {htmlEscaping} = options;
155+
152156
for (var param in params) {
153-
let value = params[param];
157+
var value = params[param];
158+
if (htmlEscaping) {
159+
var p = document.createElement('p');
160+
p.innerText = value;
161+
value = p.innerHTML;
162+
}
154163
// If a locale object is passed, take the value from the current locale
155164
if (value === Object(value)) {
156165
value = this.localize(value);

0 commit comments

Comments
 (0)