Merge pull request #801 from abdnh/strip-quotes
Strip double quotes from names
This commit is contained in:
commit
87770db7f1
@ -581,7 +581,7 @@ class CardLayout(QDialog):
|
||||
|
||||
def onRename(self):
|
||||
template = self.current_template()
|
||||
name = getOnlyText(_("New name:"), default=template["name"])
|
||||
name = getOnlyText(_("New name:"), default=template["name"]).strip('"')
|
||||
if not name.strip():
|
||||
return
|
||||
|
||||
|
@ -80,7 +80,7 @@ class FieldDialog(QDialog):
|
||||
self.loadField(idx)
|
||||
|
||||
def _uniqueName(self, prompt, ignoreOrd=None, old=""):
|
||||
txt = getOnlyText(prompt, default=old)
|
||||
txt = getOnlyText(prompt, default=old).strip('"')
|
||||
if not txt:
|
||||
return
|
||||
for f in self.model["flds"]:
|
||||
|
@ -85,8 +85,9 @@ class Models(QDialog):
|
||||
def onRename(self) -> None:
|
||||
nt = self.current_notetype()
|
||||
txt = getText(_("New name:"), default=nt["name"])
|
||||
if txt[1] and txt[0]:
|
||||
nt["name"] = txt[0]
|
||||
name = txt[0].strip('"')
|
||||
if txt[1] and name:
|
||||
nt["name"] = name
|
||||
self.saveAndRefresh(nt)
|
||||
|
||||
def saveAndRefresh(self, nt: NoteType) -> None:
|
||||
@ -119,7 +120,7 @@ class Models(QDialog):
|
||||
def onAdd(self) -> None:
|
||||
m = AddModel(self.mw, self).get()
|
||||
if m:
|
||||
txt = getText(_("Name:"), default=m["name"])[0]
|
||||
txt = getText(_("Name:"), default=m["name"])[0].strip('"')
|
||||
if txt:
|
||||
m["name"] = txt
|
||||
self.saveAndRefresh(m)
|
||||
|
@ -37,7 +37,7 @@ impl NoteField {
|
||||
|
||||
pub(crate) fn fix_name(&mut self) {
|
||||
// remove special characters
|
||||
let bad_chars = |c| c == ':' || c == '{' || c == '}';
|
||||
let bad_chars = |c| c == ':' || c == '{' || c == '}' || c == '"';
|
||||
if self.name.contains(bad_chars) {
|
||||
self.name = self.name.replace(bad_chars, "");
|
||||
}
|
||||
|
@ -223,8 +223,13 @@ impl NoteType {
|
||||
if self.templates.is_empty() {
|
||||
return Err(AnkiError::invalid_input("1 template required"));
|
||||
}
|
||||
let bad_chars = |c| c == '"';
|
||||
if self.name.contains(bad_chars) {
|
||||
self.name = self.name.replace(bad_chars, "");
|
||||
}
|
||||
self.normalize_names();
|
||||
self.fix_field_names();
|
||||
self.fix_template_names();
|
||||
self.ensure_names_unique();
|
||||
self.reposition_sort_idx();
|
||||
|
||||
@ -322,6 +327,10 @@ impl NoteType {
|
||||
self.fields.iter_mut().for_each(NoteField::fix_name);
|
||||
}
|
||||
|
||||
fn fix_template_names(&mut self) {
|
||||
self.templates.iter_mut().for_each(CardTemplate::fix_name);
|
||||
}
|
||||
|
||||
/// Find the field index of the provided field name.
|
||||
pub(crate) fn get_field_ord(&self, field_name: &str) -> Option<usize> {
|
||||
let field_name = UniCase::new(field_name);
|
||||
|
@ -88,4 +88,11 @@ impl CardTemplate {
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn fix_name(&mut self) {
|
||||
let bad_chars = |c| c == '"';
|
||||
if self.name.contains(bad_chars) {
|
||||
self.name = self.name.replace(bad_chars, "");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ fn is_tag_separator(c: char) -> bool {
|
||||
}
|
||||
|
||||
fn invalid_char_for_tag(c: char) -> bool {
|
||||
c.is_ascii_control() || is_tag_separator(c)
|
||||
c.is_ascii_control() || is_tag_separator(c) || c == '"'
|
||||
}
|
||||
|
||||
impl Collection {
|
||||
|
Loading…
Reference in New Issue
Block a user