Skip to content

Commit 6d7204a

Browse files
authored
Santizie arguments in logger (exercism#7871)
1 parent a0829a4 commit 6d7204a

File tree

1 file changed

+20
-9
lines changed
  • app/javascript/components/bootcamp/FrontendExercisePage/utils

1 file changed

+20
-9
lines changed

app/javascript/components/bootcamp/FrontendExercisePage/utils/updateIFrame.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,28 @@ export const scriptPrelude = `window.onerror = function(message, source, lineno,
99
}, '*');
1010
};
1111
12-
window.log = function(...args) {
13-
14-
const safeArgs = args.map(arg => {
15-
if (arg instanceof HTMLCollection || arg instanceof NodeList) {
16-
return Array.from(arg).map(el => el.outerHTML || String(el));
12+
window.log = function (...args) {
13+
function sanitize(value) {
14+
if (value instanceof HTMLCollection || value instanceof NodeList) {
15+
return Array.from(value).map(sanitize);
16+
}
17+
if (value instanceof Element) {
18+
return value.outerHTML;
19+
}
20+
if (Array.isArray(value)) {
21+
return value.map(sanitize);
1722
}
18-
if (arg instanceof Element) {
19-
return arg.outerHTML;
23+
if (value && typeof value === 'object') {
24+
const safeObj = {};
25+
for (const key in value) {
26+
safeObj[key] = sanitize(value[key]);
27+
}
28+
return safeObj;
2029
}
21-
return arg;
22-
});
30+
return value;
31+
}
32+
33+
const safeArgs = args.map(sanitize);
2334
2435
window.parent.postMessage({
2536
type: 'iframe-log',

0 commit comments

Comments
 (0)