File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -22,10 +22,15 @@ impl IgnorePathSet {
2222 pub ( crate ) fn is_match ( & self , file_name : & FileName ) -> bool {
2323 match file_name {
2424 FileName :: Stdin => false ,
25- FileName :: Real ( p) => self
26- . ignore_set
27- . matched_path_or_any_parents ( p, false )
28- . is_ignore ( ) ,
25+ FileName :: Real ( p) => {
26+ if p. is_absolute ( ) && !p. starts_with ( self . ignore_set . path ( ) ) {
27+ false
28+ } else {
29+ self . ignore_set
30+ . matched_path_or_any_parents ( p, false )
31+ . is_ignore ( )
32+ }
33+ }
2934 }
3035 }
3136}
@@ -70,4 +75,21 @@ mod test {
7075 assert ! ( ignore_path_set. is_match( & FileName :: Real ( PathBuf :: from( "bar_dir/baz/a.rs" ) ) ) ) ;
7176 assert ! ( !ignore_path_set. is_match( & FileName :: Real ( PathBuf :: from( "bar_dir/baz/what.rs" ) ) ) ) ;
7277 }
78+
79+ #[ nightly_only_test]
80+ #[ test]
81+ fn test_ignore_path_outside_root ( ) {
82+ //See: https://github.com/rust-lang/rustfmt/issues/6843
83+ use crate :: config:: { Config , FileName } ;
84+ use crate :: ignore_path:: IgnorePathSet ;
85+
86+ let config_path = std:: env:: temp_dir ( ) . join ( "a" ) . join ( "rustfmt.toml" ) ;
87+ let file_path = std:: env:: temp_dir ( ) . join ( "b" ) . join ( "foo.rs" ) ;
88+
89+ let config = Config :: from_toml ( r#"ignore = ["bar.rs"]"# , & config_path) . unwrap ( ) ;
90+ let ignore_path_set = IgnorePathSet :: from_ignore_list ( & config. ignore ( ) ) . unwrap ( ) ;
91+
92+ //should not panic
93+ assert ! ( !ignore_path_set. is_match( & FileName :: Real ( file_path) ) ) ;
94+ }
7395}
You can’t perform that action at this time.
0 commit comments