diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d96b5839..f21d58034 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -112,6 +112,7 @@ BUG FIXES: [GH-2766] - provisioners/salt: Fix case when salt would say "options only allowed before install arguments" [GH-3005] + - provisioners/shell: Error if script is encoded incorrectly. [GH-3000] - synced\_folders/nfs: NFS entries are pruned on every `vagrant up`, if there are any to prune. [GH-2738] diff --git a/lib/vagrant.rb b/lib/vagrant.rb index b6ebe659d..3fc960fd4 100644 --- a/lib/vagrant.rb +++ b/lib/vagrant.rb @@ -1,6 +1,3 @@ -# This file is load before RubyGems are loaded, and allow us to actually -# resolve plugin dependencies and load the proper versions of everything. - require "vagrant/shared_helpers" if Vagrant.plugins_enabled? && !defined?(Bundler) diff --git a/plugins/provisioners/shell/config.rb b/plugins/provisioners/shell/config.rb index 2c98468b2..0e4c071d0 100644 --- a/plugins/provisioners/shell/config.rb +++ b/plugins/provisioners/shell/config.rb @@ -46,11 +46,20 @@ module VagrantPlugins end # If it is not an URL, we validate the existence of a script to upload - if path && ! remote? + if path && !remote? expanded_path = Pathname.new(path).expand_path(machine.env.root_path) if !expanded_path.file? errors << I18n.t("vagrant.provisioners.shell.path_invalid", :path => expanded_path) + else + data = expanded_path.read(16) + if !data.valid_encoding? + errors << I18n.t( + "vagrant.provisioners.shell.invalid_encoding", + actual: data.encoding.to_s, + default: Encoding.default_external.to_s, + path: expanded_path.to_s) + end end end diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 275a6d2a5..e96774c50 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -1523,6 +1523,9 @@ en: shell: args_bad_type: "Shell provisioner `args` must be a string or array." + invalid_encoding: |- + Invalid encoding '%{actual}' for script at '%{path}'. + Must be '%{default}' or UTF-8. no_path_or_inline: "One of `path` or `inline` must be set." path_and_inline_set: "Only one of `path` or `inline` may be set." path_invalid: "`path` for shell provisioner does not exist on the host system: %{path}"