mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
Expect backslashes to be escaped in dupe:
text
This commit is contained in:
parent
f4cfccfc0a
commit
d9bb20ac24
2 changed files with 17 additions and 2 deletions
|
@ -399,7 +399,7 @@ fn parse_dupe(val: &str) -> ParseResult<SearchNode> {
|
||||||
let text = it.next().ok_or(ParseError {})?;
|
let text = it.next().ok_or(ParseError {})?;
|
||||||
Ok(SearchNode::Duplicates {
|
Ok(SearchNode::Duplicates {
|
||||||
note_type_id: mid,
|
note_type_id: mid,
|
||||||
text: unescape_quotes(text),
|
text: unescape_quotes_and_backslashes(text),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -478,6 +478,15 @@ fn unescape_quotes(s: &str) -> Cow<str> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// For non-globs like dupe text without any assumption about the content
|
||||||
|
fn unescape_quotes_and_backslashes(s: &str) -> Cow<str> {
|
||||||
|
if s.contains('"') || s.contains('\\') {
|
||||||
|
s.replace(r#"\""#, "\"").replace(r"\\", r"\").into()
|
||||||
|
} else {
|
||||||
|
s.into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Unescape chars with special meaning to the parser.
|
/// Unescape chars with special meaning to the parser.
|
||||||
fn unescape(txt: &str) -> ParseResult<Cow<str>> {
|
fn unescape(txt: &str) -> ParseResult<Cow<str>> {
|
||||||
if is_invalid_escape(txt) {
|
if is_invalid_escape(txt) {
|
||||||
|
|
|
@ -119,7 +119,7 @@ fn write_search_node(node: &SearchNode) -> String {
|
||||||
NoteType(s) => quote(&format!("note:{}", s)),
|
NoteType(s) => quote(&format!("note:{}", s)),
|
||||||
Rated { days, ease } => write_rated(days, ease),
|
Rated { days, ease } => write_rated(days, ease),
|
||||||
Tag(s) => quote(&format!("tag:{}", s)),
|
Tag(s) => quote(&format!("tag:{}", s)),
|
||||||
Duplicates { note_type_id, text } => quote(&format!("dupe:{},{}", note_type_id, text)),
|
Duplicates { note_type_id, text } => write_dupe(note_type_id, text),
|
||||||
State(k) => write_state(k),
|
State(k) => write_state(k),
|
||||||
Flag(u) => format!("\"flag:{}\"", u),
|
Flag(u) => format!("\"flag:{}\"", u),
|
||||||
NoteIDs(s) => format!("\"nid:{}\"", s),
|
NoteIDs(s) => format!("\"nid:{}\"", s),
|
||||||
|
@ -163,6 +163,12 @@ fn write_rated(days: &u32, ease: &EaseKind) -> String {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Escape double quotes and backslashes: \"
|
||||||
|
fn write_dupe(note_type_id: &NoteTypeIDType, text: &str) -> String {
|
||||||
|
let esc = text.replace(r"\", r"\\").replace('"', r#"\""#);
|
||||||
|
format!("\"dupe:{},{}\"", note_type_id, esc)
|
||||||
|
}
|
||||||
|
|
||||||
fn write_state(kind: &StateKind) -> String {
|
fn write_state(kind: &StateKind) -> String {
|
||||||
use StateKind::*;
|
use StateKind::*;
|
||||||
format!(
|
format!(
|
||||||
|
|
Loading…
Reference in a new issue