It isn't certain that the script has the same encoding as Ruby think it ...

...has.

Try to work around this by checking that the script's encoding is valid. If
it isn't if will first try UTF-8 and if that fails iso-8859-15.

See issue #3000