Skip to content

Commit

Permalink
Merge branch 'master' into ignore_save_kdbx4_code
Browse files Browse the repository at this point in the history
  • Loading branch information
sseemayer authored Aug 26, 2024
2 parents 14b3942 + b33d1fb commit 76858b5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
30 changes: 18 additions & 12 deletions src/db/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,31 @@ use crate::db::{
};

pub enum SearchField {
#[cfg(test)]
UUID,
Title,
}

impl SearchField {
pub(crate) fn matches(&self, node: &Node, field_value: &str) -> bool {
let uuid = match node {
Node::Entry(e) => e.uuid,
Node::Group(g) => g.uuid,
};
let title = match node {
Node::Entry(e) => e.get_title(),
Node::Group(g) => Some(g.get_name()),
};
match self {
SearchField::UUID => uuid.to_string() == field_value,
#[cfg(test)]
SearchField::UUID => {
let uuid = match node {
Node::Entry(e) => e.uuid,
Node::Group(g) => g.uuid,
};
uuid.to_string() == field_value
}
SearchField::Title => {
if let Some(title) = title {
return title == field_value;
let title = match node {
Node::Entry(e) => e.get_title(),
Node::Group(g) => Some(g.get_name()),
};
match title {
Some(t) => t == field_value,
None => false,
}
return false;
}
}
}
Expand Down Expand Up @@ -120,6 +124,7 @@ impl Group {
self.get_internal(&path, SearchField::Title)
}

#[cfg(test)]
pub(crate) fn get_by_uuid<'a, T: AsRef<str>>(&'a self, path: &[T]) -> Option<NodeRef<'a>> {
self.get_internal(&path, SearchField::UUID)
}
Expand Down Expand Up @@ -156,6 +161,7 @@ impl Group {
self.get_mut_internal(path, SearchField::Title)
}

#[cfg(test)]
pub(crate) fn get_by_uuid_mut<'a, T: AsRef<str>>(&'a mut self, path: &[T]) -> Option<NodeRefMut<'a>> {
self.get_mut_internal(path, SearchField::UUID)
}
Expand Down
3 changes: 3 additions & 0 deletions src/xml_db/parse/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ mod parse_group_test {
let value = parse_test_xml::<Group>("");
assert!(matches!(value, Err(XmlParseError::BadEvent { .. })));

let value = parse_test_xml::<Group>("<Group><Name></Name></Group>")?;
assert_eq!(value.name, "".to_string());

let value = parse_test_xml::<Group>("<TestTag>SomeData</TestTag>");
assert!(matches!(value, Err(XmlParseError::BadEvent { .. })));

Expand Down

0 comments on commit 76858b5

Please sign in to comment.