File tree 3 files changed +77
-0
lines changed
3 files changed +77
-0
lines changed Original file line number Diff line number Diff line change @@ -687,6 +687,16 @@ impl GlobalContext {
687
687
} => anyhow ! (
688
688
"unexpected variable `{variable}` in build.build-dir path `{raw_template}`"
689
689
) ,
690
+ path:: ResolveTemplateError :: UnexpectedBracket { bracket_type, raw_template } => {
691
+ let ( btype, literal) = match bracket_type {
692
+ path:: BracketType :: Opening => ( "opening" , "{" ) ,
693
+ path:: BracketType :: Closing => ( "closing" , "}" ) ,
694
+ } ;
695
+
696
+ anyhow ! (
697
+ "unexpected {btype} bracket `{literal}` in build.build-dir path `{raw_template}`"
698
+ )
699
+ }
690
700
} ) ?;
691
701
692
702
// Check if the target directory is set to an empty string in the config.toml file.
Original file line number Diff line number Diff line change @@ -58,6 +58,20 @@ impl ConfigRelativePath {
58
58
} ) ;
59
59
} ;
60
60
61
+ if value. contains ( "{" ) {
62
+ return Err ( ResolveTemplateError :: UnexpectedBracket {
63
+ bracket_type : BracketType :: Opening ,
64
+ raw_template : self . 0 . val . clone ( ) ,
65
+ } ) ;
66
+ }
67
+
68
+ if value. contains ( "}" ) {
69
+ return Err ( ResolveTemplateError :: UnexpectedBracket {
70
+ bracket_type : BracketType :: Closing ,
71
+ raw_template : self . 0 . val . clone ( ) ,
72
+ } ) ;
73
+ }
74
+
61
75
Ok ( self . 0 . definition . root ( gctx) . join ( & value) )
62
76
}
63
77
@@ -139,4 +153,14 @@ pub enum ResolveTemplateError {
139
153
variable : String ,
140
154
raw_template : String ,
141
155
} ,
156
+ UnexpectedBracket {
157
+ bracket_type : BracketType ,
158
+ raw_template : String ,
159
+ } ,
160
+ }
161
+
162
+ #[ derive( Debug ) ]
163
+ pub enum BracketType {
164
+ Opening ,
165
+ Closing ,
142
166
}
Original file line number Diff line number Diff line change @@ -684,6 +684,49 @@ fn template_workspace_path_hash_should_handle_symlink() {
684
684
}
685
685
}
686
686
687
+ #[ cargo_test]
688
+ fn template_should_handle_reject_unmatched_brackets ( ) {
689
+ let p = project ( )
690
+ . file ( "src/lib.rs" , "" )
691
+ . file (
692
+ ".cargo/config.toml" ,
693
+ r#"
694
+ [build]
695
+ build-dir = "foo/{bar"
696
+ "# ,
697
+ )
698
+ . build ( ) ;
699
+
700
+ p. cargo ( "build -Z build-dir" )
701
+ . masquerade_as_nightly_cargo ( & [ "build-dir" ] )
702
+ . with_status ( 101 )
703
+ . with_stderr_data ( str![ [ r#"
704
+ [ERROR] unexpected opening bracket `{` in build.build-dir path `foo/{bar`
705
+
706
+ "# ] ] )
707
+ . run ( ) ;
708
+
709
+ let p = project ( )
710
+ . file ( "src/lib.rs" , "" )
711
+ . file (
712
+ ".cargo/config.toml" ,
713
+ r#"
714
+ [build]
715
+ build-dir = "foo/}bar"
716
+ "# ,
717
+ )
718
+ . build ( ) ;
719
+
720
+ p. cargo ( "build -Z build-dir" )
721
+ . masquerade_as_nightly_cargo ( & [ "build-dir" ] )
722
+ . with_status ( 101 )
723
+ . with_stderr_data ( str![ [ r#"
724
+ [ERROR] unexpected closing bracket `}` in build.build-dir path `foo/}bar`
725
+
726
+ "# ] ] )
727
+ . run ( ) ;
728
+ }
729
+
687
730
fn parse_workspace_manifest_path_hash ( hash_dir : & PathBuf ) -> PathBuf {
688
731
// Since the hash will change between test runs simply find the first directories and assume
689
732
// that is the hash dir. The format is a 2 char directory followed by the remaining hash in the
You can’t perform that action at this time.
0 commit comments