diff options
author | Emanuele Torre <torreemanuele6@gmail.com> | 2023-12-09 20:46:38 +0100 |
---|---|---|
committer | Nico Williams <nico@cryptonector.com> | 2024-01-16 16:57:37 -0600 |
commit | 1f1e619f4e1478598aca56115948eb14d484b9fe (patch) | |
tree | 06820f0c606b99a01f6784810c80954d3600cc0f /tests | |
parent | 71e7bcdfc154ddbd27b80c840f35b52cb9d66215 (diff) |
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.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/jq.test | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/jq.test b/tests/jq.test index 7036df2c..b94f29d2 100644 --- a/tests/jq.test +++ b/tests/jq.test @@ -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"] |