Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 745bb51

Browse files
committed
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.
1 parent 418355f commit 745bb51

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/grunt/utils.js

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

116116
return state;

test/e2e/tests/sample.spec.js

+8
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,12 @@ 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+
expect(element(by.className('foo')).isDisplayed()).toBe(false);
19+
});
1220
});

0 commit comments

Comments
 (0)