fix(stats): generation for commands starting with a pipe (#2058)

Closes #1882
This commit is contained in:
Sandro 2024-05-30 16:55:29 +02:00 committed by GitHub
parent 4d74e38a51
commit 21109517c0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -92,7 +92,7 @@ fn split_at_pipe(command: &str) -> Vec<&str> {
"\\" => if graphemes.next().is_some() {}, "\\" => if graphemes.next().is_some() {},
"|" => { "|" => {
if !quoted { if !quoted {
if command[start..].starts_with('|') { if current > start && command[start..].starts_with('|') {
start += 1; start += 1;
} }
result.push(&command[start..current]); result.push(&command[start..current]);
@ -396,4 +396,20 @@ mod tests {
["git commit -m \"🚀\""] ["git commit -m \"🚀\""]
); );
} }
#[test]
fn starts_with_pipe() {
assert_eq!(
split_at_pipe("| sed 's/[0-9a-f]//g'"),
["", " sed 's/[0-9a-f]//g'"]
);
}
#[test]
fn starts_with_spaces_and_pipe() {
assert_eq!(
split_at_pipe(" | sed 's/[0-9a-f]//g'"),
[" ", " sed 's/[0-9a-f]//g'"]
);
}
} }