Skip to content
Snippets Groups Projects
Commit 446cb24c authored by 🥺's avatar 🥺 :transgender_flag: Committed by 🥺
Browse files

use Default value of 0 if BE array is not valid

parent 6c7bc8d7
No related branches found
No related tags found
No related merge requests found
...@@ -142,10 +142,13 @@ fn get_url_preview(&self, url: &str) -> Option<UrlPreviewData> { ...@@ -142,10 +142,13 @@ fn get_url_preview(&self, url: &str) -> Option<UrlPreviewData> {
let mut values = values.split(|&b| b == 0xFF); let mut values = values.split(|&b| b == 0xFF);
let _ts = match values.next().map(|b| u64::from_be_bytes(b.try_into().expect("valid BE array"))) { let _ts = values.next();
/* if we ever decide to use timestamp, this is here.
match values.next().map(|b| u64::from_be_bytes(b.try_into().expect("valid BE array"))) {
Some(0) => None, Some(0) => None,
x => x, x => x,
}; };*/
let title = match values.next().and_then(|b| String::from_utf8(b.to_vec()).ok()) { let title = match values.next().and_then(|b| String::from_utf8(b.to_vec()).ok()) {
Some(s) if s.is_empty() => None, Some(s) if s.is_empty() => None,
x => x, x => x,
...@@ -158,15 +161,15 @@ fn get_url_preview(&self, url: &str) -> Option<UrlPreviewData> { ...@@ -158,15 +161,15 @@ fn get_url_preview(&self, url: &str) -> Option<UrlPreviewData> {
Some(s) if s.is_empty() => None, Some(s) if s.is_empty() => None,
x => x, x => x,
}; };
let image_size = match values.next().map(|b| usize::from_be_bytes(b.try_into().expect("valid BE array"))) { let image_size = match values.next().map(|b| usize::from_be_bytes(b.try_into().unwrap_or_default())) {
Some(0) => None, Some(0) => None,
x => x, x => x,
}; };
let image_width = match values.next().map(|b| u32::from_be_bytes(b.try_into().expect("valid BE array"))) { let image_width = match values.next().map(|b| u32::from_be_bytes(b.try_into().unwrap_or_default())) {
Some(0) => None, Some(0) => None,
x => x, x => x,
}; };
let image_height = match values.next().map(|b| u32::from_be_bytes(b.try_into().expect("valid BE array"))) { let image_height = match values.next().map(|b| u32::from_be_bytes(b.try_into().unwrap_or_default())) {
Some(0) => None, Some(0) => None,
x => x, x => x,
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment