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 /src/builtin.jq | |
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 'src/builtin.jq')
-rw-r--r-- | src/builtin.jq | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/src/builtin.jq b/src/builtin.jq index 2b8263c7..802595ba 100644 --- a/src/builtin.jq +++ b/src/builtin.jq @@ -74,6 +74,8 @@ def fromdateiso8601: strptime("%Y-%m-%dT%H:%M:%SZ")|mktime; def todateiso8601: strftime("%Y-%m-%dT%H:%M:%SZ"); def fromdate: fromdateiso8601; def todate: todateiso8601; +def ltrimstr($left): if startswith($left) then .[$left | length:] end; +def rtrimstr($right): if endswith($right) then .[:$right | -length] end; def match(re; mode): _match_impl(re; mode; false)|.[]; def match($val): ($val|type) as $vt | if $vt == "string" then match($val; null) elif $vt == "array" and ($val | length) > 1 then match($val[0]; $val[1]) |