builtins: make ltrimstr and rtrimstr error for non-string inputs
Previously, ltrimstr/rtrimstr would just let the input pass through for non-string inputs or arguments. That was happening because, they were leaking the errors returned by startswith/endswith treating them as if they were jv_false(). The leak was resolved by #2977 for 1.7.1 This patch rewrites ltrimstr and rtrimstr in jq, and makes them not ignore startswith and endswith errors anymore.
This commit is contained in:
1 parent
71e7bcdfc1
commit
1f1e619f4e
3 files changed
+18
-33
No files matched your search
@@ -2115,3 +2115,19 @@ try ltrimstr("x") catch "x", try rtrimstr("x") catch "x" | "ok"
|
||||
{"hey":[]}
|
||||
"ok"
|
||||
"ok"
|
||||
|
||||
# ltrimstr/1 and rtrimstr/1 return an error for non-strings. #2969
|
||||
|
||||
.[] as [$x, $y] | try ["ok", ($x | ltrimstr($y))] catch ["ko", .]
|
||||
[["hi",1],[1,"hi"],["hi","hi"],[1,1]]
|
||||
["ko","startswith() requires string inputs"]
|
||||
["ko","startswith() requires string inputs"]
|
||||
["ok",""]
|
||||
["ko","startswith() requires string inputs"]
|
||||
|
||||
.[] as [$x, $y] | try ["ok", ($x | rtrimstr($y))] catch ["ko", .]
|
||||
[["hi",1],[1,"hi"],["hi","hi"],[1,1]]
|
||||
["ko","endswith() requires string inputs"]
|
||||
["ko","endswith() requires string inputs"]
|
||||
["ok",""]
|
||||
["ko","endswith() requires string inputs"]
|
||||
Reference in new issue
Block a user