Skip to content

Commit

Permalink
UIREQ-1080: Only certain HTML tags should be rendered when displaying…
Browse files Browse the repository at this point in the history
… staff slips
  • Loading branch information
Dmitriy-Litvinenko committed Mar 21, 2024
1 parent 0579553 commit b7250db
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change history for ui-requests

## [9.0.2] in progress

* Only certain HTML tags should be rendered when displaying staff slips. Refs UIREQ-1080.

## [9.0.1](https://github.com/folio-org/ui-requests/tree/v9.0.1) (2023-12-04)
[Full Changelog](https://github.com/folio-org/ui-requests/compare/v9.0.0...v9.0.1)

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@
"regenerator-runtime": "^0.13.9"
},
"dependencies": {
"dompurify": "^3.0.9",
"final-form": "^4.20.7",
"html-to-react": "^1.3.3",
"lodash": "^4.17.4",
Expand Down
5 changes: 3 additions & 2 deletions src/components/ComponentToPrint/ComponentToPrint.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from 'react';
import PropTypes from 'prop-types';
import HtmlToReact, { Parser } from 'html-to-react';
import Barcode from 'react-barcode';
import HtmlToReact, { Parser } from 'html-to-react';
import { sanitize } from 'dompurify';

const processNodeDefinitions = new HtmlToReact.ProcessNodeDefinitions(React);
const rules = [
Expand All @@ -19,7 +20,7 @@ const rules = [
const parser = new Parser();

const ComponentToPrint = ({ dataSource, templateFn }) => {
const componentStr = templateFn(dataSource);
const componentStr = sanitize(templateFn(dataSource));
const Component = parser.parseWithInstructions(componentStr, () => true, rules) || null;

return Component;
Expand Down
3 changes: 3 additions & 0 deletions src/components/ComponentToPrint/ComponentToPrint.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ const testIds = {
jest.mock('react-barcode', () => {
return jest.fn().mockImplementation(() => <div data-testid={testIds.barcode} />);
});
jest.mock('dompurify', () => ({
sanitize: jest.fn((data) => (data)),
}));

describe('ComponentToPrint', () => {
const templateFnMock = jest.fn();
Expand Down
4 changes: 3 additions & 1 deletion src/routes/RequestsRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
FormattedMessage,
injectIntl,
} from 'react-intl';
import { sanitize } from 'dompurify';

import {
AppIcon,
stripesConnect,
Expand Down Expand Up @@ -1000,7 +1002,7 @@ class RequestsRoute extends React.Component {
getPrintTemplate() {
const staffSlips = get(this.props.resources, 'staffSlips.records', []);
const pickSlip = staffSlips.find(slip => slip.name.toLowerCase() === pickSlipType);
return get(pickSlip, 'template', '');
return sanitize(get(pickSlip, 'template', ''));
}

handleFilterChange = ({ name, values }) => {
Expand Down

0 comments on commit b7250db

Please sign in to comment.