aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authororwell96 <orwell@bleipb.de>2021-05-03 22:05:30 +0200
committerorwell96 <orwell@bleipb.de>2021-05-03 22:05:30 +0200
commitd4593491efbcab47efd918d7918b97b4621828b3 (patch)
tree97c6f688fb8dc18fe409cc72b46502b1e9fbc44b
parent28bc9ef07f0a8b809d17e949c9a9fb223bfc3e65 (diff)
downloadadvtrains-d4593491efbcab47efd918d7918b97b4621828b3.tar.gz
advtrains-d4593491efbcab47efd918d7918b97b4621828b3.tar.bz2
advtrains-d4593491efbcab47efd918d7918b97b4621828b3.zip
Strip trailing \r's also for first and last line
-rw-r--r--serialize.lua4
1 files changed, 4 insertions, 0 deletions
diff --git a/serialize.lua b/serialize.lua
index f1175ef..78ddcfd 100644
--- a/serialize.lua
+++ b/serialize.lua
@@ -205,6 +205,8 @@ end
-- config: see above
local function read_from_fd(file)
local first_line = file:read("*line")
+ -- possibly windows fix: strip trailing \r's from line
+ first_line = string.gsub(first_line, "\r$", "")
if not string.match(first_line, "LUA_SER v=[12]") then
file:close()
error("Expected header, got '"..first_line.."' instead!")
@@ -212,6 +214,8 @@ local function read_from_fd(file)
local t = {}
read_table(t, file)
local last_line = file:read("*line")
+ -- possibly windows fix: strip trailing \r's from line
+ last_line = string.gsub(last_line, "\r$", "")
file:close()
if last_line ~= "END_SER" then
error("Missing END_SER, got '"..last_line.."' instead!")