Skip to content

recurse(f) is not identical to recurse(f; .!=null) #2412

@emanuele6

Description

@emanuele6

Describe the bug
The manual states:

recurse(f) is identical to recurse(f; . != null) and can be used without concern about recursion depth.

That is not actually true: recurse(f) only stops when there is no more input to process, not when . becomes null; it is identical to recurse(f; true).

To Reproduce

bash-5.1$ jq -cn '{foo:{bar:2,foo:{x:3}}} | recurse(.foo; . != null)'
{"foo":{"bar":2,"foo":{"x":3}}}
{"bar":2,"foo":{"x":3}}
{"x":3}

bash-5.1$ jq -cn '{foo:{bar:2,foo:{x:3}}} | recurse(.foo)'  # infinite loop
{"foo":{"bar":2,"foo":{"x":3}}}
{"bar":2,"foo":{"x":3}}
{"x":3}
null
null
null
null
^C

Expected behavior
The current behaviour for recurse(f) is fine as is in my opinion, but the manual is wrong.

Environment (please complete the following information):

  • OS and Version: Arch Linux
  • jq version: 1.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions