Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions static-serve-macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ display_full_error = "1.1"
flate2 = "1.1"
glob = "0.3"
mime_guess = "2.0.5"
pathdiff = "0.2"
proc-macro2 = "1.0"
quote = "1.0"
sha2 = "0.11"
Expand Down
5 changes: 3 additions & 2 deletions static-serve-macro/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::{
ffi::{OsStr, OsString},
fmt::{Display, Formatter},
io,
path::PathBuf,
};

use glob::{GlobError, PatternError};
Expand All @@ -17,14 +18,14 @@ pub(crate) enum Error {
CannotCanonicalizeDirectory(#[source] io::Error),
#[error("Cannot canonicalize asset file")]
CannotCanonicalizeFile(#[source] io::Error),
#[error("Cannot make file path {0} relative to directory")]
CannotMakeFileRelative(PathBuf),
#[error("File path is not utf-8")]
FilePathIsNotUtf8,
#[error("Invalid unicode in directory name")]
InvalidUnicodeInDirectoryName,
#[error("Cannot canonicalize ignore path")]
CannotCanonicalizeIgnorePath(#[source] io::Error),
#[error("Invalid unicode in entry name")]
InvalidUnicodeInEntryName,
#[error("Error while compressing with gzip")]
Gzip(#[from] GzipType),
#[error("Error while compressing with zstd")]
Expand Down
13 changes: 5 additions & 8 deletions static-serve-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -722,12 +722,9 @@ impl EmbeddedFileInfo {

// entry_path is only needed for the router (embed_assets!)
let entry_path = if let Some(dir) = assets_dir_abs_str {
let relative_entry = pathbuf
.strip_prefix(dir)
.ok()
.and_then(|p| p.to_str())
.ok_or(Error::InvalidUnicodeInEntryName)?;
let mut web_path = normalize_web_path(relative_entry);
let relative_entry = pathdiff::diff_paths(pathbuf, dir)
.ok_or_else(|| Error::CannotMakeFileRelative(pathbuf.clone()))?;
let mut web_path = normalize_web_path(&relative_entry);
if should_strip_html_ext.value && content_type == "text/html" {
strip_html_ext(&mut web_path);
}
Expand Down Expand Up @@ -855,8 +852,8 @@ fn etag(contents: &[u8]) -> String {
/// Path segments are normalized via [`Path::components`] so separator
/// style differences across platforms do not affect route generation.
/// The returned route is always absolute (starts with `/`).
fn normalize_web_path(relative_path: &str) -> String {
let normalized = Path::new(relative_path)
fn normalize_web_path(relative_path: &Path) -> String {
let normalized = relative_path
.components()
.filter_map(|component| match component {
std::path::Component::Normal(segment) => segment.to_str(),
Expand Down