Skip to content

Commit

Permalink
Fix BOM stripping in UTF-aware environments
Browse files Browse the repository at this point in the history
  • Loading branch information
mpeterv committed Jul 14, 2015
1 parent ea6680f commit b6ca668
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/luacheck/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ function utils.read_file(file)
local res = handler:read("*a")
handler:close()

if res and res:sub(1, #bom) == bom then
res = res:sub(#bom + 1)
-- Use :len() instead of # operator because in some environments
-- string library is patched to handle UTF.
if res and res:sub(1, bom:len()) == bom then
res = res:sub(bom:len() + 1)
end

return res
Expand Down

0 comments on commit b6ca668

Please sign in to comment.