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
8 changes: 5 additions & 3 deletions turbopack/crates/turbopack-browser/src/chunking_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use turbopack_core::{
chunk_id_strategy::ModuleIdStrategy,
},
environment::Environment,
ident::AssetIdent,
ident::{AssetIdent, escape_file_path},
module::Module,
module_graph::{
ModuleGraph,
Expand Down Expand Up @@ -704,9 +704,10 @@ impl ChunkingContext for BrowserChunkingContext {
match filename_template {
Some(filename) => {
let mut filename = filename.to_string();
let name = escape_file_path(name);

if match_name_placeholder(&filename) {
filename = replace_name_placeholder(&filename, name);
filename = replace_name_placeholder(&filename, &name);
}

if match_content_hash_placeholder(&filename) {
Expand Down Expand Up @@ -808,9 +809,10 @@ impl ChunkingContext for BrowserChunkingContext {
let mut filename = filename_template.to_string();

let (_, name, ext) = source_path.split_file_stem_extension();
let name = escape_file_path(name);

if match_name_placeholder(&filename) {
filename = replace_name_placeholder(&filename, name);
filename = replace_name_placeholder(&filename, &name);
}

if match_content_hash_placeholder(&filename) {
Expand Down
6 changes: 3 additions & 3 deletions turbopack/crates/turbopack-core/src/ident.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ impl ValueToString for AssetIdent {

pub fn escape_file_path(s: &str) -> String {
static SEPARATOR_REGEX: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"[/#?:\[\]<>@\s()]").unwrap());
LazyLock::new(|| Regex::new(r"[/#?:\[\]<>@\s()&]").unwrap());
Comment thread
fireairforce marked this conversation as resolved.
SEPARATOR_REGEX.replace_all(s, "_").to_string()
}

Expand Down Expand Up @@ -485,15 +485,15 @@ pub mod tests {
let fs = VirtualFileSystem::new_with_name(rcstr!("test"));
let root = fs.root().owned().await?;

let asset_ident = AssetIdent::from_path(root.join("a:b?c#d.js")?);
let asset_ident = AssetIdent::from_path(root.join("a:b?c#d&e.js")?);
let output_name = asset_ident
.output_name(root, Some(rcstr!("prefix")), rcstr!(".js"))
.await?;
Ok(Vc::cell((*output_name).clone()))
}

let output_name = output_name_operation().read_strongly_consistent().await?;
assert_eq!(&*output_name, "prefix-a_b_c_d.js");
assert_eq!(&*output_name, "prefix-a_b_c_d_e.js");

Ok(())
})
Expand Down
Loading