0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-03-03 09:31:22 -05:00

fix(repl): recover from invalid input (#8759)

This commit is contained in:
Casper Beyer 2020-12-15 00:37:08 +08:00 committed by GitHub
parent 8f8749095c
commit ce6b738ac0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 1 deletions

View file

@ -1656,6 +1656,31 @@ fn repl_test_pty_unpaired_braces() {
}
}
#[cfg(unix)]
#[test]
fn repl_test_pty_bad_input() {
use std::io::Read;
use util::pty::fork::*;
let deno_exe = util::deno_exe_path();
let fork = Fork::from_ptmx().unwrap();
if let Ok(mut master) = fork.is_parent() {
master.write_all(b"'\\u{1f3b5}'[0]\n").unwrap();
master.write_all(b"close();\n").unwrap();
let mut output = String::new();
master.read_to_string(&mut output).unwrap();
assert!(output.contains("Unterminated string literal"));
fork.wait().unwrap();
} else {
std::env::set_var("NO_COLOR", "1");
let err = exec::Command::new(deno_exe).arg("repl").exec();
println!("err {}", err);
unreachable!()
}
}
#[test]
#[ignore]
fn run_watch_with_importmap_and_relative_paths() {

View file

@ -859,7 +859,28 @@ impl v8::inspector::ChannelImpl for InspectorSession {
message: v8::UniquePtr<v8::inspector::StringBuffer>,
) {
let raw_message = message.unwrap().string().to_string();
let message = serde_json::from_str(&raw_message).unwrap();
let message: serde_json::Value = match serde_json::from_str(&raw_message) {
Ok(v) => v,
Err(error) => match error.classify() {
serde_json::error::Category::Syntax => json!({
"id": call_id,
"result": {
"result": {
"type": "error",
"description": "Unterminated string literal",
"value": "Unterminated string literal",
},
"exceptionDetails": {
"exceptionId": 0,
"text": "Unterminated string literal",
"lineNumber": 0,
"columnNumber": 0
},
},
}),
_ => panic!("Could not parse inspector message"),
},
};
self
.response_tx_map