From 54a7bb2221f4e414613a735c100b5f2ebfad9119 Mon Sep 17 00:00:00 2001 From: Geoff Leyland Date: Thu, 19 Jun 2014 17:52:44 +1200 Subject: [PATCH] Whoops! Trying to find a unicode BOM at the start of a file with an anchored pattern when file_buffer:find doesn't understand anchoring lead to reading the whole file and running out of memory right at the start. Use :sub to check the first few characters of the file --- lua/csv.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lua/csv.lua b/lua/csv.lua index 43507d3..f604653 100644 --- a/lua/csv.lua +++ b/lua/csv.lua @@ -276,11 +276,11 @@ local function separated_values_iterator(buffer, parameters) -- Is there some kind of Unicode BOM here? - if field_find("^\239\187\191") then -- UTF-8 + if field_sub(1, 3) == "\239\187\191" then -- UTF-8 advance(3) - elseif field_find("^\254\255") then -- UTF-16 big-endian + elseif field_sub(1, 2) == "\254\255" then -- UTF-16 big-endian advance(2) - elseif field_find("^\255\254") then -- UTF-16 little-endian + elseif field_sub(1, 2) == "\255\254" then -- UTF-16 little-endian advance(2) end