Skip to content

Truly independent web browser

LibWeb: Search only new EventSource body bytes for a line break

Shannon Booth13924a5d11c1
diff --git a/Libraries/LibWeb/Bindings/Rust/src/html/event_source.rs b/Libraries/LibWeb/Bindings/Rust/src/html/event_source.rs
index 4d4a8260e1a..2b5f812fa7d 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/html/event_source.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/html/event_source.rs
@@ -356,13 +356,15 @@ impl EventSource {
pub(crate) fn process_body_chunk(this: Ref<Self>, vm: &Vm, body: &[u8]) {
let mut pending_data = this.pending_data.borrow_mut();
+ // The bytes kept from earlier chunks hold no line break.
+ let kept_length = pending_data.len();
pending_data.extend_from_slice(body);
- let Some(last_line_break) = pending_data.iter().rposition(|byte| *byte == b'\r' || *byte == b'\n') else {
+ let Some(last_line_break) = body.iter().rposition(|byte| *byte == b'\r' || *byte == b'\n') else {
return;
};
- let end_index = last_line_break + 1;
+ let end_index = kept_length + last_line_break + 1;
let response: Vec<u8> = pending_data.drain(..end_index).collect();
drop(pending_data);