mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
Use enforced re to parse deck
Fix write_deck not recognising escaped deck name separators: \:\: -> ::
This commit is contained in:
parent
a6628709c5
commit
7c5cf6d18b
2 changed files with 13 additions and 13 deletions
|
@ -68,7 +68,7 @@ pub(super) enum SearchNode<'a> {
|
|||
AddedInDays(u32),
|
||||
EditedInDays(u32),
|
||||
CardTemplate(TemplateKind<'a>),
|
||||
Deck(Cow<'a, str>),
|
||||
Deck(String),
|
||||
DeckID(DeckID),
|
||||
NoteTypeID(NoteTypeID),
|
||||
NoteType(OptionalRe<'a>),
|
||||
|
@ -279,7 +279,7 @@ fn search_node_for_text_with_argument<'a>(
|
|||
Ok(match key.to_ascii_lowercase().as_str() {
|
||||
"added" => SearchNode::AddedInDays(val.parse()?),
|
||||
"edited" => SearchNode::EditedInDays(val.parse()?),
|
||||
"deck" => SearchNode::Deck(unescape_quotes(val)),
|
||||
"deck" => SearchNode::Deck(unescape_to_enforced_re(val, ".")?),
|
||||
"note" => SearchNode::NoteType(unescape_to_re(val)?),
|
||||
"tag" => SearchNode::Tag(unescape_to_enforced_re(val, r"\S")?),
|
||||
"mid" => SearchNode::NoteTypeID(val.parse()?),
|
||||
|
|
|
@ -9,7 +9,6 @@ use crate::{
|
|||
err::Result,
|
||||
notes::field_checksum,
|
||||
notetype::NoteTypeID,
|
||||
text::text_to_re,
|
||||
text::{normalize_to_nfc, strip_html_preserving_image_filenames, without_combining},
|
||||
timestamp::TimestampSecs,
|
||||
};
|
||||
|
@ -295,25 +294,26 @@ impl SqlWriter<'_> {
|
|||
|
||||
fn write_deck(&mut self, deck: &str) -> Result<()> {
|
||||
match deck {
|
||||
"*" => write!(self.sql, "true").unwrap(),
|
||||
".*" => write!(self.sql, "true").unwrap(),
|
||||
"filtered" => write!(self.sql, "c.odid != 0").unwrap(),
|
||||
deck => {
|
||||
// rewrite "current" to the current deck name
|
||||
let native_deck = if deck == "current" {
|
||||
let current_did = self.col.get_current_deck_id();
|
||||
regex::escape(
|
||||
self.col
|
||||
.storage
|
||||
.get_deck(current_did)?
|
||||
.map(|d| d.name)
|
||||
.unwrap_or_else(|| "Default".into())
|
||||
.as_str(),
|
||||
)
|
||||
} else {
|
||||
human_deck_name_to_native(deck)
|
||||
};
|
||||
|
||||
// convert to a regex that includes child decks
|
||||
// fixme: use unescape_to_enforced_re from parser.rs?
|
||||
let re = text_to_re(&native_deck);
|
||||
self.args.push(format!("(?i)^{}($|\x1f)", re));
|
||||
self.args.push(format!("(?i)^{}($|\x1f)", native_deck));
|
||||
let arg_idx = self.args.len();
|
||||
self.sql.push_str(&format!(concat!(
|
||||
"(c.did in (select id from decks where name regexp ?{n})",
|
||||
|
|
Loading…
Reference in a new issue