From cfc253ffb580bd30cb004ad3bf4e72b3314791e0 Mon Sep 17 00:00:00 2001 From: mpeterv Date: Sat, 17 Oct 2015 11:41:26 +0300 Subject: Fix empty line handling in patch.lua Interpret empty lines in hunk bodies as empty context lines, that is, add a space to them. This is consistent with command-line patch tool behaviour. Fixes #434. --- src/luarocks/tools/patch.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/luarocks/tools/patch.lua b/src/luarocks/tools/patch.lua index b53bad61..9e5074ad 100644 --- a/src/luarocks/tools/patch.lua +++ b/src/luarocks/tools/patch.lua @@ -200,8 +200,13 @@ function patch.read_patch(filename, data) if state == 'hunkbody' then -- skip hunkskip and hunkbody code until definition of hunkhead read + if line:match"^[\r\n]*$" then + -- prepend space to empty lines to interpret them as context properly + line = " " .. line + end + -- process line first - if line:match"^[- +\\]" or line:match"^[\r\n]*$" then + if line:match"^[- +\\]" then -- gather stats about line endings local he = files.hunkends[nextfileno] if endswith(line, "\r\n") then -- cgit v1.2.3-55-g6feb