@@ -138,8 +138,11 @@ impl fmt::Display for Remapping {
138138 }
139139 s. push ( ':' ) ;
140140 }
141- let name =
142- if !self . name . ends_with ( '/' ) { format ! ( "{}/" , self . name) } else { self . name . clone ( ) } ;
141+ let name = if !self . name . ends_with ( '/' ) && !self . name . ends_with ( ".sol" ) {
142+ format ! ( "{}/" , self . name)
143+ } else {
144+ self . name . clone ( )
145+ } ;
143146 s. push_str ( & {
144147 #[ cfg( target_os = "windows" ) ]
145148 {
@@ -153,7 +156,7 @@ impl fmt::Display for Remapping {
153156 }
154157 } ) ;
155158
156- if !s. ends_with ( '/' ) {
159+ if !s. ends_with ( '/' ) && !s . ends_with ( ".sol" ) {
157160 s. push ( '/' ) ;
158161 }
159162 f. write_str ( & s)
@@ -241,7 +244,7 @@ impl fmt::Display for RelativeRemapping {
241244 }
242245 } ) ;
243246
244- if !s. ends_with ( '/' ) {
247+ if !s. ends_with ( '/' ) && !s . ends_with ( ".sol" ) {
245248 s. push ( '/' ) ;
246249 }
247250 f. write_str ( & s)
@@ -252,10 +255,10 @@ impl From<RelativeRemapping> for Remapping {
252255 fn from ( r : RelativeRemapping ) -> Self {
253256 let RelativeRemapping { context, mut name, path } = r;
254257 let mut path = path. relative ( ) . display ( ) . to_string ( ) ;
255- if !path. ends_with ( '/' ) {
258+ if !path. ends_with ( '/' ) && !path . ends_with ( ".sol" ) {
256259 path. push ( '/' ) ;
257260 }
258- if !name. ends_with ( '/' ) {
261+ if !name. ends_with ( '/' ) && !name . ends_with ( ".sol" ) {
259262 name. push ( '/' ) ;
260263 }
261264 Self { context, name, path }
@@ -423,4 +426,21 @@ mod tests {
423426 ) ;
424427 assert_eq ! ( remapping. to_string( ) , "oz/=a/b/c/d/" . to_string( ) ) ;
425428 }
429+
430+ // <https://github.com/foundry-rs/foundry/issues/6706#issuecomment-3141270852>
431+ #[ test]
432+ fn can_preserve_single_sol_file_remapping ( ) {
433+ let remapping = "@my-lib/B.sol=lib/my-lib/B.sol" ;
434+ let remapping = Remapping :: from_str ( remapping) . unwrap ( ) ;
435+
436+ assert_eq ! (
437+ remapping,
438+ Remapping {
439+ context: None ,
440+ name: "@my-lib/B.sol" . to_string( ) ,
441+ path: "lib/my-lib/B.sol" . to_string( )
442+ }
443+ ) ;
444+ assert_eq ! ( remapping. to_string( ) , "@my-lib/B.sol=lib/my-lib/B.sol" . to_string( ) ) ;
445+ }
426446}
0 commit comments