Skip to content
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- [Browser Support](#-browser-support)
- [Pull Request Steps](#-pull-request-steps)
- [Contributing](#-contributing)
- [Dependencies](#-dependencies)
- [TOAST UI Family](#-toast-ui-family)
- [Used By](#-used-by)
- [License](#-license)
Expand Down Expand Up @@ -184,6 +185,10 @@ For more information on PR's steps, please see links in the Contributing section
- [Commit convention](https://github.com/nhn/tui.grid/blob/master/docs/COMMIT_MESSAGE_CONVENTION.md)
- [Issue guideline](https://github.com/nhn/tui.grid/tree/master/.github/ISSUE_TEMPLATE)

## 🔩 Dependencies

* [DOMPurify](https://github.com/cure53/DOMPurify)

## 🍞 TOAST UI Family

- [TOAST UI Calendar](https://github.com/nhn/tui.calendar)
Expand Down
13 changes: 13 additions & 0 deletions packages/toast-ui.grid/cypress/integration/renderer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,16 @@ it('should apply the options to default renderer', () => {
.should('have.attr', 'myCustom', 'my-custom')
.should('have.attr', 'title', 'my Lee');
});

it('should render data to plain text in default renderer', () => {
const data = [{ tag: '<img src="" onerror="alert(123)" />' }];
const columns = [
{
name: 'tag',
},
];

cy.createGrid({ data, columns });

cy.getByCls('cell-content').invoke('html').should('to.eq', '<img src="">');
});
20 changes: 20 additions & 0 deletions packages/toast-ui.grid/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions packages/toast-ui.grid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"@storybook/addon-notes": "^5.3.19",
"@storybook/html": "^5.3.19",
"@toast-ui/select-box": "^1.0.0",
"@types/dompurify": "^2.3.3",
"@types/node": "^12.0.0",
"@types/webpack-env": "^1.13.8",
"@typescript-eslint/eslint-plugin": "^2.9.0",
Expand Down Expand Up @@ -81,6 +82,7 @@
"webpack-merge": "^4.2.1"
},
"dependencies": {
"dompurify": "^2.3.9",
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

종속성이 추가됬다고 문서에 추가하지 않아도 될까요?

"tui-date-picker": "^4.1.0",
"tui-pagination": "^3.4.0",
"xlsx": "^0.17.1"
Expand Down
3 changes: 2 additions & 1 deletion packages/toast-ui.grid/src/renderer/default.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { CellRenderer, CellRendererProps } from '@t/renderer';
import { cls } from '../helper/dom';
import { isFunction } from '../helper/common';
import { sanitize } from 'dompurify';

type IfEquals<X, Y, A = X, B = never> = (<T>() => T extends X ? 0 : 1) extends <T>() => T extends Y
? 0
Expand Down Expand Up @@ -69,6 +70,6 @@ export class DefaultRenderer implements CellRenderer {
}

public render(props: CellRendererProps) {
this.el.innerHTML = `${props.formattedValue}`;
this.el.innerHTML = sanitize(`${props.formattedValue}`);
}
}
4 changes: 3 additions & 1 deletion packages/toast-ui.grid/src/view/clipboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { getText } from '../query/clipboard';
import { convertTextToData } from '../helper/common';
import GridEvent from '../event/gridEvent';
import { getEventBus, EventBus } from '../event/eventBus';
import { sanitize } from 'dompurify';

interface StoreProps {
navigating: boolean;
Expand Down Expand Up @@ -111,7 +112,8 @@ class ClipboardComp extends Component<Props> {
}

const { el } = this;
const html = clipboardData.getData('text/html');
const html = sanitize(clipboardData.getData('text/html'));

let data;
if (html && html.indexOf('table') !== -1) {
// step 1: Append copied data on contenteditable element to parsing correctly table data.
Expand Down