Skip to content

Commit

Permalink
fix: filter out and skip message if empty within attachment (#646)
Browse files Browse the repository at this point in the history
  • Loading branch information
dariusc93 authored Dec 13, 2024
1 parent 5513ff2 commit fdb96da
Showing 1 changed file with 2 additions and 16 deletions.
18 changes: 2 additions & 16 deletions extensions/warp-ipfs/src/store/message/attachment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,29 +84,15 @@ impl AttachmentStream {
}

pub fn set_lines(mut self, lines: Vec<String>) -> Result<Self, Error> {
if lines.is_empty() {
return Ok(self);
}

let lines_value_length: usize = lines
.iter()
.filter(|s| !s.is_empty())
.map(|s| s.trim())
.map(|s| s.chars().count())
.sum();

if lines_value_length < MIN_MESSAGE_SIZE {
tracing::error!(
current_size = lines_value_length,
min = MIN_MESSAGE_SIZE,
"length of message is invalid"
);
return Err(Error::InvalidLength {
context: "message".into(),
current: lines_value_length,
minimum: None,
maximum: Some(MIN_MESSAGE_SIZE),
});
if lines.is_empty() || lines_value_length < MIN_MESSAGE_SIZE {
return Ok(self);
}

if lines_value_length > MAX_MESSAGE_SIZE {
Expand Down

0 comments on commit fdb96da

Please sign in to comment.