provisioners/shell: error if invalid encoding [GH-3000]

This commit is contained in:
Mitchell Hashimoto 2014-02-23 21:50:53 -08:00
parent 095f6d63c5
commit a667893cbf
4 changed files with 14 additions and 4 deletions

View File

@ -112,6 +112,7 @@ BUG FIXES:
[GH-2766] [GH-2766]
- provisioners/salt: Fix case when salt would say "options only allowed - provisioners/salt: Fix case when salt would say "options only allowed
before install arguments" [GH-3005] 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`, - synced\_folders/nfs: NFS entries are pruned on every `vagrant up`,
if there are any to prune. [GH-2738] if there are any to prune. [GH-2738]

View File

@ -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" require "vagrant/shared_helpers"
if Vagrant.plugins_enabled? && !defined?(Bundler) if Vagrant.plugins_enabled? && !defined?(Bundler)

View File

@ -46,11 +46,20 @@ module VagrantPlugins
end end
# If it is not an URL, we validate the existence of a script to upload # 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) expanded_path = Pathname.new(path).expand_path(machine.env.root_path)
if !expanded_path.file? if !expanded_path.file?
errors << I18n.t("vagrant.provisioners.shell.path_invalid", errors << I18n.t("vagrant.provisioners.shell.path_invalid",
:path => expanded_path) :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
end end

View File

@ -1523,6 +1523,9 @@ en:
shell: shell:
args_bad_type: "Shell provisioner `args` must be a string or array." 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." 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_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}" path_invalid: "`path` for shell provisioner does not exist on the host system: %{path}"