File tree Expand file tree Collapse file tree 1 file changed +6
-5
lines changed
Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change @@ -51,11 +51,11 @@ pub use metrics::METRIC_OPERATION_ERRORS_TOTAL;
5151/// - level > 0: the path label will be the path split by "/" and get the last n level,
5252/// if n=1 and input path is "abc/def/ghi", and then we'll use "abc/" as the path label.
5353pub fn path_label_value ( path : & str , level : usize ) -> Option < & str > {
54- if path. is_empty ( ) {
55- return None ;
56- }
57-
5854 if level > 0 {
55+ if path. is_empty ( ) {
56+ return Some ( "" ) ;
57+ }
58+
5959 let label_value = path
6060 . char_indices ( )
6161 . filter ( |& ( _, c) | c == '/' )
@@ -80,6 +80,7 @@ mod tests {
8080 assert_eq ! ( path_label_value( path, 3 ) , Some ( "abc/def/ghi" ) ) ;
8181 assert_eq ! ( path_label_value( path, usize :: MAX ) , Some ( "abc/def/ghi" ) ) ;
8282
83- assert_eq ! ( path_label_value( "" , 1 ) , None ) ;
83+ assert_eq ! ( path_label_value( "" , 0 ) , None ) ;
84+ assert_eq ! ( path_label_value( "" , 1 ) , Some ( "" ) ) ;
8485 }
8586}
You can’t perform that action at this time.
0 commit comments