diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2021-07-09 20:14:05 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-09 20:14:05 -0400 |
commit | 7a1570885e7310e5b1e15ab798c9eb66694a96fb (patch) | |
tree | b44ee8498a55a0ab3866e0bd67600283d6fbae29 /ext/js/templates | |
parent | 22f048e527552cf0451ea03e0e9bd869b6ad240b (diff) |
Simplify get media structure (#1817)
* Remove format argument of getMedia
* Implement escaping
Diffstat (limited to 'ext/js/templates')
-rw-r--r-- | ext/js/templates/template-renderer-media-provider.js | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/ext/js/templates/template-renderer-media-provider.js b/ext/js/templates/template-renderer-media-provider.js index 604b5331..114d3387 100644 --- a/ext/js/templates/template-renderer-media-provider.js +++ b/ext/js/templates/template-renderer-media-provider.js @@ -15,6 +15,10 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. */ +/* global + * Handlebars + */ + class TemplateRendererMediaProvider { constructor() { this._requirements = null; @@ -38,8 +42,7 @@ class TemplateRendererMediaProvider { const {media} = root; const data = this._getMediaData(media, args, namedArgs); if (data !== null) { - const {format} = namedArgs; - const result = this._getFormattedValue(data, format); + const result = this._getFormattedValue(data, namedArgs); if (typeof result === 'string') { return result; } } const defaultValue = namedArgs.default; @@ -53,8 +56,13 @@ class TemplateRendererMediaProvider { this._requirements.push(value); } - _getFormattedValue(data, format) { - return Object.prototype.hasOwnProperty.call(data, format) ? data[format] : null; + _getFormattedValue(data, namedArgs) { + let {value} = data; + const {escape=true} = namedArgs; + if (escape) { + value = Handlebars.Utils.escapeExpression(value); + } + return value; } _getMediaData(media, args, namedArgs) { |