@@ -31,9 +31,17 @@ impl Function for Path {
31
31
debug ! ( "Executing path function with args: {:?}" , args) ;
32
32
33
33
let mut path = PathBuf :: new ( ) ;
34
+ let mut first = true ;
34
35
for arg in args {
35
36
if let Value :: String ( s) = arg {
36
- path. push ( s) ;
37
+ // if first argument is a drive letter, add it with a separator suffix as PathBuf.push() doesn't add it
38
+ if first && s. len ( ) == 2 && s. chars ( ) . nth ( 1 ) . unwrap ( ) == ':' {
39
+ path. push ( s. to_owned ( ) + std:: path:: MAIN_SEPARATOR . to_string ( ) . as_str ( ) ) ;
40
+ first = false ;
41
+ continue ;
42
+ } else {
43
+ path. push ( s) ;
44
+ }
37
45
} else {
38
46
return Err ( DscError :: Parser ( "Arguments must all be strings" . to_string ( ) ) ) ;
39
47
}
@@ -48,6 +56,22 @@ mod tests {
48
56
use crate :: configure:: context:: Context ;
49
57
use crate :: parser:: Statement ;
50
58
59
+ #[ test]
60
+ fn start_with_drive_letter ( ) {
61
+ let mut parser = Statement :: new ( ) . unwrap ( ) ;
62
+ let separator = std:: path:: MAIN_SEPARATOR ;
63
+ let result = parser. parse_and_execute ( "[path('C:','test')]" , & Context :: new ( ) ) . unwrap ( ) ;
64
+ assert_eq ! ( result, format!( "C:{separator}test" ) ) ;
65
+ }
66
+
67
+ #[ test]
68
+ fn drive_letter_in_middle ( ) {
69
+ let mut parser = Statement :: new ( ) . unwrap ( ) ;
70
+ let separator = std:: path:: MAIN_SEPARATOR ;
71
+ let result = parser. parse_and_execute ( "[path('a','C:','test')]" , & Context :: new ( ) ) . unwrap ( ) ;
72
+ assert_eq ! ( result, format!( "a{separator}C:{separator}test" ) ) ;
73
+ }
74
+
51
75
#[ test]
52
76
fn two_args ( ) {
53
77
let mut parser = Statement :: new ( ) . unwrap ( ) ;
0 commit comments