Skip to content

Instantly share code, notes, and snippets.

@jedfoster
Created October 24, 2012 17:56
Show Gist options
  • Save jedfoster/3947705 to your computer and use it in GitHub Desktop.
Save jedfoster/3947705 to your computer and use it in GitHub Desktop.
Thor task to remove BOM from UTF-8 files
# Remove BOM from UTF-8 file
def unbomb(file)
string = File.open(file, 'r:utf-8').read().encode!('utf-8')
if string.start_with?("\uFEFF")
string.sub!(/\uFEFF/, '') # Remove the BOM
create_file file, string, {:force => true, :verbose => false}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment