mirror of
https://github.com/ankitects/anki.git
synced 2026-06-29 15:06:42 +00:00
Anki is a smart spaced repetition flashcard program
https://apps.ankiweb.net
## Linked issue (required) Fixes https://github.com/ankitects/anki/issues/5046 Fixes https://github.com/ankitects/anki/issues/4215 Related: https://forums.ankiweb.net/t/search-search-problem-in-browse-windows/38603 ## Summary / motivation (required) When the browser search query contains non-breaking spaces (for e.g., when text is copied and pasted from a webpage or a card rendered in the reviewer webview), the parser embeds the \u{a0} characters inside the SQL query rather than treating them as word separators. SQL then tries to search them as literal substrings, which never matches the note's stored field text (which uses normal spaces), resulting in zero results even though matching notes exist. The fix normalizes \u{a0} to a regular space in parse(), before any parsing begins, so it is consistently treated as a word separator everywhere. ## Steps to reproduce (required, use N/A if not applicable) 1. Create a note with the text "hello world". 2. Copy text having a non-breaking space between "hello world" into the browser's search bar (I am unable to paste a sample here) and press Enter. 3. See that no results are returned. ## How to test (required) In this branch, the same steps return the note as expected. Checking the SQL query: Apply this patch, set environment variable `set RUST_LOG=anki=debug` before running Anki and then repeat the repro steps: ```diff diff --git a/rslib/src/search/mod.rs b/rslib/src/search/mod.rs index 0dd52dbc3..4fdab340c 100644 --- a/rslib/src/search/mod.rs +++ b/rslib/src/search/mod.rs @@ -24,6 +24,7 @@ use rusqlite::params_from_iter; use rusqlite::types::FromSql; use sqlwriter::RequiredTable; use sqlwriter::SqlWriter; +use tracing::debug; pub use writer::replace_search_node; use crate::browser_table::Column; @@ -189,6 +190,7 @@ impl Collection { let (mut sql, args) = writer.build_query(&top_node, mode.required_table())?; self.add_order(&mut sql, item_type, mode)?; + debug!(sql = %sql, args = ?args); let mut stmt = self.storage.db.prepare(&sql)?; let ids: Vec<_> = stmt ``` On the main branch, the terminal prints: ``` DEBUG sql=select c.id from cards c, notes n where c.nid=n.id and ((n.sfld like ?1 escape '\' or n.flds like ?1 escape '\')) order by c.mod desc args=["%hello\u{a0}world%"] ``` On this branch, the terminal prints: ``` DEBUG sql=select c.id from cards c, notes n where c.nid=n.id and ((n.sfld like ?1 escape '\' or n.flds like ?1 escape '\') and (n.sfld like ?2 escape '\' or n.flds like ?2 escape '\')) order by c.mod desc args=["%hello%", "%world%"] ``` ### Checklist (minimum) - [ ] I ran `./ninja check` or an equivalent relevant check locally. - [x] I added or updated tests when the change is non-trivial or behavior changed. ### Details <!-- Commands, manual steps, edge cases, and what you observed --> ## Before / after behavior (optional) <!-- For bugfixes: behavior before vs after. For other types: N/A or a short note. --> ## Risk / compatibility / migration (optional) <!-- Breaking changes, rollout notes, or N/A for small / low-risk PRs --> ## UI evidence (required for visual changes; otherwise N/A) <!-- Screenshot or short video --> ## Scope - [x] This PR is focused on one change (no unrelated edits). --------- Co-authored-by: Abdo <abdo@abdnh.net> |
||
|---|---|---|
| .cargo | ||
| .config | ||
| .cursor/rules | ||
| .github | ||
| .idea.dist | ||
| .vscode.dist | ||
| build | ||
| cargo | ||
| docs | ||
| docs-site | ||
| ftl | ||
| proto | ||
| pylib | ||
| python | ||
| qt | ||
| rslib | ||
| tools | ||
| ts | ||
| .complexipy.toml | ||
| .deny.toml | ||
| .dockerignore | ||
| .dprint.json | ||
| .eslintrc.cjs | ||
| .gitattributes | ||
| .gitignore | ||
| .gitmodules | ||
| .mypy.ini | ||
| .pre-commit-config.yaml | ||
| .prettierrc | ||
| .python-version | ||
| .readthedocs.yaml | ||
| .ruff.toml | ||
| .rustfmt-empty.toml | ||
| .rustfmt.toml | ||
| .version | ||
| .yarnrc.yml | ||
| AGENTS.md | ||
| Cargo.lock | ||
| Cargo.toml | ||
| check | ||
| CLAUDE.md | ||
| CONTRIBUTORS | ||
| justfile | ||
| LICENSE | ||
| ninja | ||
| package.json | ||
| playwright.config.ts | ||
| pyproject.toml | ||
| README.md | ||
| release.just | ||
| run | ||
| run.bat | ||
| rust-toolchain.toml | ||
| SECURITY.md | ||
| uv.lock | ||
| yarn | ||
| yarn.bat | ||
| yarn.lock | ||
Anki
This repo contains the source code for the computer version of Anki.
About
Anki is a spaced repetition program. Please see the website to learn more.
Getting Started
Contributing
Want to contribute to Anki? Check out the Contribution Guidelines.
For more information on building and developing, please see Development.
Contributors
The following people have contributed to Anki: CONTRIBUTORS
Anki Betas
If you'd like to try development builds of Anki but don't feel comfortable building the code, please see Anki betas.
License
Anki's license: LICENSE