@@ -184,7 +184,18 @@ impl<'a> InstallConfiguration<'a> {
184184 env_vars. insert ( "https_proxy" , url. to_string ( ) ) ;
185185 }
186186 if let Some ( s) = & proxy. no_proxy {
187- env_vars. insert ( "no_proxy" , s. to_string ( ) ) ;
187+ // keep use's original no_proxy var.
188+ #[ cfg( windows) ]
189+ let prev_np = std:: env:: var ( "no_proxy" ) . unwrap_or_default ( ) ;
190+ #[ cfg( unix) ]
191+ let prev_np = "$no_proxy" ;
192+
193+ let no_proxy = if prev_np. is_empty ( ) {
194+ s. to_string ( )
195+ } else {
196+ format ! ( "{s},{prev_np}" )
197+ } ;
198+ env_vars. insert ( "no_proxy" , no_proxy) ;
188199 }
189200 }
190201
@@ -594,4 +605,56 @@ c = { version = "0.1.0", conflicts = ["d", "a"] }
594605 let error = conflicts. expect_err ( "has conflicts" ) ;
595606 println ! ( "{error}" ) ;
596607 }
608+
609+ #[ test]
610+ fn no_proxy_env_var ( ) {
611+ let raw = r#"
612+ [rust]
613+ version = "1.0.0"
614+
615+ [proxy]
616+ no_proxy = "localhost,.example.com,.foo.com"
617+ "# ;
618+
619+ let manifest = ToolkitManifest :: from_str ( raw) . unwrap ( ) ;
620+ let install_dir = tempfile:: tempdir ( ) . unwrap ( ) ;
621+ let install_cfg = InstallConfiguration :: new ( install_dir. path ( ) , & manifest) . unwrap ( ) ;
622+
623+ // Temporarily modify no_proxy var to test inheritance.
624+ // FIXME (master): Later commits introduces mocked env tests, make sure to tesk this
625+ // with mocked env, that we don't need to set no_proxy var here and potentially
626+ // mess up other concurrent test cases.
627+ let no_proxy_backup = std:: env:: var ( "no_proxy" ) ;
628+ std:: env:: remove_var ( "no_proxy" ) ;
629+
630+ let env_vars = install_cfg. env_vars ( ) . unwrap ( ) ;
631+ let new_no_proxy_var = env_vars. get ( "no_proxy" ) . unwrap ( ) ;
632+
633+ #[ cfg( windows) ]
634+ assert_eq ! ( new_no_proxy_var, "localhost,.example.com,.foo.com" ) ;
635+ #[ cfg( unix) ]
636+ assert_eq ! (
637+ new_no_proxy_var,
638+ "localhost,.example.com,.foo.com,$no_proxy"
639+ ) ;
640+
641+ std:: env:: set_var ( "no_proxy" , ".bar.com,baz.com" ) ;
642+ let env_vars = install_cfg. env_vars ( ) . unwrap ( ) ;
643+ let new_no_proxy_var = env_vars. get ( "no_proxy" ) . unwrap ( ) ;
644+
645+ #[ cfg( windows) ]
646+ assert_eq ! (
647+ new_no_proxy_var,
648+ "localhost,.example.com,.foo.com,.bar.com,baz.com"
649+ ) ;
650+ #[ cfg( unix) ]
651+ assert_eq ! (
652+ new_no_proxy_var,
653+ "localhost,.example.com,.foo.com,$no_proxy"
654+ ) ;
655+
656+ if let Ok ( bck) = no_proxy_backup {
657+ std:: env:: set_var ( "no_proxy" , bck) ;
658+ }
659+ }
597660}
0 commit comments