From 58fc10ed9c8de85a82c43b02d0f4c8c8844321de Mon Sep 17 00:00:00 2001 From: Cong-Cong Pan Date: Fri, 13 Dec 2024 14:43:11 +0800 Subject: [PATCH] fix: alias match request end with slash (#35) Co-authored-by: SoonIter --- src/lib.rs | 12 ++++++++---- src/tests/alias.rs | 1 + 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 902daa8..efc06cb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -998,17 +998,21 @@ impl ResolverGeneric { let new_specifier = if tail.is_empty() { Cow::Borrowed(alias_value) } else { - let alias_value = Path::new(alias_value).normalize(); + let alias_path = Path::new(alias_value).normalize(); // Must not append anything to alias_value if it is a file. - let alias_value_cached_path = self.cache.value(&alias_value); + let alias_value_cached_path = self.cache.value(&alias_path); if alias_value_cached_path.is_file(&self.cache.fs, ctx) { return Ok(None); } // Remove the leading slash so the final path is concatenated. let tail = tail.trim_start_matches(SLASH_START); - let normalized = alias_value.normalize_with(tail); - Cow::Owned(normalized.to_string_lossy().to_string()) + if tail.is_empty() { + Cow::Borrowed(alias_value) + } else { + let normalized = alias_path.normalize_with(tail); + Cow::Owned(normalized.to_string_lossy().to_string()) + } }; *should_stop = true; diff --git a/src/tests/alias.rs b/src/tests/alias.rs index e589206..2fa8f90 100644 --- a/src/tests/alias.rs +++ b/src/tests/alias.rs @@ -79,6 +79,7 @@ fn alias() { ("should resolve '#' alias 2", "#/index", "/c/dir/index"), ("should resolve '@' alias 1", "@", "/c/dir/index"), ("should resolve '@' alias 2", "@/index", "/c/dir/index"), + ("should resolve '@' alias 3", "@/", "/c/dir/index"), ("should resolve a recursive aliased module 1", "recursive", "/recursive/dir/index"), ("should resolve a recursive aliased module 2", "recursive/index", "/recursive/dir/index"), ("should resolve a recursive aliased module 3", "recursive/dir", "/recursive/dir/index"),