From a48496000ae82f9dd2743bf2bc8004dd7651ca0a Mon Sep 17 00:00:00 2001 From: Roman Krasiuk Date: Mon, 31 Jan 2022 00:08:04 -0800 Subject: [PATCH] fix(solc): flatten replacement target location (#846) * adjust the end location * upd changelog --- CHANGELOG.md | 2 ++ ethers-solc/src/resolver.rs | 3 ++- ethers-solc/tests/project.rs | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ed9c6c6..a92aa447 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,8 @@ ### Unreleased +- Fix flatten replacement target location + [#846](https://github.com/gakonst/ethers-rs/pull/846) - Fix duplicate files during flattening [#813](https://github.com/gakonst/ethers-rs/pull/813) - Add ability to flatten file imports diff --git a/ethers-solc/src/resolver.rs b/ethers-solc/src/resolver.rs index e2c8403d..fce1c88d 100644 --- a/ethers-solc/src/resolver.rs +++ b/ethers-solc/src/resolver.rs @@ -485,7 +485,8 @@ impl SolDataUnit { pub fn loc_by_offset(&self, offset: isize) -> (usize, usize) { ( offset.saturating_add(self.loc.start as isize) as usize, - offset.saturating_add(self.loc.end as isize) as usize, + // make the end location exclusive + offset.saturating_add(self.loc.end as isize + 1) as usize, ) } } diff --git a/ethers-solc/tests/project.rs b/ethers-solc/tests/project.rs index c50fd3eb..f7b362d7 100644 --- a/ethers-solc/tests/project.rs +++ b/ethers-solc/tests/project.rs @@ -376,4 +376,5 @@ fn can_flatten_file_with_duplicates() { assert_eq!(result.matches("contract Foo {").count(), 1); assert_eq!(result.matches("contract Bar {").count(), 1); assert_eq!(result.matches("contract FooBar {").count(), 1); + assert_eq!(result.matches(";").count(), 1); }