Test files for the Byte Order Mask (BOM) (see #9954)
authorAntoine Musso <hashar@users.mediawiki.org>
Fri, 18 May 2007 19:17:21 +0000 (19:17 +0000)
committerAntoine Musso <hashar@users.mediawiki.org>
Fri, 18 May 2007 19:17:21 +0000 (19:17 +0000)
t/maint/bom.t [new file with mode: 0644]

diff --git a/t/maint/bom.t b/t/maint/bom.t
new file mode 100644 (file)
index 0000000..19d74e3
--- /dev/null
@@ -0,0 +1,39 @@
+#!/usr/bin/env perl
+#
+# This test detect Byte Order Mark (BOM). The char is sometime included at the
+# top of files by some text editors to mark them as being UTF-8 encoded.
+# They are not stripped by php 5.x and appear at the beginning of our content,
+# You want them removed!
+# See:
+#   http://www.fileformat.info/info/unicode/char/feff/index.htm
+#   http://bugzilla.wikimedia.org/show_bug.cgi?id=9954
+
+use strict;
+use warnings;
+
+use Test::More;
+
+use File::Find;
+use File::Slurp qw< slurp >;
+
+# Files for wich we want to check the BOM char ( 0xFE 0XFF )
+my $ext = qr/(?:php|inc)/x ;
+
+my $bomchar = qr/\xef\xbb\xbf/ ;
+
+
+my @files;
+
+find( sub{ push @files, $File::Find::name if -f && /\.$ext$/ }, '.' );
+
+# Register our files with the test system
+plan tests => scalar @files ;
+
+for my $file (@files) {
+       my $content = slurp $file ;
+       if( $content =~ /$bomchar/ ) {
+               ok 0 => "$file got a Byte Order Mark";
+       } else {
+               ok 1 => "$file BOM less";
+       }
+}