@@ -1499,12 +1499,16 @@ fn parse_reference(name: &str) -> Option<RecipeReference> {
14991499 || name. starts_with ( "..\\ " )
15001500 {
15011501 let path = name. replace ( '\\' , "/" ) ;
1502- let mut components: Vec < String > = path. split ( '/' ) . map ( String :: from) . skip ( 1 ) . collect ( ) ;
1502+ let mut components: Vec < String > = path. split ( '/' ) . map ( String :: from) . collect ( ) ;
15031503 let file_stem = components. pop ( ) . unwrap ( ) ;
1504- Some ( RecipeReference {
1505- components,
1506- name : file_stem,
1507- } )
1504+ if !file_stem. is_empty ( ) {
1505+ Some ( RecipeReference {
1506+ components,
1507+ name : file_stem,
1508+ } )
1509+ } else {
1510+ None
1511+ }
15081512 } else {
15091513 None
15101514 }
@@ -1520,15 +1524,15 @@ mod tests {
15201524 assert_eq ! (
15211525 parse_reference( "./pasta/spaghetti" ) ,
15221526 Some ( RecipeReference {
1523- components: vec![ "pasta" . to_string( ) ] ,
1527+ components: vec![ "." . to_string ( ) , " pasta". to_string( ) ] ,
15241528 name: "spaghetti" . into( )
15251529 } )
15261530 ) ;
15271531
15281532 assert_eq ! (
15291533 parse_reference( "../sauces/tomato" ) ,
15301534 Some ( RecipeReference {
1531- components: vec![ "sauces" . to_string( ) ] ,
1535+ components: vec![ ".." . to_string ( ) , " sauces". to_string( ) ] ,
15321536 name: "tomato" . into( )
15331537 } )
15341538 ) ;
@@ -1537,15 +1541,15 @@ mod tests {
15371541 assert_eq ! (
15381542 parse_reference( r#".\pasta\spaghetti"# ) ,
15391543 Some ( RecipeReference {
1540- components: vec![ "pasta" . to_string( ) ] ,
1544+ components: vec![ "." . to_string ( ) , " pasta". to_string( ) ] ,
15411545 name: "spaghetti" . into( )
15421546 } )
15431547 ) ;
15441548
15451549 assert_eq ! (
15461550 parse_reference( r#"..\sauces\tomato"# ) ,
15471551 Some ( RecipeReference {
1548- components: vec![ "sauces" . to_string( ) ] ,
1552+ components: vec![ ".." . to_string ( ) , " sauces". to_string( ) ] ,
15491553 name: "tomato" . into( )
15501554 } )
15511555 ) ;
@@ -1555,6 +1559,7 @@ mod tests {
15551559 parse_reference( "./recipes/italian/pasta/spaghetti" ) ,
15561560 Some ( RecipeReference {
15571561 components: vec![
1562+ "." . to_string( ) ,
15581563 "recipes" . to_string( ) ,
15591564 "italian" . to_string( ) ,
15601565 "pasta" . to_string( )
@@ -1567,7 +1572,16 @@ mod tests {
15671572 assert_eq ! (
15681573 parse_reference( "./spaghetti" ) ,
15691574 Some ( RecipeReference {
1570- components: vec![ ] ,
1575+ components: vec![ "." . to_string( ) ] ,
1576+ name: "spaghetti" . into( )
1577+ } )
1578+ ) ;
1579+
1580+ // Test paths with upper directories
1581+ assert_eq ! (
1582+ parse_reference( "./../../spaghetti" ) ,
1583+ Some ( RecipeReference {
1584+ components: vec![ "." . to_string( ) , ".." . to_string( ) , ".." . to_string( ) ] ,
15711585 name: "spaghetti" . into( )
15721586 } )
15731587 ) ;
@@ -1578,5 +1592,19 @@ mod tests {
15781592 assert_eq ! ( parse_reference( "pasta\\ spaghetti" ) , None ) ;
15791593 assert_eq ! ( parse_reference( "/pasta/spaghetti" ) , None ) ;
15801594 assert_eq ! ( parse_reference( "\\ pasta\\ spaghetti" ) , None ) ;
1595+ assert_eq ! ( parse_reference( "./" ) , None ) ;
1596+ assert_eq ! ( parse_reference( ".\\ " ) , None ) ;
1597+ assert_eq ! ( parse_reference( "../" ) , None ) ;
1598+ assert_eq ! ( parse_reference( "..\\ " ) , None ) ;
1599+
1600+ // Test path generation
1601+ let reference = RecipeReference {
1602+ components : vec ! [ "." . to_string( ) ] ,
1603+ name : "Sicilian-style Scottadito Lamb Chops" . into ( ) ,
1604+ } ;
1605+ assert_eq ! (
1606+ "./Sicilian-style Scottadito Lamb Chops" ,
1607+ reference. path( "/" )
1608+ ) ;
15811609 }
15821610}
0 commit comments