From a5a6d5da86ba8bb0bee0b10b3435c1824bca04d6 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Mon, 28 Apr 2014 10:16:28 -0700 Subject: [PATCH] Restore the BOM-skipping logic to the Lua script reader And add BOM to one of the test files to verify it works. --- automation/include/aegisub/unicode.moon | 2 +- libaegisub/lua/script_reader.cpp | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/automation/include/aegisub/unicode.moon b/automation/include/aegisub/unicode.moon index 20e8895e1..8c1d210e5 100644 --- a/automation/include/aegisub/unicode.moon +++ b/automation/include/aegisub/unicode.moon @@ -1,4 +1,4 @@ --- Copyright (c) 2007, Niels Martin Hansen, Rodrigo Braz Monteiro +-- Copyright (c) 2007, Niels Martin Hansen, Rodrigo Braz Monteiro -- All rights reserved. -- -- Redistribution and use in source and binary forms, with or without diff --git a/libaegisub/lua/script_reader.cpp b/libaegisub/lua/script_reader.cpp index 3e525c7d5..53c4f13be 100644 --- a/libaegisub/lua/script_reader.cpp +++ b/libaegisub/lua/script_reader.cpp @@ -38,6 +38,12 @@ namespace agi { namespace lua { auto buff = file.read(); size_t size = static_cast(file.size()); + // Discard the BOM if present + if (size >= 3 && buff[0] == -17 && buff[1] == -69 && buff[2] == -65) { + buff += 3; + size -= 3; + } + if (!agi::fs::HasExtension(filename, "moon")) return luaL_loadbuffer(L, buff, size, filename.string().c_str()) == 0;