From 87297dea17b77881386129abdb00e8253c4e0f91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Tue, 27 Nov 2018 15:12:15 +0100 Subject: Move RichObjectStringParser to precompiled Handlebars templates MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In Nextcloud 15 the default Content Security Policy disallows unsafe eval expressions, so Handlebars templates can no longer be compiled at runtime. For the time being that default Content Security Policy was lifted for Talk so "Handlebars.compile" could still be used. However, this only applies to Talk itself; when using Talk components in other apps they must abide to the Content Security Policy of those apps. As the RichObjectStringParser is going to be used in the Files app it has been moved to precompiled Handlebars templates (which are still compatible with the regular Talk UI). Signed-off-by: Daniel Calviño Sánchez --- js/views/richobjectstringparser.js | 34 ++++-------------- js/views/templates.js | 42 ++++++++++++++++++++++ .../richobjectstringparser_filepreview.handlebars | 4 +++ .../richobjectstringparser_unknown.handlebars | 1 + .../richobjectstringparser_unknownlink.handlebars | 1 + .../richobjectstringparser_userlocal.handlebars | 9 +++++ 6 files changed, 64 insertions(+), 27 deletions(-) create mode 100644 js/views/templates/richobjectstringparser_filepreview.handlebars create mode 100644 js/views/templates/richobjectstringparser_unknown.handlebars create mode 100644 js/views/templates/richobjectstringparser_unknownlink.handlebars create mode 100644 js/views/templates/richobjectstringparser_userlocal.handlebars diff --git a/js/views/richobjectstringparser.js b/js/views/richobjectstringparser.js index f5a125a89..7cc3be88b 100644 --- a/js/views/richobjectstringparser.js +++ b/js/views/richobjectstringparser.js @@ -1,4 +1,4 @@ -/* global OC, OCA, Handlebars */ +/* global OC, OCA */ /** * @copyright (c) 2016 Joas Schilling @@ -9,30 +9,10 @@ * later. See the COPYING file. */ -(function(OC, OCA, Handlebars) { +(function(OC, OCA) { OCA.SpreedMe.Views.RichObjectStringParser = { - _userLocalTemplate: '' + - '' + - '' + - '' + - '' + - '{{name}}' + - '' + - '', - - _filePreviewTemplate: '' + - '' + - '' + - '{{name}}' + - '', - - _unknownTemplate: '{{name}}', - _unknownLinkTemplate: '{{name}}', - /** * @param {string} subject * @param {Object} parameters @@ -69,7 +49,7 @@ switch (parameter.type) { case 'user': if (!this.userLocalTemplate) { - this.userLocalTemplate = Handlebars.compile(this._userLocalTemplate); + this.userLocalTemplate = OCA.SpreedMe.Views.Templates['richobjectstringparser_userlocal']; } if (!parameter.name) { parameter.name = parameter.id; @@ -81,20 +61,20 @@ case 'file': if (!this.filePreviewTemplate) { - this.filePreviewTemplate = Handlebars.compile(this._filePreviewTemplate); + this.filePreviewTemplate = OCA.SpreedMe.Views.Templates['richobjectstringparser_filepreview']; } return this.filePreviewTemplate(parameter); default: if (!_.isUndefined(parameter.link)) { if (!this.unknownLinkTemplate) { - this.unknownLinkTemplate = Handlebars.compile(this._unknownLinkTemplate); + this.unknownLinkTemplate = OCA.SpreedMe.Views.Templates['richobjectstringparser_unknownlink']; } return this.unknownLinkTemplate(parameter); } if (!this.unknownTemplate) { - this.unknownTemplate = Handlebars.compile(this._unknownTemplate); + this.unknownTemplate = OCA.SpreedMe.Views.Templates['richobjectstringparser_unknown']; } return this.unknownTemplate(parameter); } @@ -102,4 +82,4 @@ }; -})(OC, OCA, Handlebars); +})(OC, OCA); diff --git a/js/views/templates.js b/js/views/templates.js index ee6175bc1..7713d32b6 100644 --- a/js/views/templates.js +++ b/js/views/templates.js @@ -86,4 +86,46 @@ templates['chatview_comment'] = template({"1":function(container,depth0,helpers, + ((stack1 = ((helper = (helper = helpers.formattedMessage || (depth0 != null ? depth0.formattedMessage : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"formattedMessage","hash":{},"data":data}) : helper))) != null ? stack1 : "") + "\n\n"; },"useData":true}); +templates['richobjectstringparser_filepreview'] = template({"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) { + var helper, alias1=depth0 != null ? depth0 : (container.nullContext || {}), alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression; + + return "\n \n " + + alias4(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"name","hash":{},"data":data}) : helper))) + + "\n\n"; +},"useData":true}); +templates['richobjectstringparser_unknown'] = template({"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) { + var helper; + + return "" + + container.escapeExpression(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),{"name":"name","hash":{},"data":data}) : helper))) + + "\n"; +},"useData":true}); +templates['richobjectstringparser_unknownlink'] = template({"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) { + var helper, alias1=depth0 != null ? depth0 : (container.nullContext || {}), alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression; + + return "" + + alias4(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"name","hash":{},"data":data}) : helper))) + + "\n"; +},"useData":true}); +templates['richobjectstringparser_userlocal'] = template({"1":function(container,depth0,helpers,partials,data) { + return "currentUser"; +},"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) { + var stack1, helper, alias1=depth0 != null ? depth0 : (container.nullContext || {}), alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression; + + return "\n \n \n \n " + + alias4(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"name","hash":{},"data":data}) : helper))) + + "\n \n\n"; +},"useData":true}); })(); \ No newline at end of file diff --git a/js/views/templates/richobjectstringparser_filepreview.handlebars b/js/views/templates/richobjectstringparser_filepreview.handlebars new file mode 100644 index 000000000..608e485b9 --- /dev/null +++ b/js/views/templates/richobjectstringparser_filepreview.handlebars @@ -0,0 +1,4 @@ + + + {{name}} + diff --git a/js/views/templates/richobjectstringparser_unknown.handlebars b/js/views/templates/richobjectstringparser_unknown.handlebars new file mode 100644 index 000000000..a57be02ac --- /dev/null +++ b/js/views/templates/richobjectstringparser_unknown.handlebars @@ -0,0 +1 @@ +{{name}} diff --git a/js/views/templates/richobjectstringparser_unknownlink.handlebars b/js/views/templates/richobjectstringparser_unknownlink.handlebars new file mode 100644 index 000000000..705f62e19 --- /dev/null +++ b/js/views/templates/richobjectstringparser_unknownlink.handlebars @@ -0,0 +1 @@ +{{name}} diff --git a/js/views/templates/richobjectstringparser_userlocal.handlebars b/js/views/templates/richobjectstringparser_userlocal.handlebars new file mode 100644 index 000000000..f12b395cf --- /dev/null +++ b/js/views/templates/richobjectstringparser_userlocal.handlebars @@ -0,0 +1,9 @@ + + + + + {{name}} + + -- cgit v1.2.3