From 7cb81e4c226f16191de2b20ef452d433f8d9ebaa Mon Sep 17 00:00:00 2001 From: eliasjlara Date: Mon, 15 Sep 2025 20:48:01 +0200 Subject: [PATCH 1/2] add support for newlines in search --- pylib/tests/test_find.py | 9 +++++++++ rslib/src/search/parser.rs | 8 ++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/pylib/tests/test_find.py b/pylib/tests/test_find.py index 236096572..45c47011c 100644 --- a/pylib/tests/test_find.py +++ b/pylib/tests/test_find.py @@ -309,3 +309,12 @@ def test_findDupes(): assert not r # front isn't dupe assert col.find_dupes("Front") == [] + + +def test_find_cards_with_newlines(): + col = getEmptyCol() + note = col.newNote() + note["Front"] = "foo" + note["Back"] = "foo
bar" + col.addNote(note) + assert len(col.find_cards("foo\nbar")) == 1 diff --git a/rslib/src/search/parser.rs b/rslib/src/search/parser.rs index 33c1a4622..e3771bab5 100644 --- a/rslib/src/search/parser.rs +++ b/rslib/src/search/parser.rs @@ -204,7 +204,7 @@ fn group_inner(input: &str) -> IResult<'_, Vec> { } fn whitespace0(s: &str) -> IResult<'_, Vec> { - many0(one_of(" \u{3000}")).parse(s) + many0(one_of(" \n\u{3000}")).parse(s) } /// Optional leading space, then a (negated) group or text @@ -248,7 +248,7 @@ fn quoted_term(s: &str) -> IResult<'_, Node> { /// eg deck:"foo bar" - quotes must come after the : fn partially_quoted_term(s: &str) -> IResult<'_, Node> { let (remaining, (key, val)) = separated_pair( - escaped(is_not("\"(): \u{3000}\\"), '\\', none_of(" \u{3000}")), + escaped(is_not("\"(): \n\u{3000}\\"), '\\', none_of(" \n\u{3000}")), char(':'), quoted_term_str, ) @@ -261,7 +261,7 @@ fn partially_quoted_term(s: &str) -> IResult<'_, Node> { /// Unquoted text, terminated by whitespace or unescaped ", ( or ) fn unquoted_term(s: &str) -> IResult<'_, Node> { - match escaped(is_not("\"() \u{3000}\\"), '\\', none_of(" \u{3000}"))(s) { + match escaped(is_not("\"() \n\u{3000}\\"), '\\', none_of(" \n\u{3000}"))(s) { Ok((tail, term)) => { if term.is_empty() { Err(parse_error(s)) @@ -281,7 +281,7 @@ fn unquoted_term(s: &str) -> IResult<'_, Node> { provided: format!("\\{c}"), }, )) - } else if "\"() \u{3000}".contains(s.chars().next().unwrap()) { + } else if "\"() \n\u{3000}".contains(s.chars().next().unwrap()) { Err(parse_error(s)) } else { // input ends in an odd number of backslashes From 9a72ab514ce729a8b2ea4f6527f2a65504d780db Mon Sep 17 00:00:00 2001 From: Elias <94451739+eliasjlara@users.noreply.github.com> Date: Tue, 16 Sep 2025 07:34:42 +0200 Subject: [PATCH 2/2] Add name to CONTRIBUTORS --- CONTRIBUTORS | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 70032a23c..5904ccd4f 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -241,6 +241,7 @@ Siyuan Mattuwu Yan Lee Doughty <32392044+leedoughty@users.noreply.github.com> memchr Aldlss +Elias Johansson Lara ********************