Skip to content

Commit

Permalink
fix(css-shim): replaced innerHTML with textContent (#1892)
Browse files Browse the repository at this point in the history
  • Loading branch information
sj0x55 authored and manucorporat committed Sep 26, 2019
1 parent b3ed8de commit 613c797
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 23 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ log.txt

.idea/
.vscode/
.history/
.sass-cache/
.versions/
node_modules/
Expand Down
8 changes: 4 additions & 4 deletions src/client/polyfills/css-shim/custom-style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ export class CustomStyle {

if (!baseScope.usesCssVars) {
// This component does not use (read) css variables
styleEl.innerHTML = cssText;
styleEl.textContent = cssText;

} else if (isScoped) {
// This component is dynamic: uses css var and is scoped
(styleEl as any)['s-sc'] = cssScopeId = `${baseScope.scopeId}-${this.count}`;
styleEl.innerHTML = '/*needs update*/';
styleEl.textContent = '/*needs update*/';
this.hostStyleMap.set(hostEl, styleEl);
this.hostScopeMap.set(hostEl, reScope(baseScope, cssScopeId));
this.count++;
Expand All @@ -65,7 +65,7 @@ export class CustomStyle {
// This component uses css vars, but it's no-encapsulation (global static)
baseScope.styleEl = styleEl;
if (!baseScope.usesCssVars) {
styleEl.innerHTML = executeTemplate(baseScope.template, {});
styleEl.textContent = executeTemplate(baseScope.template, {});
}
this.globalScopes.push(baseScope);
this.updateGlobal();
Expand All @@ -90,7 +90,7 @@ export class CustomStyle {
if (styleEl) {
const selectors = getActiveSelectors(hostEl, this.hostScopeMap, this.globalScopes);
const props = resolveValues(selectors);
styleEl.innerHTML = executeTemplate(scope.template, props);
styleEl.textContent = executeTemplate(scope.template, props);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/client/polyfills/css-shim/load-link-styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function addGlobalLink(doc: Document, globalScopes: CSSScope[], linkElm:
}
const styleEl = doc.createElement('style');
styleEl.setAttribute('data-styles', '');
styleEl.innerHTML = text;
styleEl.textContent = text;

addGlobalStyle(globalScopes, styleEl);
linkElm.parentNode.insertBefore(styleEl, linkElm);
Expand Down
4 changes: 2 additions & 2 deletions src/client/polyfills/css-shim/scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function parseCSS(original: string): CSSScope {
}

export function addGlobalStyle(globalScopes: CSSScope[], styleEl: HTMLStyleElement) {
const css = parseCSS(styleEl.innerHTML);
const css = parseCSS(styleEl.textContent);
css.styleEl = styleEl;
globalScopes.push(css);
}
Expand All @@ -27,7 +27,7 @@ export function updateGlobalScopes(scopes: CSSScope[]) {
const props = resolveValues(selectors);
scopes.forEach(scope => {
if (scope.usesCssVars) {
scope.styleEl.innerHTML = executeTemplate(scope.template, props);
scope.styleEl.textContent = executeTemplate(scope.template, props);
}
});
}
Expand Down
32 changes: 16 additions & 16 deletions src/client/polyfills/css-shim/test/css-shim.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('css-shim', () => {
`);
await customStyle.addGlobalStyle(styleElm);

expect(css(styleElm.innerHTML)).toBe(
expect(css(styleElm.textContent)).toBe(
css(`
p {
color: red;
Expand All @@ -47,7 +47,7 @@ describe('css-shim', () => {
`);
await customStyle.addGlobalStyle(styleElm);

expect(css(styleElm.innerHTML)).toBe(
expect(css(styleElm.textContent)).toBe(
css(`
p {
color: red;
Expand All @@ -70,7 +70,7 @@ describe('css-shim', () => {
`);
await customStyle.addGlobalStyle(styleElm);

expect(css(styleElm.innerHTML)).toBe(
expect(css(styleElm.textContent)).toBe(
css(`
html {
background: yellow;
Expand All @@ -94,7 +94,7 @@ describe('css-shim', () => {

await customStyle.addGlobalStyle(styleElm);

expect(css(styleElm.innerHTML)).toBe(
expect(css(styleElm.textContent)).toBe(
css(`
html {
color: green;
Expand All @@ -115,7 +115,7 @@ describe('css-shim', () => {

await customStyle.addGlobalStyle(styleElm);

expect(css(styleElm.innerHTML)).toBe(
expect(css(styleElm.textContent)).toBe(
css(`
html {
background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAAZdEVYdFNvZnR3YXJlAEFkb2JlIEltYWdlUmVhZHlxyWU8AAAHVElEQVRoQ92aW2yURRTHz24vu1B63V62LTWSAL2ILQFBASEF5WpQEwy1BIhGCAGDkUrKCw+Q8AAqwYSID2gCIkWJPhgSLuXWcAelBYWWAglRoO12u223F6B7aT3/2emypbvLfLtQwF/y5euc2W9mzpwzZ84M6HoY+h+gl+8XnidqkTNnztGxYxV08WIVXb9xg+7eqaMHDx6IOqPRSJlDM2jkiOE0duwYmjqtkCZNfEPUPRGgSDgcOXKsZ8477/NkRPBj7DEY4ntiY5N7EhLMPSZTRk9ycqZ48DdkqDPyb/BbfINv0Ua4hGyRXbv20MrPVpG9tYViY+PEjOt0OlmrBrqGxdrb2yg+PpG2bt1CixYVy1ptaFbk2rVamjp1JjU0WCgpKZEiIyNlTXi4XC5qbm6hNHMaVRw/RDk52bJGDU2LveSLNZSbm0NdXV2UmpryxJQAaAttOrht9FFSskbWqKFskYKC8XTlylUymZI0u5BWMKRmWzO9MiqPLl/+Q0qDo6RIamoW3bt3j2JiYqRkYOjs7KTBgwdTY+NtKQnMYxWBEliQgwYNkpKB5f79+2TgQGJ9jDJB10hBwThhiWelBEDf93kM+fnjpMQ/ARXBYrt6pXrA3ckfGEN1dTWtKimVkv74da2amlrKy8uhlJShT31hq4JhWq13WKEaEdUexa8iZvPL5HB0UVRUlJSogaZcLjf+8ggCouNwG6F5kpxOJ0VHR/Me9o+UPKSfa+38cTdHCYsmJdxut9jMrNYGDs+JlJ6ezpNh9vugDr+xWi3iG3yrCsbU2NhIO3f+JCUP6WcRzocoIkKvvNkhqrjd3bR9+7e0YMGHUqrGnj2/0NKlK0iv1ysHFGQAL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C8C1cnMLqL6+QXkhPi0QUNLTzVRTczngMSOgIsDW1EQjs/OF3xuNBikdWHDfhWBQW/uXSBID4V89SZLJRJcunRcLE7My0KBPKIExmHgswQiqCBYkbgGrq6uEaVtb7ZoDQCigD/SFPtE3xvC44BBUEQCfhEkvVZ2novnzOC2pF2HwaYG20cd87quK+0TfKsfvoGvEFyx+t9tFBw4coiVLVlBLS6vmzSwYvZtqQkI8/fD9dzR7zkxuO1L5DkFZkV6QHnRx0rZ16zb68qst1NHRSUOGxIi0JpS9Ae2hDVwLlZaW0MqVK0TSiva0oFkRAOs4ulghTjX27v1V/C+IkydPcVCIEgNARgBLIYfyBf/8gJmH+0ABl8tJkydPooULi6mo6AM+g3sUULWCLyEp0gsG5nI5yOlwig3r6LEKunDhT6qpvkb/3r4tzikOrgPR0VHikuGlrCzKzcuh8eNeo2lvFVICZ71RXBcZxYlqCAr0EpYivmCWe2cb7+5uXMRxRW/z7HbwPL0elorwWk1rPheIJ6aIP+CCvoTiMmoQ/Qfk2TCbSm2n3gAAAABJRU5ErkJggg==');
Expand All @@ -138,7 +138,7 @@ describe('css-shim', () => {
`);
await customStyle.addGlobalStyle(styleElm);

expect(css(styleElm.innerHTML)).toBe(
expect(css(styleElm.textContent)).toBe(
css(`
html {
background: yellow;
Expand All @@ -162,7 +162,7 @@ describe('css-shim', () => {

await customStyle.addGlobalStyle(styleElm);

expect(css(styleElm.innerHTML)).toBe(
expect(css(styleElm.textContent)).toBe(
css(`
html {
background-image: url('data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==');
Expand All @@ -182,7 +182,7 @@ describe('css-shim', () => {

await customStyle.addGlobalStyle(styleElm);

expect(css(styleElm.innerHTML)).toBe(
expect(css(styleElm.textContent)).toBe(

css(`
html {
Expand All @@ -204,7 +204,7 @@ describe('css-shim', () => {

await customStyle.addGlobalStyle(styleElm);

expect(css(styleElm.innerHTML)).toBe(
expect(css(styleElm.textContent)).toBe(

css(`
html {
Expand All @@ -229,7 +229,7 @@ describe('css-shim', () => {

await customStyle.addGlobalStyle(styleElm);

expect(css(styleElm.innerHTML)).toBe(
expect(css(styleElm.textContent)).toBe(
css(`
html{}
p {
Expand All @@ -252,7 +252,7 @@ describe('css-shim', () => {

await customStyle.addGlobalStyle(styleElm);

expect(css(styleElm.innerHTML)).toBe(
expect(css(styleElm.textContent)).toBe(
css(`
html {
color: red;
Expand All @@ -275,7 +275,7 @@ describe('css-shim', () => {

await customStyle.addGlobalStyle(styleElm);

expect(css(styleElm.innerHTML)).toBe(
expect(css(styleElm.textContent)).toBe(
css(`
html{}
.transform {
Expand All @@ -301,7 +301,7 @@ describe('css-shim', () => {

await customStyle.addGlobalStyle(styleElm);

expect(css(styleElm.innerHTML)).toBe(
expect(css(styleElm.textContent)).toBe(
css(`
html{}
@keyframes animation {
Expand All @@ -328,7 +328,7 @@ describe('css-shim', () => {

await customStyle.addGlobalStyle(styleElm);

expect(css(styleElm.innerHTML)).toBe(
expect(css(styleElm.textContent)).toBe(
css(`
html{}
@media only screen {
Expand Down Expand Up @@ -360,7 +360,7 @@ describe('css-shim', () => {

await customStyle.addGlobalStyle(styleElm);

expect(css(styleElm.innerHTML)).toBe(
expect(css(styleElm.textContent)).toBe(
css(`
html{}
div {
Expand All @@ -376,7 +376,7 @@ describe('css-shim', () => {

function style(text: string) {
const elm = document.createElement('style');
elm.innerHTML = text;
elm.textContent = text;
return elm;
}

Expand Down

0 comments on commit 613c797

Please sign in to comment.