Skip to content

Commit

Permalink
Fix public url handling with key prefixes
Browse files Browse the repository at this point in the history
  • Loading branch information
eandre committed Nov 27, 2024
1 parent e73ba46 commit 31c2729
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
10 changes: 3 additions & 7 deletions runtimes/core/src/objects/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,17 +496,13 @@ fn escape_path(s: &str) -> Cow<'_, str> {
/// Computes the public url given a base url, optional key prefix, and object name.
fn public_url(base_url: String, key_prefix: Option<&str>, name: &str) -> String {
let mut url = base_url;
if let Some(key_prefix) = key_prefix {
if !url.ends_with('/') {
url.push('/');
}
url.push_str(&escape_path(key_prefix));
}

if !url.ends_with('/') {
url.push('/');
}

if let Some(key_prefix) = key_prefix {
url.push_str(&escape_path(key_prefix));
}
url.push_str(&escape_path(name));
url
}
5 changes: 5 additions & 0 deletions runtimes/go/storage/objects/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ func (b *Bucket) PublicURL(object string, options ...PublicURLOption) *url.URL {
if !strings.HasSuffix(u.Path, "/") {
u.Path += "/"
}

if b.runtimeCfg.KeyPrefix != "" {
u.Path += escape(b.runtimeCfg.KeyPrefix, encodePath)
}

u.Path += escape(object, encodePath)

return &u
Expand Down

0 comments on commit 31c2729

Please sign in to comment.