Skip to content

Commit c9e6045

Browse files
authored
Merge branch 'master' into No-GC-For-Staff
2 parents fcb635c + fe360ae commit c9e6045

File tree

17 files changed

+55
-19
lines changed

17 files changed

+55
-19
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"array-move": "^4.0.0",
4848
"browserfs": "^1.4.3",
4949
"classnames": "^2.3.2",
50+
"dompurify": "^3.1.6",
5051
"flexboxgrid": "^6.3.1",
5152
"flexboxgrid-helpers": "^1.1.3",
5253
"hastscript": "^9.0.0",
@@ -109,6 +110,7 @@
109110
"@testing-library/jest-dom": "^6.0.0",
110111
"@testing-library/react": "^14.0.0",
111112
"@testing-library/user-event": "^14.4.3",
113+
"@types/dompurify": "^3.0.5",
112114
"@types/estree": "^1.0.5",
113115
"@types/gapi": "^0.0.44",
114116
"@types/gapi.auth2": "^0.0.57",

src/commons/Markdown.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Classes } from '@blueprintjs/core';
22
import classNames from 'classnames';
3+
import DOMPurify from 'dompurify';
34
import React from 'react';
45
import { Converter } from 'showdown';
56

@@ -24,7 +25,12 @@ const Markdown: React.FC<Props> = props => {
2425
return (
2526
<div
2627
className={classNames(props.className ? props.className : 'md', Classes.RUNNING_TEXT)}
27-
dangerouslySetInnerHTML={{ __html: converter.makeHtml(props.content) }}
28+
dangerouslySetInnerHTML={{
29+
__html: DOMPurify.sanitize(converter.makeHtml(props.content), {
30+
USE_PROFILES: { html: true },
31+
ADD_ATTR: ['target']
32+
})
33+
}}
2834
/>
2935
);
3036
};

src/commons/__tests__/__snapshots__/Markdown.tsx.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ exports[`Markdown page renders correctly 1`] = `
66
dangerouslySetInnerHTML={
77
Object {
88
"__html": "<p>Welcome to the Source Academy playground!</p>
9-
<p>The book <a href=\\"https://sourceacademy.org/sicpjs/\\" rel=\\"noopener noreferrer\\" target=\\"_blank\\"><em>Structure and Interpretation of Computer Programs, JavaScript Edition</em></a>
10-
uses JavaScript sublanguages that we call <a href=\\"https://docs.sourceacademy.org/\\" rel=\\"noopener noreferrer\\" target=\\"_blank\\"><em>Source</em></a>. You have chosen the sublanguage <a href=\\"https://docs.sourceacademy.org/source_1/\\" rel=\\"noopener noreferrer\\" target=\\"_blank\\"><em>Source §1</em></a>.</p>
11-
<p>In the editor on the left, you can use the <a href=\\"https://github.com/ajaxorg/ace/wiki/Default-Keyboard-Shortcuts\\" rel=\\"noopener noreferrer\\" target=\\"_blank\\"><em>Ace keyboard shortcuts</em></a>
12-
and also the <a href=\\"https://github.com/source-academy/frontend/wiki/Source-Academy-Keyboard-Shortcuts\\" rel=\\"noopener noreferrer\\" target=\\"_blank\\"><em>Source Academy keyboard shortcuts</em></a>.</p>",
9+
<p>The book <a target=\\"_blank\\" rel=\\"noopener noreferrer\\" href=\\"https://sourceacademy.org/sicpjs/\\"><em>Structure and Interpretation of Computer Programs, JavaScript Edition</em></a>
10+
uses JavaScript sublanguages that we call <a target=\\"_blank\\" rel=\\"noopener noreferrer\\" href=\\"https://docs.sourceacademy.org/\\"><em>Source</em></a>. You have chosen the sublanguage <a target=\\"_blank\\" rel=\\"noopener noreferrer\\" href=\\"https://docs.sourceacademy.org/source_1/\\"><em>Source §1</em></a>.</p>
11+
<p>In the editor on the left, you can use the <a target=\\"_blank\\" rel=\\"noopener noreferrer\\" href=\\"https://github.com/ajaxorg/ace/wiki/Default-Keyboard-Shortcuts\\"><em>Ace keyboard shortcuts</em></a>
12+
and also the <a target=\\"_blank\\" rel=\\"noopener noreferrer\\" href=\\"https://github.com/source-academy/frontend/wiki/Source-Academy-Keyboard-Shortcuts\\"><em>Source Academy keyboard shortcuts</em></a>.</p>",
1313
}
1414
}
1515
/>

src/commons/assessment/__tests__/Assessment.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Store } from '@reduxjs/toolkit';
2-
import { act, render, screen } from '@testing-library/react';
2+
import { render, screen } from '@testing-library/react';
3+
import { act } from 'react';
34
import { Provider } from 'react-redux';
45
import { createMemoryRouter, RouterProvider } from 'react-router';
56
import { OverallState, Role } from 'src/commons/application/ApplicationTypes';

src/commons/assessmentWorkspace/__tests__/AssessmentWorkspace.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { act, render, screen } from '@testing-library/react';
1+
import { render, screen } from '@testing-library/react';
2+
import { act } from 'react';
23
import { Provider } from 'react-redux';
34
import { createMemoryRouter, RouterProvider } from 'react-router';
45
import { mockInitialStore } from 'src/commons/mocks/StoreMocks';

src/commons/gitHubOverlay/__tests__/FileExplorerDialog.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Octokit } from '@octokit/rest';
2-
import { act, fireEvent, render, screen, waitFor } from '@testing-library/react';
2+
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
3+
import { act } from 'react';
34

45
import * as GitHubUtils from '../../../features/github/GitHubUtils';
56
import FileExplorerDialog from '../FileExplorerDialog';

src/commons/gitHubOverlay/__tests__/RepositoryDialog.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { act, fireEvent, render, screen } from '@testing-library/react';
1+
import { fireEvent, render, screen } from '@testing-library/react';
2+
import { act } from 'react';
23

34
import * as NotificationHelper from '../../utils/notifications/NotificationsHelper';
45
import RepositoryDialog from '../RepositoryDialog';

src/commons/profile/__tests__/Profile.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { act, render, screen } from '@testing-library/react';
1+
import { render, screen } from '@testing-library/react';
2+
import { act } from 'react';
23
import { Provider } from 'react-redux';
34
import { MemoryRouter } from 'react-router';
45
import { OverallState, Role } from 'src/commons/application/ApplicationTypes';

src/commons/sideContent/__tests__/SideContentAutograder.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { act, render, screen } from '@testing-library/react';
1+
import { render, screen } from '@testing-library/react';
22
import { ErrorSeverity, ErrorType, SourceError } from 'js-slang/dist/types';
3+
import { act } from 'react';
34
import { shallowRender } from 'src/commons/utils/TestUtils';
45

56
import { AutogradingResult, Testcase, TestcaseTypes } from '../../assessment/AssessmentTypes';

src/commons/sideContent/__tests__/SideContentContestLeaderboard.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { act, render, screen } from '@testing-library/react';
1+
import { render, screen } from '@testing-library/react';
22
import userEvent from '@testing-library/user-event';
3+
import { act } from 'react';
34
import { shallowRender } from 'src/commons/utils/TestUtils';
45

56
import SideContentContestLeaderboard from '../content/SideContentContestLeaderboard';

0 commit comments

Comments
 (0)