Skip to content

fix(many): innerHTML is disabled by default #27029

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions BREAKING.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ This is a comprehensive list of the breaking changes introduced in the major ver
- [Textarea](#version-7x-textarea)
- [Toggle](#version-7x-toggle)
- [Virtual Scroll](#version-7x-virtual-scroll)
- [Config](#version-7x-config)
- [Types](#version-7x-types)
- [Overlay Attribute Interfaces](#version-7x-overlay-attribute-interfaces)
- [JavaScript Frameworks](#version-7x-javascript-frameworks)
Expand Down Expand Up @@ -297,6 +298,10 @@ Developers using the component will need to migrate to a virtual scroll solution

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`.

<h2 id="version-7x-config">Config</h2>

- `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.

<h2 id="version-7x-types">Types</h2>

<h4 id="version-7x-overlay-attribute-interfaces">Overlay Attribute Interfaces</h4>
Expand Down
4 changes: 2 additions & 2 deletions core/src/components/alert/test/alert.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import { Alert } from '../alert';
import { config } from '../../../global/config';

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

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

it('should allow for custom html', async () => {
Expand Down
6 changes: 6 additions & 0 deletions core/src/components/alert/test/basic/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@
</ion-app>

<script>
window.Ionic = {
config: {
innerHTMLTemplatesEnabled: true,
},
};

async function openAlert(opts) {
const alert = await alertController.create(opts);
await alert.present();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import { InfiniteScrollContent } from '../infinite-scroll-content';
import { config } from '../../../global/config';

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

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

it('should allow for custom html', async () => {
Expand Down
6 changes: 6 additions & 0 deletions core/src/components/loading/test/basic/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@
</ion-content>
</ion-app>
<script>
window.Ionic = {
config: {
innerHTMLTemplatesEnabled: true,
},
};

async function openLoading(opts) {
const loading = await loadingController.create(opts);
await loading.present();
Expand Down
4 changes: 2 additions & 2 deletions core/src/components/loading/test/loading.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import { Loading } from '../loading';
import { config } from '../../../global/config';

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

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

it('should allow for custom html', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ import { RefresherContent } from '../refresher-content';
import { config } from '../../../global/config';

describe('refresher-content: custom html', () => {
it('should allow for custom html by default', async () => {
it('should not allow for custom html by default', async () => {
const page = await newSpecPage({
components: [RefresherContent],
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>`,
});

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

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

it('should allow for custom html', async () => {
Expand Down
6 changes: 6 additions & 0 deletions core/src/components/toast/test/basic/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,12 @@
</ion-content>
</ion-app>
<script>
window.Ionic = {
config: {
innerHTMLTemplatesEnabled: true,
},
};

window.addEventListener('ionToastDidDismiss', function (e) {
console.log('didDismiss', e);
});
Expand Down
4 changes: 2 additions & 2 deletions core/src/components/toast/test/toast.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Toast } from '../toast';
import { config } from '../../../global/config';

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

it('should allow for custom html', async () => {
Expand Down
2 changes: 1 addition & 1 deletion core/src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,4 +249,4 @@ export const getMode = (): Mode => {
return 'md';
};

export const ENABLE_HTML_CONTENT_DEFAULT = true;
export const ENABLE_HTML_CONTENT_DEFAULT = false;