Skip to content

Commit 3bcb76b

Browse files
binarypieealmloff
andauthored
Resolves #5045: Trim slashes to prevent base path resolution issues in web (#5049)
* issue-5045 Trim slashes to prevent base path resolution issues in web * Revert "issue-5045 Trim slashes to prevent base path resolution issues in web" This reverts commit 480cd48. * This is a more comprehensive approach. No matter how "/" gets set into DIOXUS_ASSET_ROOT (cli arg, dioxus toml, or env var) it will be normalized when used. * Move the trim fix to the locations we set the variable DIOXUS_ASSET_ROOT as this environment variable is not meant for public consumption. * pull out trimming into a method --------- Co-authored-by: Evan Almloff <[email protected]>
1 parent e5a98d0 commit 3bcb76b

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

packages/cli/src/build/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ impl AppBuilder {
521521
envs.push(("RUST_BACKTRACE".into(), "1".to_string()));
522522
}
523523

524-
if let Some(base_path) = krate.base_path() {
524+
if let Some(base_path) = krate.trimmed_base_path() {
525525
envs.push((
526526
dioxus_cli_config::ASSET_ROOT_ENV.into(),
527527
base_path.to_string(),

packages/cli/src/build/request.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2801,7 +2801,7 @@ impl BuildRequest {
28012801
// If this is a release build, bake the base path and title into the binary with env vars.
28022802
// todo: should we even be doing this? might be better being a build.rs or something else.
28032803
if self.release {
2804-
if let Some(base_path) = self.base_path() {
2804+
if let Some(base_path) = self.trimmed_base_path() {
28052805
env_vars.push((ASSET_ROOT_ENV.into(), base_path.to_string().into()));
28062806
}
28072807
env_vars.push((
@@ -4898,7 +4898,7 @@ __wbg_init({{module_or_path: "/{}/{wasm_path}"}}).then((wasm) => {{
48984898

48994899
// Add the base path to the head if this is a debug build
49004900
if self.is_dev_build() {
4901-
if let Some(base_path) = &self.base_path() {
4901+
if let Some(base_path) = &self.trimmed_base_path() {
49024902
head_resources.push_str(&format_base_path_meta_element(base_path));
49034903
}
49044904
}
@@ -5044,14 +5044,16 @@ __wbg_init({{module_or_path: "/{}/{wasm_path}"}}).then((wasm) => {{
50445044
.filter(|_| matches!(self.bundle, BundleFormat::Web | BundleFormat::Server))
50455045
}
50465046

5047-
/// Get the normalized base path for the application with `/` trimmed from both ends. If the base path is not set, this will return `.`.
5047+
/// Get the normalized base path for the application with `/` trimmed from both ends.
5048+
pub(crate) fn trimmed_base_path(&self) -> Option<&str> {
5049+
self.base_path()
5050+
.map(|p| p.trim_matches('/'))
5051+
.filter(|p| !p.is_empty())
5052+
}
5053+
5054+
/// Get the trimmed base path or `.` if no base path is set
50485055
pub(crate) fn base_path_or_default(&self) -> &str {
5049-
let trimmed_path = self.base_path().unwrap_or_default().trim_matches('/');
5050-
if trimmed_path.is_empty() {
5051-
"."
5052-
} else {
5053-
trimmed_path
5054-
}
5056+
self.trimmed_base_path().unwrap_or(".")
50555057
}
50565058

50575059
/// Get the path to the package manifest directory

0 commit comments

Comments
 (0)