Merge pull request #21126 from nextcloud/fix/make-translation-sanitization-optional-stable19
[stable19] Make the translation sanitization optional
This commit is contained in:
commit
bdb9f31cf1
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -21,7 +21,7 @@
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div id="security" class="section">
|
<div id="security" class="section">
|
||||||
<h2>{{ t('settings', 'Devices & sessions') }}</h2>
|
<h2>{{ t('settings', 'Devices & sessions', {}, undefined, {sanitize: false}) }}</h2>
|
||||||
<p class="settings-hint hidden-when-empty">
|
<p class="settings-hint hidden-when-empty">
|
||||||
{{ t('settings', 'Web, desktop and mobile clients currently logged in to your account.') }}
|
{{ t('settings', 'Web, desktop and mobile clients currently logged in to your account.') }}
|
||||||
</p>
|
</p>
|
||||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -12,6 +12,7 @@ import _ from 'underscore'
|
||||||
import $ from 'jquery'
|
import $ from 'jquery'
|
||||||
import DOMPurify from 'dompurify'
|
import DOMPurify from 'dompurify'
|
||||||
import Handlebars from 'handlebars'
|
import Handlebars from 'handlebars'
|
||||||
|
import identity from 'lodash/fp/identity'
|
||||||
import escapeHTML from 'escape-html'
|
import escapeHTML from 'escape-html'
|
||||||
|
|
||||||
import OC from './index'
|
import OC from './index'
|
||||||
|
@ -84,15 +85,20 @@ const L10n = {
|
||||||
* @param {number} [count] number to replace %n with
|
* @param {number} [count] number to replace %n with
|
||||||
* @param {array} [options] options array
|
* @param {array} [options] options array
|
||||||
* @param {bool} [options.escape=true] enable/disable auto escape of placeholders (by default enabled)
|
* @param {bool} [options.escape=true] enable/disable auto escape of placeholders (by default enabled)
|
||||||
|
* @param {bool} [options.sanitize=true] enable/disable sanitization (by default enabled)
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
translate: function(app, text, vars, count, options) {
|
translate: function(app, text, vars, count, options) {
|
||||||
const defaultOptions = {
|
const defaultOptions = {
|
||||||
escape: true,
|
escape: true,
|
||||||
|
sanitize: true,
|
||||||
}
|
}
|
||||||
const allOptions = options || {}
|
const allOptions = options || {}
|
||||||
_.defaults(allOptions, defaultOptions)
|
_.defaults(allOptions, defaultOptions)
|
||||||
|
|
||||||
|
const optSanitize = allOptions.sanitize ? DOMPurify.sanitize : identity
|
||||||
|
const optEscape = allOptions.escape ? escapeHTML : identity
|
||||||
|
|
||||||
// TODO: cache this function to avoid inline recreation
|
// TODO: cache this function to avoid inline recreation
|
||||||
// of the same function over and over again in case
|
// of the same function over and over again in case
|
||||||
// translate() is used in a loop
|
// translate() is used in a loop
|
||||||
|
@ -101,13 +107,9 @@ const L10n = {
|
||||||
function(a, b) {
|
function(a, b) {
|
||||||
const r = vars[b]
|
const r = vars[b]
|
||||||
if (typeof r === 'string' || typeof r === 'number') {
|
if (typeof r === 'string' || typeof r === 'number') {
|
||||||
if (allOptions.escape) {
|
return optSanitize(optEscape(r))
|
||||||
return DOMPurify.sanitize(escapeHTML(r))
|
|
||||||
} else {
|
} else {
|
||||||
return DOMPurify.sanitize(r)
|
return optSanitize(a)
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return DOMPurify.sanitize(a)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -120,9 +122,9 @@ const L10n = {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof vars === 'object' || count !== undefined) {
|
if (typeof vars === 'object' || count !== undefined) {
|
||||||
return DOMPurify.sanitize(_build(translation, vars, count))
|
return optSanitize(_build(translation, vars, count))
|
||||||
} else {
|
} else {
|
||||||
return DOMPurify.sanitize(translation)
|
return optSanitize(translation)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue