Skip to content

Commit 2d77c21

Browse files
author
Mike Taylor
authored
Merge pull request #1682 from /issues/1679/1
Fixes: #1679. Remove unsafe-eval directive from our CSP policy.
2 parents 433c70b + 697d8b5 commit 2d77c21

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+323
-240
lines changed

.eslintrc

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"Promise": true,
2828
"require": true,
2929
"wcEvents": true,
30+
"wcTmpl": true,
3031
"WindowHelpers": true
3132
},
3233
"rules": {

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ webcompat/static/js/issues.js
2525
webcompat/static/js/issue-list.js
2626
webcompat/static/js/user-activity.js
2727
webcompat/static/js/cssfixme.js
28+
webcompat/static/js/templates.js
2829
webcompat/**/*.min.js
2930
webcompat/**/*.min.css
3031
webcompat/**/*.dev.css

Gruntfile.js

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
module.exports = function(grunt) {
66
grunt.initConfig({
77
pkg: grunt.file.readJSON("package.json"),
8+
tmplPath: "webcompat/templates/",
89
jsPath: "webcompat/static/js",
910
cssPath: "webcompat/static/css",
1011
imgPath: "webcompat/static/img",
@@ -24,6 +25,7 @@ module.exports = function(grunt) {
2425
// Default task.
2526
grunt.registerTask("default", [
2627
"checkDependencies",
28+
"jst",
2729
"concat",
2830
"uglify",
2931
"postcss",
@@ -33,6 +35,7 @@ module.exports = function(grunt) {
3335
// Task used before doing a deploy (same as default, but does image optimization)
3436
grunt.registerTask("deploy", [
3537
"checkDependencies",
38+
"jst",
3639
"concat",
3740
"uglify",
3841
"postcss",

docs/dev-env-setup.md

+1
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ After certain kinds of changes are made, you need to build the project before se
198198

199199
* CSS: a build will run cssnext, combine custom media queries, and concat all source files into webcompat.dev.css. You'll need to re-build the CSS to see any changes, so it's recommended to use a watch task (see `npm run watch`).
200200
* JS: a build will run eslint, minify and concat source files.
201+
* JS templates (.jst files): if you are making changes to a Backbone template in a `.jst` file, you will need to re-run the `build` command to update the pre-compiled `templates.js` file before you will see the results.
201202
* HTML templates: the changes should be served from disk without the need for rebuilding
202203
* Python: the Flask local server will detect changes and restart automatically. No need to re-build.
203204

grunt-tasks/concat.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ module.exports = function(grunt) {
2222
"<%= jsPath %>/vendor/backbone.mousetrap.js",
2323
"<%= jsPath %>/lib/flash-message.js",
2424
"<%= jsPath %>/lib/homepage.js",
25-
"<%= jsPath %>/lib/bugform.js"
25+
"<%= jsPath %>/lib/bugform.js",
26+
"<%= jsPath %>/templates.js"
2627
],
2728
dest: "<%= jsPath %>/<%= pkg.name %>.js"
2829
},

grunt-tasks/jst.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
5+
module.exports = function(grunt) {
6+
grunt.config("jst", {
7+
compile: {
8+
options: {
9+
namespace: "wcTmpl",
10+
prettify: true,
11+
processContent: function(src) {
12+
// strip the opening and closing <script> tags...
13+
// otherwise, the template functions will just inject script elements
14+
// that won't render.
15+
src = src.replace(/<script type="text\/template">/, "");
16+
src = src.replace(/<\/script>/, "");
17+
return src.trim();
18+
},
19+
processName: function(filename) {
20+
// make this a bit less redunant when we have to refer back
21+
// to the pre-compiled template function names.
22+
return filename.split("webcompat/templates/")[1];
23+
}
24+
},
25+
files: {
26+
"<%= jsPath %>/templates.js": ["<%= tmplPath %>/**/*.jst"]
27+
}
28+
}
29+
});
30+
};

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"grunt-contrib-concat": "^1.0.0",
3333
"grunt-contrib-cssmin": "^2.0.0",
3434
"grunt-contrib-imagemin": "~1.0.1",
35+
"grunt-contrib-jst": "^1.0.0",
3536
"grunt-contrib-uglify": "^2.3.0",
3637
"grunt-contrib-watch": "^1.0.0",
3738
"grunt-postcss": "^0.8.0",

webcompat/helpers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ def add_csp(response):
494494
"font-src 'self'; " +
495495
"img-src 'self' https://www.google-analytics.com https://*.githubusercontent.com data:; " + # nopep8
496496
"manifest-src 'self'; " +
497-
"script-src 'self' 'unsafe-eval' https://www.google-analytics.com https://api.github.com; " + # nopep8
497+
"script-src 'self' https://www.google-analytics.com https://api.github.com; " + # nopep8
498498
"style-src 'self' 'unsafe-inline'; " +
499499
"report-uri /csp-report"
500500
)

webcompat/static/js/lib/comments.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ issues.CommentView = Backbone.View.extend({
2626
id: function() {
2727
return this.model.get("commentLinkId");
2828
},
29-
template: _.template($("#comment-tmpl").html()),
29+
template: wcTmpl["issue/issue-comment-list.jst"],
3030
render: function() {
3131
this.$el.html(this.template(this.model.toJSON()));
3232
return this;

webcompat/static/js/lib/diagnose.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ diagnose.NeedsTriageView = Backbone.View.extend({
2323
})
2424
.error(function() {});
2525
},
26-
template: _.template($("#needstriage-tmpl").html()),
26+
template: wcTmpl["web_modules/issue-list.jst"],
2727
render: function() {
2828
this.$el.html(
2929
this.template({

webcompat/static/js/lib/flash-message.js

+1-10
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,7 @@ var FlashMessageView = Backbone.View.extend({
4444
this.render(message);
4545
},
4646
showThanks: function(opts) {
47-
var buildTemplate = _.template(
48-
[
49-
"<h4>Thanks for reporting an issue!</h4>",
50-
"<p>You're helping us make the web a better place to work and play.</p>",
51-
"<p>Tell your friends about the bug you just filed:</p>",
52-
'<a class="wc-Button wc-Button--action" href="https://twitter.com/intent/tweet?text=<%- encodeURIComponent("I just filed a bug on the internet:") %>&url=<%- encodeURIComponent("https://webcompat.com/issues/") %><%= number %>&via=webcompat" target="_blank">Share on Twitter</a>',
53-
'<a class="wc-Button wc-Button--action" href="https://facebook.com/sharer/sharer.php?u=<%- encodeURIComponent("https://webcompat.com/issues/") %><%= number %>" target="_blank">Share on Facebook</a>'
54-
].join("")
55-
);
56-
47+
var buildTemplate = wcTmpl["issue/thanks.jst"];
5748
this.$el.addClass("is-active wc-FlashMessage--thanks");
5849
this.$el
5950
.html(buildTemplate({ number: opts.message }))

webcompat/static/js/lib/issue-list.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ issueList.DropdownView = Backbone.View.extend({
3838
_.bind(this.selectDropdownOption, this)
3939
);
4040
},
41-
template: _.template($("#dropdown-tmpl").html()),
41+
template: wcTmpl["list-issue/dropdown.jst"],
4242
render: function() {
4343
this.$el.html(this.template(this.model.toJSON()));
4444
return this;
@@ -154,7 +154,7 @@ issueList.SearchView = Backbone.View.extend({
154154
issueList.events.on("search:clear", _.bind(this.clearSearchBox, this));
155155
issueList.events.on("search:current", _.bind(this.currentSearch, this));
156156
},
157-
template: _.template($("#issuelist-search-tmpl").html()),
157+
template: wcTmpl["list-issue/issuelist-search.jst"],
158158
render: function(cb) {
159159
this.$el.html(this.template());
160160
this.input = this.$el.find("input");
@@ -245,7 +245,7 @@ issueList.SortingView = Backbone.View.extend({
245245
model: this.sortModel
246246
});
247247
},
248-
template: _.template($("#issuelist-sorting-tmpl").html()),
248+
template: wcTmpl["list-issue/issuelist-sorting.jst"],
249249
render: function() {
250250
this.$el.html(this.template());
251251
this.paginationDropdown
@@ -290,7 +290,7 @@ issueList.IssueView = Backbone.View.extend(
290290
issuesPagination.initMixin(this, this.issues, $("main"));
291291
this.loadIssues();
292292
},
293-
template: _.template($("#issuelist-issue-tmpl").html()),
293+
template: wcTmpl["list-issue/issuelist-issue.jst"],
294294
loadIssues: function() {
295295
// Attemps to load model state from URL params, if present,
296296
// otherwise grab model defaults and load issues

webcompat/static/js/lib/issues.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ issues.MetaDataView = Backbone.View.extend({
100100
}, this)
101101
);
102102
},
103-
template: _.template($("#metadata-tmpl").html()),
103+
template: wcTmpl["issue/metadata.jst"],
104104
render: function() {
105105
this.$el.html(this.template(this.model.toJSON()));
106106
return this;
@@ -117,7 +117,7 @@ issues.AsideView = Backbone.View.extend({
117117
}, this)
118118
);
119119
},
120-
template: _.template($("#aside-tmpl").html()),
120+
template: wcTmpl["issue/aside.jst"],
121121
render: function() {
122122
this.$el.html(this.template(this.model.toJSON()));
123123
return this;
@@ -127,7 +127,7 @@ issues.AsideView = Backbone.View.extend({
127127
issues.BodyView = Backbone.View.extend({
128128
el: $(".wc-Issue-report"),
129129
mainView: null,
130-
template: _.template($("#issue-info-tmpl").html()),
130+
template: wcTmpl["issue/issue-report.jst"],
131131
initialize: function(options) {
132132
this.mainView = options.mainView;
133133
},
@@ -184,7 +184,7 @@ issues.ImageUploadView = Backbone.View.extend({
184184
},
185185
_submitButton: $(".js-Issue-comment-button"),
186186
_loaderImage: $(".js-Upload-Loader"),
187-
template: _.template($("#upload-input-tmpl").html()),
187+
template: wcTmpl["issue/upload-image.jst"],
188188
render: function() {
189189
this.$el.html(this.template()).insertAfter($("textarea"));
190190
return this;
@@ -352,7 +352,7 @@ issues.StateButtonView = Backbone.View.extend({
352352
}, this)
353353
);
354354
},
355-
template: _.template($("#state-button-tmpl").html()),
355+
template: wcTmpl["issue/state-button.jst"],
356356
render: function() {
357357
var buttonText;
358358
if (this.model.get("state") === "open") {

webcompat/static/js/lib/labels.js

+4-12
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,10 @@ issues.LabelsView = Backbone.View.extend({
3535
this.editLabels();
3636
}
3737
},
38-
template: _.template($("#issue-labels-tmpl").html()),
38+
template: wcTmpl["issue/issue-labels.jst"],
3939
// this subTemplate will need to be kept in sync with
40-
// relavant parts in $('#issue-labels-tmpl')
41-
subTemplate: _.template(
42-
[
43-
"<% _.each(labels, function(label) { %>",
44-
'<span class="wc-Label wc-Label--badge js-Label" style="background-color:#<%=label.color%>">',
45-
"<%= label.name %>",
46-
"</span>",
47-
"<% }); %>"
48-
].join("")
49-
),
40+
// relavant parts in issue/issue-labels.jst
41+
subTemplate: wcTmpl["issue/issue-labels-sub.jst"],
5042
render: function() {
5143
this.$el.html(this.template(this.model.toJSON()));
5244
this.fetchLabels();
@@ -105,7 +97,7 @@ issues.LabelEditorView = Backbone.View.extend({
10597
initialize: function(options) {
10698
this.issueView = options.issueView;
10799
},
108-
template: _.template($("#label-editor-tmpl").html()),
100+
template: wcTmpl["web_modules/label-editor.jst"],
109101
render: function() {
110102
this.$el.html(this.template(this.model));
111103
this.resizeEditorHeight();

webcompat/static/js/lib/user-activity.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ issueList.MyIssuesView = Backbone.View.extend(
3636
);
3737
this.fetchAndRenderIssues({ url: this.issues.url });
3838
},
39-
template: _.template($("#my-issues-tmpl").html()),
39+
template: wcTmpl["web_modules/issue-list.jst"],
4040
render: function() {
4141
this.$el.html(
4242
this.template({
43-
myIssues: this.issues.toJSON()
43+
issues: this.issues.toJSON()
4444
})
4545
);
4646

@@ -107,11 +107,11 @@ issueList.IssueMentionsView = Backbone.View.extend(
107107
);
108108
this.fetchAndRenderIssues({ url: this.issues.url });
109109
},
110-
template: _.template($("#issue-mentions-tmpl").html()),
110+
template: wcTmpl["web_modules/issue-list.jst"],
111111
render: function() {
112112
this.$el.html(
113113
this.template({
114-
issueMentions: this.issues.toJSON()
114+
issues: this.issues.toJSON()
115115
})
116116
);
117117
return this;

0 commit comments

Comments
 (0)