File tree Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -483,9 +483,11 @@ description = "Converts a value to a string"
483483description = " Returns a substring that starts at the specified character position and contains the specified number of characters"
484484invoked = " substring function"
485485startIndexNegative = " Start index cannot be negative"
486- lengthNegative = " Length cannot be negative"
487486startIndexTooLarge = " Start index is beyond the end of the string"
487+ startIndexValueTooLarge = " Start index value too large"
488+ lengthNegative = " Length cannot be negative"
488489lengthTooLarge = " Length extends beyond the end of the string"
490+ lengthValueTooLarge = " Length value too large"
489491
490492[functions .sub ]
491493description = " Subtracts the second number from the first"
Original file line number Diff line number Diff line change @@ -43,7 +43,12 @@ impl Function for Substring {
4343 ) ) ;
4444 }
4545
46- let start_index = start_index_value as usize ;
46+ let start_index = usize:: try_from ( start_index_value) . map_err ( |_| {
47+ DscError :: FunctionArg (
48+ "substring" . to_string ( ) ,
49+ t ! ( "functions.substring.startIndexValueTooLarge" ) . to_string ( ) ,
50+ )
51+ } ) ?;
4752 let string_length = string_to_parse. chars ( ) . count ( ) ;
4853
4954 if start_index > string_length {
@@ -65,7 +70,12 @@ impl Function for Substring {
6570 ) ) ;
6671 }
6772
68- let length = length_value as usize ;
73+ let length = usize:: try_from ( length_value) . map_err ( |_| {
74+ DscError :: FunctionArg (
75+ "substring" . to_string ( ) ,
76+ t ! ( "functions.substring.lengthValueTooLarge" ) . to_string ( ) ,
77+ )
78+ } ) ?;
6979
7080 if start_index + length > string_length {
7181 return Err ( DscError :: FunctionArg (
@@ -220,3 +230,4 @@ mod tests {
220230 assert_eq ! ( result, Value :: String ( "" . to_string( ) ) ) ;
221231 }
222232}
233+
You can’t perform that action at this time.
0 commit comments