Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Task to detect files containing UTF-8 BOM header.

  • Loading branch information...
commit 0dbbed0068ad6adacec90d1f729b45bd5e5e1f5a 1 parent e3c3269
Pavel Kunc authored

Showing 1 changed file with 21 additions and 0 deletions. Show diff stats Hide diff stats

  1. +21 0 lib/tasks/bom.rake
21 lib/tasks/bom.rake
... ... @@ -0,0 +1,21 @@
  1 +desc 'List files containing UTF-8 BOM header; specify format with FORMAT=other'
  2 +task :bom do
  3 + format = ENV['FORMAT'] || 'markdown'
  4 + files = Dir.glob("book-content/**/*.#{format}")
  5 + files.each do |file|
  6 + File.open(file) do |f|
  7 + begin
  8 + has_bom = false
  9 + f.each_with_index do |line, index|
  10 + hex = line.unpack('U'*line.length).collect {|x| x.to_s 16}.join
  11 + has_bom = true if /^feff/ =~ hex
  12 + break
  13 + end
  14 + puts "BOM DETECTED: #{file}" if has_bom
  15 + rescue ArgumentError => e
  16 + # Catch UTF malformed characters exception from unpack()
  17 + puts "#{e.message} in #{file}"
  18 + end
  19 + end
  20 + end
  21 +end

0 comments on commit 0dbbed0

Please sign in to comment.
Something went wrong with that request. Please try again.