From c9fa541be488917c6178e41680b5ed9a37038c3a Mon Sep 17 00:00:00 2001 From: plotchy Date: Fri, 6 Oct 2023 00:28:44 -0400 Subject: [PATCH 1/2] fix: test different ends_with --- ethers-solc/src/config.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ethers-solc/src/config.rs b/ethers-solc/src/config.rs index 23060b236..923ec9111 100644 --- a/ethers-solc/src/config.rs +++ b/ethers-solc/src/config.rs @@ -348,7 +348,7 @@ impl ProjectPathsConfig { // (`/=.../contracts`) and the stripped import also starts with // `contracts` if let Ok(adjusted_import) = stripped_import.strip_prefix("contracts/") { - if r.path.ends_with("contracts/") && !lib_path.exists() { + if r.path.ends_with("/contracts/") && !lib_path.exists() { return Path::new(&r.path).join(adjusted_import) } } From 54c3b19b8a70220e7c7c8ca2e39b8775b10ec722 Mon Sep 17 00:00:00 2001 From: plotchy Date: Fri, 6 Oct 2023 11:16:36 -0400 Subject: [PATCH 2/2] add descriptive comments for remapping --- ethers-solc/src/config.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/ethers-solc/src/config.rs b/ethers-solc/src/config.rs index 923ec9111..0f02991cc 100644 --- a/ethers-solc/src/config.rs +++ b/ethers-solc/src/config.rs @@ -320,8 +320,8 @@ impl ProjectPathsConfig { /// /// There is no strict rule behind this, but because [`crate::remappings::Remapping::find_many`] /// returns `'@openzeppelin/=node_modules/@openzeppelin/contracts/'` we should handle the - /// case if the remapping path ends with `contracts` and the import path starts with - /// `/contracts`. Otherwise we can end up with a resolved path that has a + /// case if the remapping path ends with `/contracts/` and the import path starts with + /// `/contracts/`. Otherwise we can end up with a resolved path that has a /// duplicate `contracts` segment: /// `@openzeppelin/contracts/contracts/token/ERC20/IERC20.sol` we check for this edge case /// here so that both styles work out of the box. @@ -344,10 +344,12 @@ impl ProjectPathsConfig { import.strip_prefix(&r.name).ok().map(|stripped_import| { let lib_path = Path::new(&r.path).join(stripped_import); - // we handle the edge case where the path of a remapping ends with "contracts" - // (`/=.../contracts`) and the stripped import also starts with - // `contracts` + // we handle the edge case where the path of a remapping ends with "/contracts/" + // (`/=.../contracts/`) and the stripped import also starts with + // `contracts/` if let Ok(adjusted_import) = stripped_import.strip_prefix("contracts/") { + // Wrap suffix check in `/` so this prevents matching remapping paths that + // end with '-contracts/', '_contracts/', '.contracts/' etc. if r.path.ends_with("/contracts/") && !lib_path.exists() { return Path::new(&r.path).join(adjusted_import) }