Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkp/pkp-lib#9408 Permit escaping of mixed content when localizing strings #290

Open
wants to merge 1 commit into
base: stable-3_3_0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,11 @@ export default {
cancelLabel: this.__('common.no'),
modalName: 'delete',
title: this.deleteAnnouncementLabel,
message: this.replaceLocaleParams(this.confirmDeleteMessage, {
title: this.localize(announcement.title)
}),
message: this.replaceLocaleParams(
asmecher marked this conversation as resolved.
Show resolved Hide resolved
this.confirmDeleteMessage,
{title: this.localize(announcement.title)},
{htmlEscaping: true}
),
callback: () => {
var self = this;
$.ajax({
Expand Down
24 changes: 15 additions & 9 deletions src/components/ListPanel/emailTemplates/EmailTemplatesListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,29 @@
<list>
<list-item>
{{
replaceLocaleParams(this.subjectLabel, {
subject: item.subject
})
replaceLocaleParams(
this.subjectLabel,
{subject: item.subject},
{htmlEscaping: true}
)
}}
</list-item>
<list-item v-if="item.fromRoleId">
{{
replaceLocaleParams(this.fromLabel, {
value: getRoleLabel(item.fromRoleId)
})
replaceLocaleParams(
this.fromLabel,
{value: getRoleLabel(item.fromRoleId)},
{htmlEscaping: true}
)
}}
</list-item>
<list-item v-if="item.toRoleId">
{{
replaceLocaleParams(this.toLabel, {
value: getRoleLabel(item.toRoleId)
})
replaceLocaleParams(
this.toLabel,
{value: getRoleLabel(item.toRoleId)},
{htmlEscaping: true}
)
}}
</list-item>
<list-item
Expand Down
11 changes: 10 additions & 1 deletion src/mixins/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,20 @@ export default {
*
* @param {String} str String to replace params in
* @param {Object} params Key/value hash of params to replace
* @param {Object} [options={}]
* @param {boolean} [options.htmlEscaping=false] - Set to `true` to escape HTML content in param values.
* @return {String}
*/
replaceLocaleParams(str, params) {
replaceLocaleParams(str, params, options = {}) {
const {htmlEscaping} = options;

for (var param in params) {
asmecher marked this conversation as resolved.
Show resolved Hide resolved
let value = params[param];
if (htmlEscaping) {
var p = document.createElement('p');
p.innerText = value;
value = p.innerHTML;
}
// If a locale object is passed, take the value from the current locale
asmecher marked this conversation as resolved.
Show resolved Hide resolved
if (value === Object(value)) {
value = this.localize(value);
Expand Down