mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-31 20:31:19 -03:00
Fix DCS parser spuriously stopping at escape byte
DCS commands stop at ST ("\e\\"). Make sure we don't stop at just "\e". I
don't know of any command that will actually include the escape byte in its
payload but better safe than sorry.
This commit is contained in:
@@ -1349,28 +1349,34 @@ fn parse_ss3(&mut self, buffer: &mut Vec<u8>) -> Option<KeyEvent> {
|
||||
Some(key)
|
||||
}
|
||||
|
||||
fn parse_xtversion(&mut self, buffer: &mut Vec<u8>) {
|
||||
assert!(buffer.len() == 3);
|
||||
fn read_until_sequence_terminator(&mut self, buffer: &mut Vec<u8>) -> Option<()> {
|
||||
let mut escape = false;
|
||||
loop {
|
||||
match self.try_readb(buffer) {
|
||||
None => return,
|
||||
Some(b'\x1b') => break,
|
||||
Some(_) => continue,
|
||||
let b = self.try_readb(buffer)?;
|
||||
if escape && b == b'\\' {
|
||||
break;
|
||||
}
|
||||
escape = b == b'\x1b';
|
||||
}
|
||||
if self.try_readb(buffer) != Some(b'\\') {
|
||||
return;
|
||||
}
|
||||
if buffer[3] != b'|' {
|
||||
return;
|
||||
buffer.pop();
|
||||
buffer.pop();
|
||||
Some(())
|
||||
}
|
||||
|
||||
fn parse_xtversion(&mut self, buffer: &mut Vec<u8>) -> Option<()> {
|
||||
assert_eq!(buffer, b"\x1bP>");
|
||||
self.read_until_sequence_terminator(buffer)?;
|
||||
if buffer.get(3)? != &b'|' {
|
||||
return None;
|
||||
}
|
||||
FLOG!(
|
||||
reader,
|
||||
format!(
|
||||
"Received XTVERSION response: {}",
|
||||
str2wcstring(&buffer[4..buffer.len() - 2]),
|
||||
str2wcstring(&buffer[4..buffer.len()])
|
||||
)
|
||||
);
|
||||
None
|
||||
}
|
||||
|
||||
fn parse_dcs(&mut self, buffer: &mut Vec<u8>) -> Option<KeyEvent> {
|
||||
@@ -1393,12 +1399,7 @@ fn parse_dcs(&mut self, buffer: &mut Vec<u8>) -> Option<KeyEvent> {
|
||||
if self.try_readb(buffer)? != b'r' {
|
||||
return None;
|
||||
}
|
||||
while self.try_readb(buffer)? != b'\x1b' {}
|
||||
if self.try_readb(buffer)? != b'\\' {
|
||||
return None;
|
||||
}
|
||||
buffer.pop();
|
||||
buffer.pop();
|
||||
self.read_until_sequence_terminator(buffer)?;
|
||||
// \e P 1 r + Pn ST
|
||||
// \e P 0 r + msg ST
|
||||
let buffer = &buffer[5..];
|
||||
|
||||
Reference in New Issue
Block a user