From 3130a9c377454551a0eb9e7caa2fecac8f76bd95 Mon Sep 17 00:00:00 2001 From: MinusGix Date: Sat, 26 Nov 2022 13:19:08 -0600 Subject: [PATCH] Limit search response size (#1753) --- CHANGELOG.md | 1 + lapce-proxy/src/dispatch.rs | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 34770166..6df402d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ ### Bug Fixes - [#1737](https://github.com/lapce/lapce/pull/1726): Fix an issue that plugins can't be upgraded - [#1724](https://github.com/lapce/lapce/pull/1724): files and hidden folders no longer will be considered when trying to open a plugin base folder +- [#1753](https://github.com/lapce/lapce/pull/1753): Limit proxy search response size in order to avoid issues with absurdly long lines ## 0.2.4 diff --git a/lapce-proxy/src/dispatch.rs b/lapce-proxy/src/dispatch.rs index 953434dc..5aab8e57 100644 --- a/lapce-proxy/src/dispatch.rs +++ b/lapce-proxy/src/dispatch.rs @@ -304,6 +304,7 @@ fn handle_request(&mut self, id: RequestId, rpc: ProxyRequest) { } => { let workspace = self.workspace.clone(); let proxy_rpc = self.proxy_rpc.clone(); + // Perform the search on another thread to avoid blocking the proxy thread thread::spawn(move || { let result = if let Some(workspace) = workspace.as_ref() { let mut matches = IndexMap::new(); @@ -325,10 +326,20 @@ fn handle_request(&mut self, id: RequestId, rpc: ProxyRequest) { let mymatch = matcher .find(line.as_bytes())? .unwrap(); + // Shorten the line to avoid sending over absurdly long-lines + // (such as in minified javascript) + // Note that the start/end are column based, not absolute from the + // start of the file. + let display_range = mymatch + .start() + .saturating_sub(100) + ..line + .len() + .min(mymatch.end() + 100); line_matches.push(( lnum as usize, (mymatch.start(), mymatch.end()), - line.to_string(), + line[display_range].to_string(), )); Ok(true) }),