Skip to content

Commit 1550531

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

File tree

3 files changed

+37
-14
lines changed

3 files changed

+37
-14
lines changed

src/components/ListPanel/announcements/AnnouncementsListPanel.vue

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,13 @@ 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+
{
205+
title: this.localize(announcement.title)
206+
},
207+
true
208+
),
205209
callback: () => {
206210
var self = this;
207211
$.ajax({

src/components/ListPanel/emailTemplates/EmailTemplatesListItem.vue

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,35 @@
2727
<list>
2828
<list-item>
2929
{{
30-
replaceLocaleParams(this.subjectLabel, {
31-
subject: item.subject
32-
})
30+
replaceLocaleParams(
31+
this.subjectLabel,
32+
{
33+
subject: item.subject
34+
},
35+
true
36+
)
3337
}}
3438
</list-item>
3539
<list-item v-if="item.fromRoleId">
3640
{{
37-
replaceLocaleParams(this.fromLabel, {
38-
value: getRoleLabel(item.fromRoleId)
39-
})
41+
replaceLocaleParams(
42+
this.fromLabel,
43+
{
44+
value: getRoleLabel(item.fromRoleId)
45+
},
46+
true
47+
)
4048
}}
4149
</list-item>
4250
<list-item v-if="item.toRoleId">
4351
{{
44-
replaceLocaleParams(this.toLabel, {
45-
value: getRoleLabel(item.toRoleId)
46-
})
52+
replaceLocaleParams(
53+
this.toLabel,
54+
{
55+
value: getRoleLabel(item.toRoleId)
56+
},
57+
true
58+
)
4759
}}
4860
</list-item>
4961
<list-item

src/mixins/global.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,18 @@ 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 {bool} applyEscaping True iff replaced content should be HTML escaped
149150
* @return {String}
150151
*/
151-
replaceLocaleParams(str, params) {
152+
replaceLocaleParams(str, params, applyEscaping = false) {
152153
for (var param in params) {
153-
let value = params[param];
154+
var value = params[param];
155+
if (applyEscaping) {
156+
var text = document.createTextNode(value);
157+
var p = document.createElement('p');
158+
p.appendChild(text);
159+
value = p.innerHTML;
160+
}
154161
// If a locale object is passed, take the value from the current locale
155162
if (value === Object(value)) {
156163
value = this.localize(value);

0 commit comments

Comments
 (0)