Skip to content

Commit 9d76262

Browse files
committed
fix: Assure ReadlineBufRead::readline_str() calls our implementation for Box<T: ReadlineBufRead> as well.
This fixes a bug where the HTTP implementation would incorrectly concatenate packetlines without newlines as sent by the server for shallow info lines.
1 parent e4bb6af commit 9d76262

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

gix-transport/src/client/async_io/bufread_ext.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl<T: AsyncRead + Unpin> ReadlineBufRead for gix_packetline::read::WithSideban
9494
self.read_data_line().await
9595
}
9696
async fn readline_str(&mut self, line: &mut String) -> io::Result<usize> {
97-
self.read_line(line).await
97+
self.read_line_to_string(line).await
9898
}
9999
}
100100

@@ -104,7 +104,7 @@ impl<'a, T: AsyncRead + Unpin> ReadlineBufRead for gix_packetline::read::WithSid
104104
self.read_data_line().await
105105
}
106106
async fn readline_str(&mut self, line: &mut String) -> io::Result<usize> {
107-
self.read_line(line).await
107+
self.read_line_to_string(line).await
108108
}
109109
}
110110

gix-transport/src/client/blocking_io/bufread_ext.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use std::io::BufRead;
21
use std::{
32
io,
43
ops::{Deref, DerefMut},
@@ -58,7 +57,7 @@ impl<'a, T: ReadlineBufRead + ?Sized + 'a> ReadlineBufRead for Box<T> {
5857
ReadlineBufRead::readline(self.deref_mut())
5958
}
6059
fn readline_str(&mut self, line: &mut String) -> io::Result<usize> {
61-
self.read_line(line)
60+
ReadlineBufRead::readline_str(self.deref_mut(), line)
6261
}
6362
}
6463

@@ -86,7 +85,7 @@ impl<T: io::Read> ReadlineBufRead for gix_packetline::read::WithSidebands<'_, T,
8685
}
8786

8887
fn readline_str(&mut self, line: &mut String) -> io::Result<usize> {
89-
self.read_line(line)
88+
self.read_line_to_string(line)
9089
}
9190
}
9291

@@ -96,7 +95,7 @@ impl<'a, T: io::Read> ReadlineBufRead for gix_packetline::read::WithSidebands<'a
9695
}
9796

9897
fn readline_str(&mut self, line: &mut String) -> io::Result<usize> {
99-
self.read_line(line)
98+
self.read_line_to_string(line)
10099
}
101100
}
102101

gix-transport/src/client/blocking_io/ssh/tests.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,22 +126,22 @@ mod program_kind {
126126
&["ssh", "-o", "SendEnv=GIT_PROTOCOL", "host"][..],
127127
),
128128
] {
129-
assert_eq!(call_args(ProgramKind::Ssh, url, protocol), quoted(expected));
129+
assert_eq!(call_args(ProgramKind::Ssh, url, protocol), joined(expected));
130130
}
131131
}
132132

133133
#[test]
134134
fn tortoise_plink_has_batch_command() {
135135
assert_eq!(
136136
call_args(ProgramKind::TortoisePlink, "ssh://user@host:42/p", Protocol::V2),
137-
quoted(&["tortoiseplink.exe", "-batch", "-P", "42", "user@host"])
137+
joined(&["tortoiseplink.exe", "-batch", "-P", "42", "user@host"])
138138
);
139139
}
140140

141141
#[test]
142142
fn port_for_all() {
143143
for kind in [ProgramKind::TortoisePlink, ProgramKind::Plink, ProgramKind::Putty] {
144-
assert!(call_args(kind, "ssh://user@host:43/p", Protocol::V2).ends_with(r#""-P" "43" "user@host""#));
144+
assert!(call_args(kind, "ssh://user@host:43/p", Protocol::V2).ends_with("-P 43 user@host"));
145145
}
146146
}
147147

@@ -153,7 +153,7 @@ mod program_kind {
153153
}
154154
assert_eq!(
155155
call_args(ProgramKind::Simple, "ssh://user@host/p", Protocol::V2),
156-
quoted(&["simple", "user@host"]),
156+
joined(&["simple", "user@host"]),
157157
"simple can only do simple invocations"
158158
);
159159
}
@@ -191,8 +191,8 @@ mod program_kind {
191191
Ok(())
192192
}
193193

194-
fn quoted(input: &[&str]) -> String {
195-
input.iter().map(|s| format!("\"{s}\"")).collect::<Vec<_>>().join(" ")
194+
fn joined(input: &[&str]) -> String {
195+
input.iter().copied().collect::<Vec<_>>().join(" ")
196196
}
197197
fn try_call(
198198
kind: ProgramKind,
@@ -207,7 +207,15 @@ mod program_kind {
207207
try_call(kind, url, version).expect("no error")
208208
}
209209
fn call_args(kind: ProgramKind, url: &str, version: Protocol) -> String {
210-
format!("{:?}", std::process::Command::from(call(kind, url, version)))
210+
let cmd = std::process::Command::from(call(kind, url, version));
211+
format!(
212+
"{} {}",
213+
cmd.get_program().to_string_lossy(),
214+
cmd.get_args()
215+
.map(|arg| arg.to_string_lossy().into_owned())
216+
.collect::<Vec<_>>()
217+
.join(" ")
218+
)
211219
}
212220

213221
type Result = std::result::Result<(), ssh::invocation::Error>;

0 commit comments

Comments
 (0)