From fdb3995141075bbd4a4e97490993dee5288e48da Mon Sep 17 00:00:00 2001 From: historic_bruno Date: Fri, 17 Aug 2012 19:24:23 +0000 Subject: [PATCH] Adds UTF-8 BOM stripping to checkrefs.pl when using JSON files, patch by retrosnub. Refs #1556 This was SVN commit r12456. --- source/tools/entity/checkrefs.pl | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/source/tools/entity/checkrefs.pl b/source/tools/entity/checkrefs.pl index aba2a50de1..3d7d6966e1 100755 --- a/source/tools/entity/checkrefs.pl +++ b/source/tools/entity/checkrefs.pl @@ -372,7 +372,9 @@ sub add_civs push @roots, $f; open my $fh, vfs_to_physical($f) or die "Failed to open '$f': $!"; - my $civ = decode_json(do { local $/; <$fh> }); + # decode_json expects a UTF-8 string and doesn't handle BOMs, so we strip those + # (see http://trac.wildfiregames.com/ticket/1556) + my $civ = decode_json(do { local $/; my $file = <$fh>; $file =~ s/^\xEF\xBB\xBF//; $file }); push @deps, [ $f, "art/textures/ui/" . $civ->{Emblem} ]; @@ -394,7 +396,9 @@ sub add_rms push @roots, $f; open my $fh, vfs_to_physical($f) or die "Failed to open '$f': $!"; - my $rms = decode_json(do { local $/; <$fh> }); + # decode_json expects a UTF-8 string and doesn't handle BOMs, so we strip those + # (see http://trac.wildfiregames.com/ticket/1556) + my $rms = decode_json(do { local $/; my $file = <$fh>; $file =~ s/^\xEF\xBB\xBF//; $file }); push @deps, [ $f, "maps/random/" . $rms->{settings}{Script} ];