Skip to content

Commit 72f4a14

Browse files
committed
Escape line number in HTML
1 parent 03be1c4 commit 72f4a14

File tree

2 files changed

+11
-10
lines changed
  • packages/app/src/app

2 files changed

+11
-10
lines changed

packages/app/src/app/components/Preview/DevTools/Tests/TestDetails/ErrorDetails/index.tsx

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import styled from 'styled-components';
33
import theme from '@codesandbox/common/lib/theme';
44
import ansiHTML from 'ansi-html';
55

6+
import { escapeHtml } from 'app/utils/escape';
7+
68
import { TestError } from '../../';
79

810
const Container = styled.div`
@@ -22,15 +24,6 @@ const Container = styled.div`
2224
}
2325
`;
2426

25-
function escapeHtml(unsafe) {
26-
return unsafe
27-
.replace(/&/g, '&')
28-
.replace(/</g, '&lt;')
29-
.replace(/>/g, '&gt;')
30-
.replace(/"/g, '&quot;')
31-
.replace(/'/g, '&#039;');
32-
}
33-
3427
const formatDiffMessage = (error: TestError, path: string) => {
3528
let finalMessage: string = '';
3629
if (error.matcherResult) {
@@ -92,7 +85,7 @@ const formatDiffMessage = (error: TestError, path: string) => {
9285
? `<span style="color:${theme.red()};">></span> `
9386
: '') +
9487
newMargin.join('') +
95-
code.lineNumber +
88+
escapeHtml('' + code.lineNumber) +
9689
' | ' +
9790
escapeHtml(code.content) +
9891
'</div>';
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export function escapeHtml(unsafe: string) {
2+
return unsafe
3+
.replace(/&/g, '&amp;')
4+
.replace(/</g, '&lt;')
5+
.replace(/>/g, '&gt;')
6+
.replace(/"/g, '&quot;')
7+
.replace(/'/g, '&#039;');
8+
}

0 commit comments

Comments
 (0)