mirror of
https://github.com/nushell/nushell.git
synced 2024-11-24 17:34:00 +01:00
fixed issue with find not working with symbols that should be escaped (#13792)
# Description Thanks to @weirdan's suggestion, this now works. ![image](https://github.com/user-attachments/assets/34522c7b-b012-4f73-883d-9913142e85b9) Closes #13789
This commit is contained in:
parent
b2cab3274b
commit
870eb2530c
@ -193,7 +193,8 @@ pub fn highlight_search_string(
|
||||
string_style: &Style,
|
||||
highlight_style: &Style,
|
||||
) -> Result<String, ShellError> {
|
||||
let regex_string = format!("(?i){needle}");
|
||||
let escaped_needle = regex::escape(needle);
|
||||
let regex_string = format!("(?i){escaped_needle}");
|
||||
let regex = match Regex::new(®ex_string) {
|
||||
Ok(regex) => regex,
|
||||
Err(err) => {
|
||||
|
@ -138,3 +138,63 @@ fn find_in_table_keeps_row_with_multiple_matched_and_keeps_other_columns() {
|
||||
assert!(actual.out.contains("bill"));
|
||||
assert!(actual.out.contains("60"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn find_with_string_search_with_special_char_1() {
|
||||
let actual = nu!("[[d]; [a?b] [a*b] [a{1}b] ] | find '?' | to json -r");
|
||||
|
||||
assert_eq!(
|
||||
actual.out,
|
||||
"[{\"d\":\"\\u001b[37ma\\u001b[0m\\u001b[41;37m?\\u001b[0m\\u001b[37mb\\u001b[0m\"}]"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn find_with_string_search_with_special_char_2() {
|
||||
let actual = nu!("[[d]; [a?b] [a*b] [a{1}b]] | find '*' | to json -r");
|
||||
|
||||
assert_eq!(
|
||||
actual.out,
|
||||
"[{\"d\":\"\\u001b[37ma\\u001b[0m\\u001b[41;37m*\\u001b[0m\\u001b[37mb\\u001b[0m\"}]"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn find_with_string_search_with_special_char_3() {
|
||||
let actual = nu!("[[d]; [a?b] [a*b] [a{1}b] ] | find '{1}' | to json -r");
|
||||
|
||||
assert_eq!(
|
||||
actual.out,
|
||||
"[{\"d\":\"\\u001b[37ma\\u001b[0m\\u001b[41;37m{1}\\u001b[0m\\u001b[37mb\\u001b[0m\"}]"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn find_with_string_search_with_special_char_4() {
|
||||
let actual = nu!("[{d: a?b} {d: a*b} {d: a{1}b} {d: a[]b}] | find '[' | to json -r");
|
||||
|
||||
assert_eq!(
|
||||
actual.out,
|
||||
"[{\"d\":\"\\u001b[37ma\\u001b[0m\\u001b[41;37m[\\u001b[0m\\u001b[37m]b\\u001b[0m\"}]"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn find_with_string_search_with_special_char_5() {
|
||||
let actual = nu!("[{d: a?b} {d: a*b} {d: a{1}b} {d: a[]b}] | find ']' | to json -r");
|
||||
|
||||
assert_eq!(
|
||||
actual.out,
|
||||
"[{\"d\":\"\\u001b[37ma[\\u001b[0m\\u001b[41;37m]\\u001b[0m\\u001b[37mb\\u001b[0m\"}]"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn find_with_string_search_with_special_char_6() {
|
||||
let actual = nu!("[{d: a?b} {d: a*b} {d: a{1}b} {d: a[]b}] | find '[]' | to json -r");
|
||||
|
||||
assert_eq!(
|
||||
actual.out,
|
||||
"[{\"d\":\"\\u001b[37ma\\u001b[0m\\u001b[41;37m[]\\u001b[0m\\u001b[37mb\\u001b[0m\"}]"
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user