Search nested structures recursively in find command (#15850)

# Description

Instead of converting nested structures into strings and
pattern-matching the strings, the `find` command will recursively search
the nested structures for matches.

- fixes #15618 

# User-Facing Changes

Text in nested structures will now be highlighted as well.

Error values will always passed on instead of testing them against the
search term

There will be slight changes in match behavior, such as characters that
are part of the string representations of data structures no longer
matching all nested data structures.
This commit is contained in:
new-years-eve
2025-06-16 22:29:41 +02:00
committed by GitHub
parent 55240d98a5
commit 3db9c81958
2 changed files with 57 additions and 42 deletions

View File

@ -293,3 +293,20 @@ fn find_with_string_search_with_special_char_6() {
);
assert_eq!(actual_no_highlight.out, "[{\"d\":\"a[]b\"}]");
}
#[test]
fn find_in_nested_list_dont_match_bracket() {
let actual = nu!(r#"[ [foo bar] [foo baz] ] | find "[" | to json -r"#);
assert_eq!(actual.out, "[]");
}
#[test]
fn find_and_highlight_in_nested_list() {
let actual = nu!(r#"[ [foo bar] [foo baz] ] | find "foo" | to json -r"#);
assert_eq!(
actual.out,
r#"[["\u001b[37m\u001b[0m\u001b[41;37mfoo\u001b[0m\u001b[37m\u001b[0m","bar"],["\u001b[37m\u001b[0m\u001b[41;37mfoo\u001b[0m\u001b[37m\u001b[0m","baz"]]"#
);
}