Skip to content

Commit

Permalink
cr
Browse files Browse the repository at this point in the history
  • Loading branch information
Arqu committed Oct 14, 2022
1 parent 016206d commit 19692f6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions iroh-gateway/src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ async fn serve_fs_dir<T: ContentLoader + std::marker::Unpin>(
.unwrap_or_default()
});
if !force_dir && has_index {
if !req.resolved_path.is_dir_like_path() {
if !req.resolved_path.has_trailing_slash() {
let redirect_path = format!(
"{}/{}",
req.resolved_path,
Expand All @@ -623,7 +623,7 @@ async fn serve_fs_dir<T: ContentLoader + std::marker::Unpin>(

let mut template_data: Map<String, Json> = Map::new();
let mut root_path = req.resolved_path.clone();
if !root_path.is_dir_like_path() {
if !root_path.has_trailing_slash() {
root_path.push("");
}

Expand Down
10 changes: 5 additions & 5 deletions iroh-resolver/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl Path {
}

// used only for string path manipulation
pub fn is_dir_like_path(&self) -> bool {
pub fn has_trailing_slash(&self) -> bool {
!self.tail.is_empty() && self.tail.last().unwrap().is_empty()
}

Expand All @@ -127,7 +127,7 @@ impl Path {
}
s.push_str(&format!("/{}", part)[..]);
}
if self.is_dir_like_path() {
if self.has_trailing_slash() {
s.push('/');
}
s
Expand Down Expand Up @@ -160,7 +160,7 @@ impl Display for Path {
write!(f, "/{}", part)?;
}

if self.is_dir_like_path() {
if self.has_trailing_slash() {
write!(f, "/")?;
}

Expand Down Expand Up @@ -1246,8 +1246,8 @@ mod tests {

assert!(non_dir_path.to_string() == non_dir_test);
assert!(dir_path.to_string() == dir_test);
assert!(dir_path.is_dir_like_path());
assert!(!non_dir_path.is_dir_like_path());
assert!(dir_path.has_trailing_slash());
assert!(!non_dir_path.has_trailing_slash());
}

fn make_ipld() -> Ipld {
Expand Down

0 comments on commit 19692f6

Please sign in to comment.