File tree 3 files changed +45
-1
lines changed
3 files changed +45
-1
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 @@ -685,7 +685,7 @@ fn template_workspace_path_hash_should_handle_symlink() {
685
685
}
686
686
687
687
#[ cargo_test]
688
- fn template_should_handle_ignore_unmatched_brackets ( ) {
688
+ fn template_should_handle_reject_unmatched_brackets ( ) {
689
689
let p = project ( )
690
690
. file ( "src/lib.rs" , "" )
691
691
. file (
@@ -699,6 +699,11 @@ fn template_should_handle_ignore_unmatched_brackets() {
699
699
700
700
p. cargo ( "build -Z build-dir" )
701
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
+ "# ] ] )
702
707
. run ( ) ;
703
708
704
709
let p = project ( )
@@ -714,6 +719,11 @@ fn template_should_handle_ignore_unmatched_brackets() {
714
719
715
720
p. cargo ( "build -Z build-dir" )
716
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
+ "# ] ] )
717
727
. run ( ) ;
718
728
}
719
729
You can’t perform that action at this time.
0 commit comments