Skip to content
Open
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
8 changes: 4 additions & 4 deletions overlay/components/RuntimeErrorStack.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ function RuntimeErrorStack(document, root, props) {
errorStacks = ErrorStackParser.parse(props.error);
} catch (e) {
errorStacks = [];
stackContainer.innerHTML = 'No stack trace is available for this error!';
stackContainer.textContent = 'No stack trace is available for this error!';
}

for (let i = 0; i < Math.min(errorStacks.length, 10); i += 1) {
const currentStack = errorStacks[i];

const functionName = document.createElement('code');
functionName.innerHTML = `&emsp;${currentStack.functionName || '(anonymous function)'}`;
functionName.textContent = `\u2003${currentStack.functionName || '(anonymous function)'}`;
functionName.style.color = theme.yellow;
functionName.style.fontFamily = [
'"SFMono-Regular"',
Expand All @@ -52,8 +52,8 @@ function RuntimeErrorStack(document, root, props) {
].join(', ');

const fileName = document.createElement('div');
fileName.innerHTML =
'&emsp;&emsp;' +
fileName.textContent =
'\u2003\u2003' +
utils.formatFilename(currentStack.fileName) +
':' +
currentStack.lineNumber +
Expand Down
22 changes: 22 additions & 0 deletions test/overlay/components/RuntimeErrorStack.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* @jest-environment jsdom
*/
/* eslint-env browser */

const RuntimeErrorStack = require('../../../overlay/components/RuntimeErrorStack');

describe('RuntimeErrorStack', () => {
it('renders stack frame values as text', () => {
const root = document.createElement('div');
const error = new Error('Failed');
error.stack =
'Error: Failed\n at <img src=x onerror=alert(1)> (/tmp/<strong>file</strong>.js:1:2)';

RuntimeErrorStack(document, root, { error });

expect(root.querySelector('img')).toBeNull();
expect(root.querySelector('strong')).toBeNull();
expect(root.textContent).toContain('<img src=x onerror=alert(1)>');
expect(root.textContent).toContain('tmp/<strong>file</strong>.js:1:2');
});
});