fix(lsp): blank line before Content-Length breaks header parsing #41524

Problem:
A blank line before the Content-Length header makes header parsing
fail with "Content-Length not found in header". An LF in the 'name'
state falls through to the 'invalid' state, which only return to
'name' at the *next* LF. That LF terminates the next line, so the
line with Content-Length is swallowed.
The same issue happens when a junk line is a partial match of the
header name (e.g. "Cont\nContent-Length: ...").

Solution:
When seeing an LF in the 'name' state, reset the cursor and stay in
'name' rather than entering 'invalid'.
This commit is contained in:
Yanze Li
2026-08-29 06:13:04 -07:00
committed by GitHub
parent cbb0775fb6
commit ab707262b1
2 changed files with 25 additions and 1 deletions

View File

@@ -41,7 +41,9 @@ local function get_content_length(ptr, start, len)
if c >= 65 and c <= 90 then -- lower case
c = c + 32
end
if (c == 32 or c == 9) and j == 1 then -- luacheck: ignore 542
if c == 10 then -- a blank line or a line with a prefix of header
j = 1
elseif (c == 32 or c == 9) and j == 1 then -- luacheck: ignore 542
-- skip OWS for compatibility only
elseif c == name:byte(j) then
j = j + 1