mirror of
https://github.com/YGGverse/agate.git
synced 2026-04-09 04:55:27 +00:00
Percent-escape more characters
This commit is contained in:
parent
da3f3fb727
commit
bf2e35537c
1 changed files with 10 additions and 2 deletions
12
src/main.rs
12
src/main.rs
|
|
@ -229,7 +229,15 @@ async fn send_header<W: Write + Unpin>(stream: &mut W, status: &str, meta: &[&st
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn list_directory<W: Write + Unpin>(stream: &mut W, path: &Path) -> Result {
|
async fn list_directory<W: Write + Unpin>(stream: &mut W, path: &Path) -> Result {
|
||||||
const WHITESPACE: AsciiSet = CONTROLS.add(b' ');
|
const ENCODE_SET: AsciiSet = CONTROLS.add(b' ')
|
||||||
|
// https://url.spec.whatwg.org/#path-percent-encode-set
|
||||||
|
.add(b'"').add(b'#').add(b'<').add(b'>')
|
||||||
|
.add(b'?').add(b'`').add(b'{').add(b'}')
|
||||||
|
// https://tools.ietf.org/html/rfc3986#section-2.2
|
||||||
|
.add(b':').add(b'/').add(b'?').add(b'#').add(b'[').add(b']').add(b'@')
|
||||||
|
.add(b'!').add(b'$').add(b'&').add(b'\'').add(b'(').add(b')')
|
||||||
|
.add(b'*').add(b'+').add(b',').add(b';').add(b'=');
|
||||||
|
|
||||||
log::info!("Listing directory {:?}", path);
|
log::info!("Listing directory {:?}", path);
|
||||||
send_text_gemini_header(stream).await?;
|
send_text_gemini_header(stream).await?;
|
||||||
let mut entries = async_std::fs::read_dir(path).await?;
|
let mut entries = async_std::fs::read_dir(path).await?;
|
||||||
|
|
@ -244,7 +252,7 @@ async fn list_directory<W: Write + Unpin>(stream: &mut W, path: &Path) -> Result
|
||||||
name += "/";
|
name += "/";
|
||||||
}
|
}
|
||||||
if name.contains(char::is_whitespace) {
|
if name.contains(char::is_whitespace) {
|
||||||
let url = percent_encode(name.as_bytes(), &WHITESPACE);
|
let url = percent_encode(name.as_bytes(), &ENCODE_SET);
|
||||||
lines.push(format!("=> {} {}\n", url, name));
|
lines.push(format!("=> {} {}\n", url, name));
|
||||||
} else {
|
} else {
|
||||||
lines.push(format!("=> {}\n", name));
|
lines.push(format!("=> {}\n", name));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue