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

Fix JSON parsing: make field type optional #212

Closed
Closed
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
2 changes: 1 addition & 1 deletion src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ pub enum LinkedIdType {
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
struct CipherField {
#[serde(rename = "Type", alias = "type")]
ty: FieldType,
ty: Option<FieldType>,
#[serde(rename = "Name", alias = "name")]
name: Option<String>,
#[serde(rename = "Value", alias = "value")]
Expand Down
23 changes: 14 additions & 9 deletions src/bin/rbw/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -742,24 +742,29 @@ struct DecryptedField {
name: Option<String>,
value: Option<String>,
#[serde(serialize_with = "serialize_field_type", rename = "type")]
ty: rbw::api::FieldType,
ty: Option<rbw::api::FieldType>,
}

#[allow(clippy::trivially_copy_pass_by_ref)]
fn serialize_field_type<S>(
ty: &rbw::api::FieldType,
ty: &Option<rbw::api::FieldType>,
serializer: S,
) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
let s = match ty {
rbw::api::FieldType::Text => "text",
rbw::api::FieldType::Hidden => "hidden",
rbw::api::FieldType::Boolean => "boolean",
rbw::api::FieldType::Linked => "linked",
};
serializer.serialize_str(s)
match ty {
Some(ty) => {
let s = match ty {
rbw::api::FieldType::Text => "text",
rbw::api::FieldType::Hidden => "hidden",
rbw::api::FieldType::Boolean => "boolean",
rbw::api::FieldType::Linked => "linked",
};
serializer.serialize_some(&Some(s))
}
None => serializer.serialize_none(),
}
}

#[derive(Debug, Clone, Serialize)]
Expand Down
2 changes: 1 addition & 1 deletion src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ pub enum EntryData {
serde::Serialize, serde::Deserialize, Debug, Clone, Eq, PartialEq,
)]
pub struct Field {
pub ty: crate::api::FieldType,
pub ty: Option<crate::api::FieldType>,
pub name: Option<String>,
pub value: Option<String>,
pub linked_id: Option<crate::api::LinkedIdType>,
Expand Down
Loading