Skip to content

Commit

Permalink
Fix sanitization in log display
Browse files Browse the repository at this point in the history
  • Loading branch information
fonsp committed Oct 21, 2023
1 parent 329d430 commit 66f7041
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
13 changes: 9 additions & 4 deletions frontend/components/Cell.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ const on_jump = (hasBarrier, pluto_actions, cell_id) => () => {
* force_hide_input: boolean,
* focus_after_creation: boolean,
* process_waiting_for_permission: boolean,
* sanitze_html: boolean,
* sanitize_html: boolean,
* [key: string]: any,
* }} props
* */
Expand Down Expand Up @@ -139,8 +139,8 @@ export const Cell = ({

const remount = useMemo(() => () => setKey(key + 1))
// cm_forced_focus is null, except when a line needs to be highlighted because it is part of a stack trace
const [cm_forced_focus, set_cm_forced_focus] = useState(/** @type{any} */ (null))
const [cm_highlighted_range, set_cm_highlighted_range] = useState(null)
const [cm_forced_focus, set_cm_forced_focus] = useState(/** @type {any} */ (null))
const [cm_highlighted_range, set_cm_highlighted_range] = useState(/** @type {{from, to}?} */ (null))
const [cm_highlighted_line, set_cm_highlighted_line] = useState(null)
const [cm_diagnostics, set_cm_diagnostics] = useState([])

Expand Down Expand Up @@ -349,7 +349,12 @@ export const Cell = ({
onerror=${remount}
/>
${show_logs && cell_api_ready
? html`<${Logs} logs=${Object.values(logs)} line_heights=${line_heights} set_cm_highlighted_line=${set_cm_highlighted_line} />`
? html`<${Logs}
logs=${Object.values(logs)}
line_heights=${line_heights}
set_cm_highlighted_line=${set_cm_highlighted_line}
sanitize_html=${sanitize_html}
/>`
: null}
<${RunArea}
cell_id=${cell_id}
Expand Down
10 changes: 6 additions & 4 deletions frontend/components/Logs.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const is_stdout_log = (log) => {
return log.level == STDOUT_LOG_LEVEL
}

export const Logs = ({ logs, line_heights, set_cm_highlighted_line }) => {
export const Logs = ({ logs, line_heights, set_cm_highlighted_line, sanitize_html }) => {
const progress_logs = logs.filter(is_progress_log)
const latest_progress_logs = progress_logs.reduce((progress_logs, log) => ({ ...progress_logs, [log.id]: log }), {})
const stdout_log = logs.reduce((stdout_log, log) => {
Expand Down Expand Up @@ -63,6 +63,7 @@ export const Logs = ({ logs, line_heights, set_cm_highlighted_line }) => {
level=${log.level}
msg=${log.msg}
kwargs=${log.kwargs}
sanitize_html=${sanitize_html}
key=${i}
y=${is_hidden_input ? 0 : log.line - 1}
/> `
Expand Down Expand Up @@ -97,9 +98,7 @@ const Progress = ({ progress }) => {
return html`<pluto-progress-bar ref=${bar_ref}>${Math.ceil(100 * progress)}%</pluto-progress-bar>`
}

const mimepair_output = (pair) => html`<${SimpleOutputBody} cell_id=${"adsf"} mime=${pair[1]} body=${pair[0]} persist_js_state=${false} />`

const Dot = ({ set_cm_highlighted_line, msg, kwargs, y, level }) => {
const Dot = ({ set_cm_highlighted_line, msg, kwargs, y, level, sanitize_html }) => {
const is_progress = is_progress_log({ level, kwargs })
const is_stdout = level === STDOUT_LOG_LEVEL
let progress = null
Expand All @@ -119,6 +118,9 @@ const Dot = ({ set_cm_highlighted_line, msg, kwargs, y, level }) => {
level = "Stdout"
}

const mimepair_output = (pair) =>
html`<${SimpleOutputBody} cell_id=${"adsf"} mime=${pair[1]} body=${pair[0]} persist_js_state=${false} sanitize_html=${sanitize_html} />`

return html`<pluto-log-dot-positioner
class=${cl({ [level]: true })}
onMouseenter=${() => is_progress || set_cm_highlighted_line(y + 1)}
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/Popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const help_circle_icon = new URL("https://cdn.jsdelivr.net/gh/ionic-team/
* @typedef MiscPopupDetails
* @property {"info" | "warn"} type
* @property {import("../imports/Preact.js").ReactElement} body
* @property {HTMLElement} [source_element]
* @property {HTMLElement?} [source_element]
* @property {Boolean} [big]
*/

Expand Down

0 comments on commit 66f7041

Please sign in to comment.