Browse Source

Refactor the uri match change

Refactored the uri match fix to also convert numbers within a string to an int.
If it fails it will be null.

Signed-off-by: BlackDex <black.dex@gmail.com>
pull/5339/head
BlackDex 4 months ago
parent
commit
ac6fe5c85e
No known key found for this signature in database GPG Key ID: 58C80A2AA6C765E1
  1. 27
      src/db/models/cipher.rs

27
src/db/models/cipher.rs

@ -241,20 +241,23 @@ impl Cipher {
// NOTE: This was marked as *Backwards Compatibility Code*, but as of January 2021 this is still being used by upstream // NOTE: This was marked as *Backwards Compatibility Code*, but as of January 2021 this is still being used by upstream
// Set the first element of the Uris array as Uri, this is needed several (mobile) clients. // Set the first element of the Uris array as Uri, this is needed several (mobile) clients.
if self.atype == 1 { if self.atype == 1 {
if type_data_json["uris"].is_array() { // Upstream always has an `uri` key/value
// Fix uri match values first, they are only allowed to be a number or null type_data_json["uri"] = Value::Null;
// If it is a string, convert it to null since all clients do not allow strings anyway if let Some(uris) = type_data_json["uris"].as_array_mut() {
let uri_count = type_data_json["uris"].as_array().unwrap().len(); if !uris.is_empty() {
for n in 0..uri_count { // Fix uri match values first, they are only allowed to be a number or null
if type_data_json["uris"][n]["match"].is_string() { // If it is a string, convert it to an int or null if that fails
type_data_json["uris"][n]["match"] = Value::Null; for uri in &mut *uris {
if uri["match"].is_string() {
let match_value = match uri["match"].as_str().unwrap_or_default().parse::<u8>() {
Ok(n) => json!(n),
_ => Value::Null,
};
uri["match"] = match_value;
}
} }
type_data_json["uri"] = uris[0]["uri"].clone();
} }
let uri = type_data_json["uris"][0]["uri"].clone();
type_data_json["uri"] = uri;
} else {
// Upstream always has an Uri key/value
type_data_json["uri"] = Value::Null;
} }
} }

Loading…
Cancel
Save