-
Notifications
You must be signed in to change notification settings - Fork 27.5k
Conversation
Thanks for the PR!
If you need to make changes to your pull request, you can update the commit with Thanks again for your help! |
@@ -70,12 +71,17 @@ module.exports = { | |||
|
|||
|
|||
addStyle: function(src, styles, minify){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would change the addStyle
function to this:
addStyle: function(src, styles, minify) {
return styles.reduce(function(result, file) {
var css = fs.readFileSync(file).toString();
result.concatenatedCss += css + '\n';
result.js += processCSS(css, minify);
return result;
}, {js: src, concatenatedCss: ''});
function processCSS(css, minify) {
// minify
css = css
.replace(/\r?\n/g, '')
.replace(/\/\*.*?\*\//g, '')
.replace(/:\s+/g, ':')
.replace(/\s*\{\s*/g, '{')
.replace(/\s*\}\s*/g, '}')
.replace(/\s*\,\s*/g, ',')
.replace(/\s*\;\s*/g, ';');
// escape for JS
css = css
.replace(/\\/g, '\\\\')
.replace(/'/g, "\\'")
.replace(/\r?\n/g, '\\n');
return "if (!document.securityPolicy || !document.securityPolicy.isActive) { angular.element(document).find('head').prepend('<style type=\"text/css\">" + css + "</style>'); }";
}
},
LGTM |
@vojtajina Thanks for the review. Actually tested the condition
This shows warnings in the javascript console regarding csp, and when I check |
Here is an idea for another solution, as checking
Integrating this with the @IgorMinar What do you think about this? |
I created #4444 which fixes some of the issues also addressed in this PR. I think that we should merge #4444 first as it fixes a more general issue with CSP and then rebase this PR on top of master and get it in. The only colision should be in the grunt file which constructs the javascript string that injects the stylesheet. |
@@ -91,7 +97,7 @@ module.exports = { | |||
.replace(/\\/g, '\\\\') | |||
.replace(/'/g, "\\'") | |||
.replace(/\r?\n/g, '\\n'); | |||
return "angular.element(document).find('head').prepend('<style type=\"text/css\">" + css + "</style>');"; | |||
return "if (!document.securityPolicy || !document.securityPolicy.isActive) { angular.element(document).find('head').prepend('<style type=\"text/css\">" + css + "</style>'); }"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made some changes that will make the changes on this line obsolte. see #4444
Also add `angular-csp.css` to the resulting build.
Refactored according to @vojtajina idea using reduce, a little differently though:
|
When we refactored , we broke the csp mode because the previous implementation relied on the fact that it was ok to lazy initialize the .csp property, this is not the case any more. Besides, we need to know about csp mode during bootstrap and avoid injecting the stylesheet when csp is active, so I refactored the code to fix both issues. PR angular#4411 will follow up on this commit and add more improvements. Closes angular#917 Closes angular#2963 Closes angular#4394 Closes angular#4444 BREAKING CHANGE: triggering ngCsp directive via `ng:csp` attribute is not supported any more. Please use data-ng-csp instead.
When we refactored , we broke the csp mode because the previous implementation relied on the fact that it was ok to lazy initialize the .csp property, this is not the case any more. Besides, we need to know about csp mode during bootstrap and avoid injecting the stylesheet when csp is active, so I refactored the code to fix both issues. PR #4411 will follow up on this commit and add more improvements. Closes #917 Closes #2963 Closes #4394 Closes #4444 BREAKING CHANGE: triggering ngCsp directive via `ng:csp` attribute is not supported any more. Please use data-ng-csp instead.
landed as a86cf20 |
When we refactored , we broke the csp mode because the previous implementation relied on the fact that it was ok to lazy initialize the .csp property, this is not the case any more. Besides, we need to know about csp mode during bootstrap and avoid injecting the stylesheet when csp is active, so I refactored the code to fix both issues. PR angular#4411 will follow up on this commit and add more improvements. Closes angular#917 Closes angular#2963 Closes angular#4394 Closes angular#4444 BREAKING CHANGE: triggering ngCsp directive via `ng:csp` attribute is not supported any more. Please use data-ng-csp instead.
When we refactored , we broke the csp mode because the previous implementation relied on the fact that it was ok to lazy initialize the .csp property, this is not the case any more. Besides, we need to know about csp mode during bootstrap and avoid injecting the stylesheet when csp is active, so I refactored the code to fix both issues. PR angular#4411 will follow up on this commit and add more improvements. Closes angular#917 Closes angular#2963 Closes angular#4394 Closes angular#4444 BREAKING CHANGE: triggering ngCsp directive via `ng:csp` attribute is not supported any more. Please use data-ng-csp instead.
Also add
angular-csp.css
to the resulting build.