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 #17014
This commit is contained in:
Krzysztof Kotowicz
2020-05-24 20:09:21 +03:00
committed by George Kalpakas
parent 7de25c8e41
commit 2518966153
2 changed files with 10 additions and 1 deletions
+1 -1
View File
@@ -111,7 +111,7 @@ module.exports = {
.replace(/\\/g, '\\\\')
.replace(/'/g, '\\\'')
.replace(/\r?\n/g, '\\n');
js = '!window.angular.$$csp().noInlineStyle && window.angular.element(document.head).prepend(\'<style type="text/css">' + css + '</style>\');';
js = '!window.angular.$$csp().noInlineStyle && window.angular.element(document.head).prepend(window.angular.element(\'<style>\').text(\'' + css + '\'));';
state.js.push(js);
return state;
+9
View File
@@ -9,4 +9,13 @@ describe('Sample', function() {
it('should have the interpolated text', function() {
expect(element(by.binding('text')).getText()).toBe('Hello, world!');
});
it('should insert the ng-cloak styles', function() {
browser.executeScript(`
var span = document.createElement('span');
span.className = 'ng-cloak foo';
document.body.appendChild(span);
`);
expect(element(by.className('foo')).isDisplayed()).toBe(false);
});
});