From e2eac465061b4ec8b186dca0b344afb609e7fbe1 Mon Sep 17 00:00:00 2001 From: Minh Bui <89572023+Phuocminh94@users.noreply.github.com> Date: Thu, 2 Jul 2026 18:02:05 +0700 Subject: [PATCH] fix(googleai): escape raw newlines in stream response to prevent json decode error --- lua/gp/dispatcher.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lua/gp/dispatcher.lua b/lua/gp/dispatcher.lua index c28caba9..343f3a74 100644 --- a/lua/gp/dispatcher.lua +++ b/lua/gp/dispatcher.lua @@ -320,7 +320,12 @@ local query = function(buf, provider, payload, handler, on_exit, callback) if qt.provider == "googleai" then if line:match('"text":') then - content = vim.json.decode("{" .. line .. "}").text + -- Escape raw newlines to prevent json decode from crashing + local sanitized = line:gsub("\r", ""):gsub("\n", "\\n") + local success, decoded = pcall(vim.json.decode, "{" .. sanitized .. "}") + if success and decoded and decoded.text then + content = decoded.text + end end end