diff --git a/Cargo.toml b/Cargo.toml index a74c763..1aaca4a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,7 @@ crate-type = ["cdylib", "rlib"] js-sys = "0.3" log = "0.4" fern = "0.6" +html-escape = "0.2" screeps-game-api = "0.21" # If you'd like to use a locally-cloned out version of the game API crate # (for testing PRs, etc), you can use a local path (replacing the above line): @@ -30,14 +31,14 @@ lto = true # Replace the following to enable wasm-opt optimization # wasm-pack will try to install wasm-opt automatically, but it must be installed by hand on some # operating systems. -wasm-opt = false +#wasm-opt = false # See wasm-opt for full available options; handy examples: # -O4 - optimize aggressively for performance # -Oz - optimize aggressively for code size # -g - leave debug info in place, allowing for more descriptive stack traces on panic # --disable-sign-ext - prevents opcodes that the screeps servers can't load (see # https://github.com/rustyscreeps/screeps-game-api/issues/391) -#wasm-opt = ["-O4", "--disable-sign-ext"] +wasm-opt = ["-O4", "--signext-lowering"] [features] default = [] diff --git a/src/logging.rs b/src/logging.rs index bc0916e..ea0f66e 100644 --- a/src/logging.rs +++ b/src/logging.rs @@ -1,6 +1,6 @@ -use core::panic::PanicInfo; use std::{fmt::Write, panic}; +use html_escape::encode_text; use js_sys::JsString; use log::*; use screeps::game; @@ -39,7 +39,7 @@ pub fn setup_logging(verbosity: log::LevelFilter) { "({}) {}: {}", record.level(), record.target(), - message + encode_text(&message.to_string()) )) }) .chain(Box::new(JsLog) as Box) @@ -48,7 +48,11 @@ pub fn setup_logging(verbosity: log::LevelFilter) { .level(log::LevelFilter::Warn) .format(|out, message, _record| { let time = game::time(); - out.finish(format_args!("[{}] {}", time, message)) + out.finish(format_args!( + "[{}] {}", + time, + encode_text(&message.to_string()) + )) }) .chain(Box::new(JsNotify) as Box), ) @@ -71,7 +75,7 @@ extern "C" { fn stack_trace_limit(size: f32); } -fn panic_hook(info: &PanicInfo) { +fn panic_hook(info: &panic::PanicHookInfo) { // import JS Error API to get backtrace info (backtraces don't work in wasm) // Node 8 does support this API: https://nodejs.org/docs/latest-v8.x/api/errors.html#errors_error_stack