mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 12:53:13 +00:00
Escape nonprintable characters when reporting invalid key name
Part of #10450
This commit is contained in:
parent
769316fd1a
commit
040cb04423
2 changed files with 16 additions and 2 deletions
15
src/key.rs
15
src/key.rs
|
@ -3,6 +3,7 @@ use std::rc::Rc;
|
||||||
use libc::VERASE;
|
use libc::VERASE;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
common::{escape_string, EscapeFlags, EscapeStringStyle},
|
||||||
fallback::fish_wcwidth,
|
fallback::fish_wcwidth,
|
||||||
reader::TERMINAL_MODE_ON_STARTUP,
|
reader::TERMINAL_MODE_ON_STARTUP,
|
||||||
wchar::prelude::*,
|
wchar::prelude::*,
|
||||||
|
@ -224,6 +225,13 @@ pub(crate) fn canonicalize_key(mut key: Key) -> Result<Key, WString> {
|
||||||
|
|
||||||
pub const KEY_SEPARATOR: char = ',';
|
pub const KEY_SEPARATOR: char = ',';
|
||||||
|
|
||||||
|
fn escape_nonprintables(key_name: &wstr) -> WString {
|
||||||
|
escape_string(
|
||||||
|
key_name,
|
||||||
|
EscapeStringStyle::Script(EscapeFlags::NO_PRINTABLES | EscapeFlags::NO_QUOTED),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn parse_keys(value: &wstr) -> Result<Vec<Key>, WString> {
|
pub(crate) fn parse_keys(value: &wstr) -> Result<Vec<Key>, WString> {
|
||||||
let mut res = vec![];
|
let mut res = vec![];
|
||||||
if value.is_empty() {
|
if value.is_empty() {
|
||||||
|
@ -267,7 +275,7 @@ pub(crate) fn parse_keys(value: &wstr) -> Result<Vec<Key>, WString> {
|
||||||
return Err(wgettext_fmt!(
|
return Err(wgettext_fmt!(
|
||||||
"unknown modifier '%s' in '%s'",
|
"unknown modifier '%s' in '%s'",
|
||||||
modifier,
|
modifier,
|
||||||
full_key_name
|
escape_nonprintables(full_key_name)
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -298,7 +306,10 @@ pub(crate) fn parse_keys(value: &wstr) -> Result<Vec<Key>, WString> {
|
||||||
codepoint,
|
codepoint,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return Err(wgettext_fmt!("cannot parse key '%s'", full_key_name));
|
return Err(wgettext_fmt!(
|
||||||
|
"cannot parse key '%s'",
|
||||||
|
escape_nonprintables(full_key_name)
|
||||||
|
));
|
||||||
};
|
};
|
||||||
res.push(key);
|
res.push(key);
|
||||||
}
|
}
|
||||||
|
|
|
@ -148,4 +148,7 @@ bind \r
|
||||||
bind \n 2>&1
|
bind \n 2>&1
|
||||||
# CHECK: bind: No binding found for key 'ctrl-j'
|
# CHECK: bind: No binding found for key 'ctrl-j'
|
||||||
|
|
||||||
|
bind _\cx_\ci_\ei_\\_\'_ 'echo foo'
|
||||||
|
# CHECKERR: bind: cannot parse key '_\cx_\t_\ei_\\_'_'
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|
Loading…
Reference in a new issue