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"
483
483
description = " Returns a substring that starts at the specified character position and contains the specified number of characters"
484
484
invoked = " substring function"
485
485
startIndexNegative = " Start index cannot be negative"
486
- lengthNegative = " Length cannot be negative"
487
486
startIndexTooLarge = " Start index is beyond the end of the string"
487
+ startIndexValueTooLarge = " Start index value too large"
488
+ lengthNegative = " Length cannot be negative"
488
489
lengthTooLarge = " Length extends beyond the end of the string"
490
+ lengthValueTooLarge = " Length value too large"
489
491
490
492
[functions .sub ]
491
493
description = " 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 {
43
43
) ) ;
44
44
}
45
45
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
+ } ) ?;
47
52
let string_length = string_to_parse. chars ( ) . count ( ) ;
48
53
49
54
if start_index > string_length {
@@ -65,7 +70,12 @@ impl Function for Substring {
65
70
) ) ;
66
71
}
67
72
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
+ } ) ?;
69
79
70
80
if start_index + length > string_length {
71
81
return Err ( DscError :: FunctionArg (
@@ -220,3 +230,4 @@ mod tests {
220
230
assert_eq ! ( result, Value :: String ( "" . to_string( ) ) ) ;
221
231
}
222
232
}
233
+
You can’t perform that action at this time.
0 commit comments