Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ensure empty group name dump to '<Name />' #238

Merged
merged 4 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/xml_db/dump/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ pub(crate) trait DumpXml {
writer: &mut EventWriter<E>,
inner_cipher: &mut dyn Cipher,
) -> Result<(), xml::writer::Error>;

fn normalize_empty_elements(&self) -> bool {
false
}
}

impl DumpXml for &chrono::NaiveDateTime {
Expand Down Expand Up @@ -96,6 +100,10 @@ impl DumpXml for &str {
) -> Result<(), xml::writer::Error> {
writer.write(WriterEvent::characters(self))
}

fn normalize_empty_elements(&self) -> bool {
self.is_empty()
}
}

impl DumpXml for &String {
Expand All @@ -106,6 +114,10 @@ impl DumpXml for &String {
) -> Result<(), xml::writer::Error> {
writer.write(WriterEvent::characters(self))
}

fn normalize_empty_elements(&self) -> bool {
self.is_empty()
}
}

impl DumpXml for &Uuid {
Expand Down Expand Up @@ -139,7 +151,9 @@ impl<S: AsRef<str>, D: DumpXml> DumpXml for SimpleTag<S, D> {
inner_cipher: &mut dyn Cipher,
) -> Result<(), xml::writer::Error> {
writer.write(WriterEvent::start_element(self.0.as_ref()))?;
self.1.dump_xml(writer, inner_cipher)?;
if !self.1.normalize_empty_elements() {
self.1.dump_xml(writer, inner_cipher)?;
}
writer.write(WriterEvent::end_element())?;
Ok(())
}
Expand Down
10 changes: 9 additions & 1 deletion src/xml_db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ mod tests {
use uuid::uuid;

use crate::{
config::DatabaseConfig,
config::{DatabaseConfig, InnerCipherConfig},
db::{
entry::History,
meta::{BinaryAttachments, CustomIcons, Icon, MemoryProtection},
Expand All @@ -26,6 +26,7 @@ mod tests {
},
format::kdbx4,
key::DatabaseKey,
xml_db::dump::DumpXml,
};

fn make_key() -> DatabaseKey {
Expand Down Expand Up @@ -125,6 +126,13 @@ mod tests {

#[test]
pub fn test_group() {
let group = Group::new("");
let mut inner_cipher = InnerCipherConfig::Plain.get_cipher(&[]).unwrap();
let mut writer = xml::EventWriter::new(Vec::new());
let _v = group.dump_xml(&mut writer, &mut *inner_cipher).unwrap();
let xml = writer.into_inner();
assert!(String::from_utf8(xml).unwrap().contains("<Name />"));

let mut root_group = Group::new("Root");
let mut entry = Entry::new();
let new_entry_uuid = entry.uuid.clone();
Expand Down