Skip to content

Commit 2518966

Browse files
kotogkalpak
authored andcommitted
fix(grunt-utils): insert the core CSS styles without using innerHTML
Create style elements and modify their text content instead of using innerHTML to create the whole `<style>` element with its content. That way style insertion done at bootstrap time doesn't interfere with Trusted Types restrictions in Chrome (https://bit.ly/trusted-types). Remove the type attribute - `text/css` is default: https://html.spec.whatwg.org/#update-a-style-block. Closes angular#17014
1 parent 7de25c8 commit 2518966

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/grunt/utils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ module.exports = {
111111
.replace(/\\/g, '\\\\')
112112
.replace(/'/g, '\\\'')
113113
.replace(/\r?\n/g, '\\n');
114-
js = '!window.angular.$$csp().noInlineStyle && window.angular.element(document.head).prepend(\'<style type="text/css">' + css + '</style>\');';
114+
js = '!window.angular.$$csp().noInlineStyle && window.angular.element(document.head).prepend(window.angular.element(\'<style>\').text(\'' + css + '\'));';
115115
state.js.push(js);
116116

117117
return state;

test/e2e/tests/sample.spec.js

+9
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,13 @@ describe('Sample', function() {
99
it('should have the interpolated text', function() {
1010
expect(element(by.binding('text')).getText()).toBe('Hello, world!');
1111
});
12+
13+
it('should insert the ng-cloak styles', function() {
14+
browser.executeScript(`
15+
var span = document.createElement('span');
16+
span.className = 'ng-cloak foo';
17+
document.body.appendChild(span);
18+
`);
19+
expect(element(by.className('foo')).isDisplayed()).toBe(false);
20+
});
1221
});

0 commit comments

Comments
 (0)