From 1f1e619f4e1478598aca56115948eb14d484b9fe Mon Sep 17 00:00:00 2001 From: Emanuele Torre Date: Sat, 9 Dec 2023 20:46:38 +0100 Subject: 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. --- tests/jq.test | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'tests') 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"] -- cgit v1.2.3