Skip to content

Commit b7e4603

Browse files
authored
fix(many): innerHTML is disabled by default (#27029)
BREAKING CHANGE: The `innerHTMLTemplatesEnabled` Ionic Config now defaults to `false`. Developers can set this option to `true` if they would like to continue to use custom HTML features in `ion-alert`, `ion-infinite-scroll-content`, `ion-loading`, `ion-refresher-content`, and `ion-toast`.
1 parent b148384 commit b7e4603

File tree

10 files changed

+35
-12
lines changed

10 files changed

+35
-12
lines changed

BREAKING.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ This is a comprehensive list of the breaking changes introduced in the major ver
3535
- [Textarea](#version-7x-textarea)
3636
- [Toggle](#version-7x-toggle)
3737
- [Virtual Scroll](#version-7x-virtual-scroll)
38+
- [Config](#version-7x-config)
3839
- [Types](#version-7x-types)
3940
- [Overlay Attribute Interfaces](#version-7x-overlay-attribute-interfaces)
4041
- [JavaScript Frameworks](#version-7x-javascript-frameworks)
@@ -297,6 +298,10 @@ Developers using the component will need to migrate to a virtual scroll solution
297298

298299
Any references to the virtual scroll types from `@ionic/core` have been removed. Please remove or replace these types: `Cell`, `VirtualNode`, `CellType`, `NodeChange`, `HeaderFn`, `ItemHeightFn`, `FooterHeightFn`, `ItemRenderFn` and `DomRenderFn`.
299300

301+
<h2 id="version-7x-config">Config</h2>
302+
303+
- `innerHTMLTemplatesEnabled` defaults to `false`. Developers who wish to use the `innerHTML` functionality inside of `ion-alert`, `ion-infinite-scroll-content`, `ion-loading`, `ion-refresher-content`, and `ion-toast` must set this config to `true` and properly sanitize their content.
304+
300305
<h2 id="version-7x-types">Types</h2>
301306

302307
<h4 id="version-7x-overlay-attribute-interfaces">Overlay Attribute Interfaces</h4>

core/src/components/alert/test/alert.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ import { Alert } from '../alert';
33
import { config } from '../../../global/config';
44

55
describe('alert: custom html', () => {
6-
it('should allow for custom html by default', async () => {
6+
it('should not allow for custom html by default', async () => {
77
const page = await newSpecPage({
88
components: [Alert],
99
html: `<ion-alert message="<button class='custom-html'>Custom Text</button>"></ion-alert>`,
1010
});
1111

1212
const content = page.body.querySelector('.alert-message');
1313
expect(content.textContent).toContain('Custom Text');
14-
expect(content.querySelector('button.custom-html')).not.toBe(null);
14+
expect(content.querySelector('button.custom-html')).toBe(null);
1515
});
1616

1717
it('should allow for custom html', async () => {

core/src/components/alert/test/basic/index.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@
5858
</ion-app>
5959

6060
<script>
61+
window.Ionic = {
62+
config: {
63+
innerHTMLTemplatesEnabled: true,
64+
},
65+
};
66+
6167
async function openAlert(opts) {
6268
const alert = await alertController.create(opts);
6369
await alert.present();

core/src/components/infinite-scroll-content/test/infinite-scroll-content.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ import { InfiniteScrollContent } from '../infinite-scroll-content';
33
import { config } from '../../../global/config';
44

55
describe('infinite-scroll-content: custom html', () => {
6-
it('should allow for custom html by default', async () => {
6+
it('should not allow for custom html by default', async () => {
77
const page = await newSpecPage({
88
components: [InfiniteScrollContent],
99
html: `<ion-infinite-scroll-content loading-text="<button class='custom-html'>Custom Text</button>"></ion-infinite-scroll-content>`,
1010
});
1111

1212
const content = page.body.querySelector('.infinite-loading-text');
1313
expect(content.textContent).toContain('Custom Text');
14-
expect(content.querySelector('button.custom-html')).not.toBe(null);
14+
expect(content.querySelector('button.custom-html')).toBe(null);
1515
});
1616

1717
it('should allow for custom html', async () => {

core/src/components/loading/test/basic/index.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@
100100
</ion-content>
101101
</ion-app>
102102
<script>
103+
window.Ionic = {
104+
config: {
105+
innerHTMLTemplatesEnabled: true,
106+
},
107+
};
108+
103109
async function openLoading(opts) {
104110
const loading = await loadingController.create(opts);
105111
await loading.present();

core/src/components/loading/test/loading.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ import { Loading } from '../loading';
33
import { config } from '../../../global/config';
44

55
describe('alert: custom html', () => {
6-
it('should allow for custom html by default', async () => {
6+
it('should not allow for custom html by default', async () => {
77
const page = await newSpecPage({
88
components: [Loading],
99
html: `<ion-loading message="<button class='custom-html'>Custom Text</button>"></ion-loading>`,
1010
});
1111

1212
const content = page.body.querySelector('.loading-content');
1313
expect(content.textContent).toContain('Custom Text');
14-
expect(content.querySelector('button.custom-html')).not.toBe(null);
14+
expect(content.querySelector('button.custom-html')).toBe(null);
1515
});
1616

1717
it('should allow for custom html', async () => {

core/src/components/refresher-content/test/refresher-content.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ import { RefresherContent } from '../refresher-content';
33
import { config } from '../../../global/config';
44

55
describe('refresher-content: custom html', () => {
6-
it('should allow for custom html by default', async () => {
6+
it('should not allow for custom html by default', async () => {
77
const page = await newSpecPage({
88
components: [RefresherContent],
99
html: `<ion-refresher-content pulling-text="<button class='custom-pulling-html'>Custom Pulling Text</button>" refreshing-text="<button class='custom-refreshing-html'>Custom Refreshing Text</button>"></ion-refresher-content>`,
1010
});
1111

1212
const pullingContent = page.body.querySelector('.refresher-pulling-text');
1313
expect(pullingContent.textContent).toContain('Custom Pulling Text');
14-
expect(pullingContent.querySelector('button.custom-pulling-html')).not.toBe(null);
14+
expect(pullingContent.querySelector('button.custom-pulling-html')).toBe(null);
1515

1616
const refreshingContent = page.body.querySelector('.refresher-refreshing-text');
1717
expect(refreshingContent.textContent).toContain('Custom Refreshing Text');
18-
expect(refreshingContent.querySelector('button.custom-refreshing-html')).not.toBe(null);
18+
expect(refreshingContent.querySelector('button.custom-refreshing-html')).toBe(null);
1919
});
2020

2121
it('should allow for custom html', async () => {

core/src/components/toast/test/basic/index.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,12 @@
195195
</ion-content>
196196
</ion-app>
197197
<script>
198+
window.Ionic = {
199+
config: {
200+
innerHTMLTemplatesEnabled: true,
201+
},
202+
};
203+
198204
window.addEventListener('ionToastDidDismiss', function (e) {
199205
console.log('didDismiss', e);
200206
});

core/src/components/toast/test/toast.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Toast } from '../toast';
33
import { config } from '../../../global/config';
44

55
describe('alert: custom html', () => {
6-
it('should allow for custom html by default', async () => {
6+
it('should not allow for custom html by default', async () => {
77
const page = await newSpecPage({
88
components: [Toast],
99
html: `<ion-toast message="<button class='custom-html'>Custom Text</button>"></ion-toast>`,
@@ -12,7 +12,7 @@ describe('alert: custom html', () => {
1212
const toast = page.body.querySelector('ion-toast');
1313
const content = toast.shadowRoot.querySelector('.toast-message');
1414
expect(content.textContent).toContain('Custom Text');
15-
expect(content.querySelector('button.custom-html')).not.toBe(null);
15+
expect(content.querySelector('button.custom-html')).toBe(null);
1616
});
1717

1818
it('should allow for custom html', async () => {

core/src/utils/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,4 +249,4 @@ export const getMode = (): Mode => {
249249
return 'md';
250250
};
251251

252-
export const ENABLE_HTML_CONTENT_DEFAULT = true;
252+
export const ENABLE_HTML_CONTENT_DEFAULT = false;

0 commit comments

Comments
 (0)