@@ -1070,13 +1070,32 @@ impl ResourceDef {
1070
1070
dyn_segment_count += 1 ;
1071
1071
}
1072
1072
1073
+ if is_prefix && has_tail_segment {
1074
+ // tail segments in prefixes have no defined semantics
1075
+
1076
+ #[ cfg( not( test) ) ]
1077
+ log:: warn!(
1078
+ "Prefix resources should not have tail segments. \
1079
+ Use `ResourceDef::new` constructor. \
1080
+ This may become a panic in the future."
1081
+ ) ;
1082
+
1083
+ // panic in tests to make this case detectable
1084
+ #[ cfg( test) ]
1085
+ panic ! ( "prefix resource definitions should not have tail segments" ) ;
1086
+ }
1087
+
1073
1088
if unprocessed. ends_with ( '*' ) {
1074
1089
// unnamed tail segment
1075
1090
1076
1091
#[ cfg( not( test) ) ]
1077
- log:: warn!( "tail segments must have names; consider `{{tail}}*`" ) ;
1092
+ log:: warn!(
1093
+ "Tail segments must have names. \
1094
+ Consider `.../{{tail}}*`. \
1095
+ This may become a panic in the future."
1096
+ ) ;
1078
1097
1079
- // to this case detectable in tests
1098
+ // panic in tests to make this case detectable
1080
1099
#[ cfg( test) ]
1081
1100
panic ! ( "tail segments must have names" ) ;
1082
1101
} else if !has_tail_segment && !unprocessed. is_empty ( ) {
@@ -1197,7 +1216,6 @@ mod tests {
1197
1216
1198
1217
assert_eq ! ( ResourceDef :: new( "/" ) , ResourceDef :: new( [ "/" ] ) ) ;
1199
1218
assert_eq ! ( ResourceDef :: new( "/" ) , ResourceDef :: new( vec![ "/" ] ) ) ;
1200
- assert_eq ! ( ResourceDef :: new( "/{id}*" ) , ResourceDef :: prefix( "/{id}*" ) ) ;
1201
1219
1202
1220
assert_ne ! ( ResourceDef :: new( "" ) , ResourceDef :: prefix( "" ) ) ;
1203
1221
assert_ne ! ( ResourceDef :: new( "/" ) , ResourceDef :: prefix( "/" ) ) ;
@@ -1774,11 +1792,11 @@ mod tests {
1774
1792
#[ test]
1775
1793
#[ should_panic]
1776
1794
fn invalid_unnamed_tail_segment ( ) {
1777
- ResourceDef :: new ( r "/*") ;
1795
+ ResourceDef :: new ( "/*" ) ;
1778
1796
}
1779
1797
1780
1798
#[ test]
1781
- // #[should_panic] // TODO: consider if this should be allowed
1799
+ #[ should_panic]
1782
1800
fn prefix_plus_tail_match_is_allowed ( ) {
1783
1801
ResourceDef :: prefix ( "/user/{id}*" ) ;
1784
1802
}
0 commit comments