Page warnings log their line only, never words or source (M-11)

A document can forge both a console message and its source (KaTeX's
\errmessage, data: scripts, sourceURL, encoded paths), so the display
handler logs a line number and nothing the page wrote. The page's own
diagnostics reach the app over elyQuery: a missed reveal sends its
line; the visual failure and diagram lines already did. A test calls
the real handler and checks the captured log.

Round 5 found only the missing test; it is added and mutation-checked,
with no sixth review under the five-round cap. M-15 is new: the print
page runs a document's scripts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ZacharyZhang-NYandClaude Opus 5.5 committed 2026-10-10 13:02:06 -04:00
1 parent 4a2dcbb222
commit c5cb153f72
13 files changed
+101 -30

No files matched your search

+48 -6
View File
@@ -264,15 +264,13 @@ wrap_display_handler! {
&self,
_browser: Option<&mut Browser>,
level: LogSeverity,
message: Option<&CefString>,
source: Option<&CefString>,
_message: Option<&CefString>,
_source: Option<&CefString>,
line: ::std::os::raw::c_int,
) -> ::std::os::raw::c_int {
// A page's warnings and errors, never its other chatter.
// Words and sources a document may forge stay out.
if level.get_raw() >= LogSeverity::WARNING.get_raw() {
let said = message.map(CefString::to_string).unwrap_or_default();
let at = source.map(CefString::to_string).unwrap_or_default();
log::warn!("web: page says {said} at {at}:{line}");
log::warn!("web: the page warned at line {line}");
}
0
}
@@ -449,3 +447,47 @@ fn keys() -> Option<KeyboardHandler> {
fn keys() -> Option<KeyboardHandler> {
None
}
#[cfg(test)]
mod tests {
use std::sync::{Arc, Mutex, OnceLock};
use cef::{CefString, ImplDisplayHandler, LogSeverity};
struct Kept;
fn kept() -> &'static Mutex<Vec<String>> {
static KEPT: OnceLock<Mutex<Vec<String>>> = OnceLock::new();
KEPT.get_or_init(Mutex::default)
}
impl log::Log for Kept {
fn enabled(&self, _: &log::Metadata) -> bool {
true
}
fn log(&self, record: &log::Record) {
kept().lock().expect("the kept lock").push(record.args().to_string());
}
fn flush(&self) {}
}
#[test]
fn a_pages_words_and_sources_never_reach_the_log() {
log::set_boxed_logger(Box::new(Kept)).expect("the only logger");
log::set_max_level(log::LevelFilter::Trace);
let surface = crate::surface::Surface::new(std::env::temp_dir(), 1.0);
let display = super::Display::new(Arc::new(Mutex::new(surface)));
let said = CefString::from("ely: M11_SECRET");
let at = CefString::from("file:///content/M11_SECRET.js");
for level in [LogSeverity::WARNING, LogSeverity::ERROR, LogSeverity::INFO] {
display.on_console_message(None, level, Some(&said), Some(&at), 7);
}
let records = kept().lock().expect("the kept lock").clone();
let warned = records.iter().filter(|said| *said == "web: the page warned at line 7");
assert_eq!(warned.count(), 2, "warnings and errors stay seen: {records:#?}");
assert!(!records.iter().any(|said| said.contains("M11_SECRET")), "{records:#?}");
}
}