Fix repository paths containing spaces (#62)
This commit is contained in:
@@ -110,7 +110,7 @@ async fn reads_nested_directory_from_compatible_contents_endpoint() {
|
||||
let mut buffer = [0; 4096];
|
||||
let length = stream.read(&mut buffer).unwrap();
|
||||
let request = String::from_utf8_lossy(&buffer[..length]).into_owned();
|
||||
let body = r#"[{"name":"guide.md","path":"docs/guide.md","type":"file"}]"#;
|
||||
let body = r#"[{"name":"guide.md","path":"docs/private guide/guide.md","type":"file"}]"#;
|
||||
write!(
|
||||
stream,
|
||||
"HTTP/1.1 200 OK\r\nContent-Type: application/json\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{body}",
|
||||
@@ -125,16 +125,53 @@ async fn reads_nested_directory_from_compatible_contents_endpoint() {
|
||||
.unwrap();
|
||||
let repository = RepositoryId::new("forgejo", "forgejo").unwrap();
|
||||
let contents = client
|
||||
.repository_contents(&repository, "docs/guide")
|
||||
.repository_contents(&repository, "docs/private guide")
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(contents.len(), 1);
|
||||
assert_eq!(contents[0].path.as_deref(), Some("docs/guide.md"));
|
||||
assert_eq!(
|
||||
contents[0].path.as_deref(),
|
||||
Some("docs/private guide/guide.md")
|
||||
);
|
||||
assert!(
|
||||
server
|
||||
.join()
|
||||
.unwrap()
|
||||
.starts_with("GET /api/v1/repos/forgejo/forgejo/contents/docs%2Fguide ")
|
||||
.starts_with("GET /api/v1/repos/forgejo/forgejo/contents/docs%2Fprivate%20guide ")
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn reads_file_with_spaces_from_raw_endpoint() {
|
||||
let listener = TcpListener::bind("127.0.0.1:0").unwrap();
|
||||
let address = listener.local_addr().unwrap();
|
||||
let server = thread::spawn(move || {
|
||||
let (mut stream, _) = listener.accept().unwrap();
|
||||
let mut buffer = [0; 4096];
|
||||
let length = stream.read(&mut buffer).unwrap();
|
||||
let request = String::from_utf8_lossy(&buffer[..length]).into_owned();
|
||||
let body = "contents";
|
||||
write!(
|
||||
stream,
|
||||
"HTTP/1.1 200 OK\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{body}",
|
||||
body.len()
|
||||
)
|
||||
.unwrap();
|
||||
request
|
||||
});
|
||||
|
||||
let client = Client::new(&format!("http://{address}"), None).unwrap();
|
||||
let repository = RepositoryId::new("gitea", "gitea").unwrap();
|
||||
let contents = client
|
||||
.repository_file(&repository, "docs/private guide/read me.md")
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(contents, b"contents");
|
||||
assert!(
|
||||
server.join().unwrap().starts_with(
|
||||
"GET /api/v1/repos/gitea/gitea/raw/docs%2Fprivate%20guide%2Fread%20me.md "
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user