Skip to content

Commit cba1193

Browse files
committed
Issue #2828 - Changes the concatenation from + to join
This was initially triggered by pycodestyle W504. It kinds of force you to choose your style in between W503 and W504. Breaking before binary operators or after. To avoid it altogether, I switched to ''.join() which is more effective anyway in performance. https://wiki.python.org/moin/PythonSpeed/PerformanceTips#String_Concatenation
1 parent acd93e2 commit cba1193

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

webcompat/helpers.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -501,19 +501,20 @@ def add_csp(response):
501501
This should be used in @app.after_request to ensure the header is
502502
added to all responses.
503503
"""
504-
response.headers['Content-Security-Policy'] = (
505-
"default-src 'self'; " +
506-
"object-src 'none'; " +
507-
"connect-src 'self' https://api.github.com; " +
508-
"font-src 'self' https://fonts.gstatic.com; " +
509-
get_img_src_policy() +
510-
"manifest-src 'self'; " +
511-
"script-src 'self' https://www.google-analytics.com https://api.github.com 'nonce-{nonce}'; ".format(nonce=request.nonce) + # noqa
512-
"style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; " +
513-
"base-uri 'self'; " +
514-
"frame-ancestors 'self'; " +
504+
csp_params = [
505+
"default-src 'self'; ",
506+
"object-src 'none'; ",
507+
"connect-src 'self' https://api.github.com; ",
508+
"font-src 'self' https://fonts.gstatic.com; ",
509+
get_img_src_policy(),
510+
"manifest-src 'self'; ",
511+
"script-src 'self' https://www.google-analytics.com https://api.github.com 'nonce-{nonce}'; ".format(nonce=request.nonce), # noqa
512+
"style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; ",
513+
"base-uri 'self'; ",
514+
"frame-ancestors 'self'; ",
515515
"report-uri /csp-report"
516-
)
516+
]
517+
response.headers['Content-Security-Policy'] = (''.join(csp_params))
517518

518519

519520
def cache_policy(private=True, uri_max_age=86400, must_revalidate=False):

0 commit comments

Comments
 (0)