summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.markdown16
-rw-r--r--lib/puppet/parser/functions/ensure_packages.rb2
-rw-r--r--lib/puppet/provider/file_line/ruby.rb2
-rw-r--r--lib/puppet/type/file_line.rb21
-rwxr-xr-xspec/acceptance/type_spec.rb2
-rw-r--r--spec/aliases/absolute_path_spec.rb4
-rw-r--r--spec/aliases/httpsurl_spec.rb6
-rw-r--r--spec/aliases/httpurl_spec.rb6
-rw-r--r--spec/aliases/ipv6_spec.rb14
-rw-r--r--spec/aliases/unixpath_spec.rb6
-rw-r--r--spec/aliases/windowspath_spec.rb7
-rwxr-xr-xspec/functions/concat_spec.rb5
-rwxr-xr-xspec/functions/defined_with_params_spec.rb5
-rw-r--r--spec/functions/dig44_spec.rb26
-rw-r--r--spec/functions/dos2unix_spec.rb17
-rwxr-xr-xspec/functions/ensure_packages_spec.rb7
-rwxr-xr-xspec/functions/getparam_spec.rb8
-rwxr-xr-xspec/functions/is_mac_address_spec.rb6
-rwxr-xr-xspec/functions/keys_spec.rb5
-rwxr-xr-xspec/functions/load_module_metadata_spec.rb10
-rw-r--r--spec/functions/loadjson_spec.rb6
-rwxr-xr-xspec/functions/loadyaml_spec.rb4
-rwxr-xr-xspec/functions/parsejson_spec.rb11
-rwxr-xr-xspec/functions/parseyaml_spec.rb11
-rwxr-xr-xspec/functions/range_spec.rb8
-rw-r--r--spec/functions/seeded_rand_spec.rb5
-rwxr-xr-xspec/functions/squeeze_spec.rb6
-rwxr-xr-xspec/functions/validate_ipv6_address_spec.rb10
-rwxr-xr-xspec/unit/puppet/type/file_line_spec.rb25
-rw-r--r--types/compat/ipv6.pp2
30 files changed, 237 insertions, 26 deletions
diff --git a/README.markdown b/README.markdown
index a4c30b5..c8c2819 100644
--- a/README.markdown
+++ b/README.markdown
@@ -118,6 +118,22 @@ In this code example, `match` looks for a line beginning with export
followed by HTTP_PROXY and delete it. If multiple lines match, an
error will be raised unless the `multiple => true` parameter is set.
+Encoding example:
+
+ file_line { "XScreenSaver":
+ ensure => present,
+ path => '/root/XScreenSaver'
+ line => "*lock: 10:00:00",
+ match => '^*lock:',
+ encoding => "iso-8859-1",
+ }
+
+Files with special characters that are not valid UTF-8 will give the
+error message "invalid byte sequence in UTF-8". In this case, determine
+the correct file encoding and specify the correct encoding using the
+encoding attribute, the value of which needs to be a valid Ruby character
+encoding.
+
**Autorequires:** If Puppet is managing the file that contains the line being managed, the `file_line` resource autorequires that file.
##### Parameters
diff --git a/lib/puppet/parser/functions/ensure_packages.rb b/lib/puppet/parser/functions/ensure_packages.rb
index 504273d..17942b8 100644
--- a/lib/puppet/parser/functions/ensure_packages.rb
+++ b/lib/puppet/parser/functions/ensure_packages.rb
@@ -36,7 +36,9 @@ third argument to the ensure_resource() function.
Puppet::Parser::Functions.function(:ensure_resource)
packages.each { |package_name|
+ if !findresource("Package[#{package_name}]")
function_ensure_resource(['package', package_name, defaults ])
+ end
}
end
end
diff --git a/lib/puppet/provider/file_line/ruby.rb b/lib/puppet/provider/file_line/ruby.rb
index beeb430..fbf7d8e 100644
--- a/lib/puppet/provider/file_line/ruby.rb
+++ b/lib/puppet/provider/file_line/ruby.rb
@@ -40,7 +40,7 @@ Puppet::Type.type(:file_line).provide(:ruby) do
# file; for now assuming that this type is only used on
# small-ish config files that can fit into memory without
# too much trouble.
- @lines ||= File.readlines(resource[:path])
+ @lines ||= File.readlines(resource[:path], :encoding => resource[:encoding])
end
def match_regex
diff --git a/lib/puppet/type/file_line.rb b/lib/puppet/type/file_line.rb
index 7b7d44e..e82b246 100644
--- a/lib/puppet/type/file_line.rb
+++ b/lib/puppet/type/file_line.rb
@@ -48,6 +48,22 @@ Puppet::Type.newtype(:file_line) do
followed by HTTP_PROXY and delete it. If multiple lines match, an
error will be raised unless the `multiple => true` parameter is set.
+ Encoding example:
+
+ file_line { "XScreenSaver":
+ ensure => present,
+ path => '/root/XScreenSaver'
+ line => "*lock: 10:00:00",
+ match => '^*lock:',
+ encoding => "iso-8859-1",
+ }
+
+ Files with special characters that are not valid UTF-8 will give the
+ error message "invalid byte sequence in UTF-8". In this case, determine
+ the correct file encoding and specify the correct encoding using the
+ encoding attribute, the value of which needs to be a valid Ruby character
+ encoding.
+
**Autorequires:** If Puppet is managing the file that will contain the line
being managed, the file_line resource will autorequire that file.
EOT
@@ -107,6 +123,11 @@ Puppet::Type.newtype(:file_line) do
defaultto true
end
+ newparam(:encoding) do
+ desc 'For files that are not UTF-8 encoded, specify encoding such as iso-8859-1'
+ defaultto 'UTF-8'
+ end
+
# Autorequire the file resource if it's being managed
autorequire(:file) do
self[:path]
diff --git a/spec/acceptance/type_spec.rb b/spec/acceptance/type_spec.rb
index 7cf445b..5cc9470 100755
--- a/spec/acceptance/type_spec.rb
+++ b/spec/acceptance/type_spec.rb
@@ -12,7 +12,7 @@ describe 'type function' do
EOS
apply_manifest(pp, :catch_failures => true) do |r|
- expect(r.stdout).to match(/type is Tuple\[String, String, String, String\]/)
+ expect(r.stdout).to match(/type is Tuple\[String.*, String.*, String.*, String.*\]/)
end
end
it 'types strings' do
diff --git a/spec/aliases/absolute_path_spec.rb b/spec/aliases/absolute_path_spec.rb
index 3fb9d12..eeda76a 100644
--- a/spec/aliases/absolute_path_spec.rb
+++ b/spec/aliases/absolute_path_spec.rb
@@ -15,6 +15,8 @@ if Puppet.version.to_f >= 4.5
/
/var/tmp
/var/opt/../lib/puppet
+ /var/ůťƒ8
+ /var/ネット
}.each do |value|
describe value.inspect do
let(:params) {{ value: value }}
@@ -50,6 +52,8 @@ if Puppet.version.to_f >= 4.5
etc/puppetlabs/puppet
opt/puppet/bin
relative\\windows
+ \var\ůťƒ8
+ \var\ネット
}.each do |value|
describe value.inspect do
let(:params) {{ value: value }}
diff --git a/spec/aliases/httpsurl_spec.rb b/spec/aliases/httpsurl_spec.rb
index 97ae006..9cc9a76 100644
--- a/spec/aliases/httpsurl_spec.rb
+++ b/spec/aliases/httpsurl_spec.rb
@@ -7,6 +7,8 @@ if Puppet.version.to_f >= 4.5
https://hello.com
https://notcreative.org
https://notexciting.co.uk
+ https://graphemica.com/❤
+ https://graphemica.com/緩
}.each do |value|
describe value.inspect do
let(:params) {{ value: value }}
@@ -26,7 +28,9 @@ if Puppet.version.to_f >= 4.5
'',
"httds://notquiteright.org",
"hptts:/nah",
- "https;//notrightbutclose.org"
+ "https;//notrightbutclose.org",
+ "http://graphemica.com/❤",
+ "http://graphemica.com/緩"
].each do |value|
describe value.inspect do
let(:params) {{ value: value }}
diff --git a/spec/aliases/httpurl_spec.rb b/spec/aliases/httpurl_spec.rb
index 8bd57ca..f92ddb3 100644
--- a/spec/aliases/httpurl_spec.rb
+++ b/spec/aliases/httpurl_spec.rb
@@ -10,6 +10,8 @@ if Puppet.version.to_f >= 4.5
http://anhttp.com
http://runningoutofideas.gov
http://
+ http://graphemica.com/❤
+ http://graphemica.com/緩
}.each do |value|
describe value.inspect do
let(:params) {{ value: value }}
@@ -29,7 +31,9 @@ if Puppet.version.to_f >= 4.5
'',
"httds://notquiteright.org",
"hptts:/nah",
- "https;//notrightbutclose.org"
+ "https;//notrightbutclose.org",
+ "hts://graphemica.com/❤",
+ "https:graphemica.com/緩"
].each do |value|
describe value.inspect do
let(:params) {{ value: value }}
diff --git a/spec/aliases/ipv6_spec.rb b/spec/aliases/ipv6_spec.rb
index 13d7c3e..6237eba 100644
--- a/spec/aliases/ipv6_spec.rb
+++ b/spec/aliases/ipv6_spec.rb
@@ -5,7 +5,14 @@ if Puppet.version.to_f >= 4.5
describe 'accepts ipv6 addresses' do
[
'2001:0db8:85a3:0000:0000:8a2e:0370:7334',
- 'fa76:8765:34ac:0823:ab76:eee9:0987:1111'
+ 'fa76:8765:34ac:0823:ab76:eee9:0987:1111',
+ 'fe80:0000:0000:0000:0204:61ff:fe9d:f156',
+ 'fe80:0:0:0:204:61ff:fe9d:f156',
+ 'fe80::204:61ff:fe9d:f156',
+ 'fe80:0:0:0:0204:61ff:254.157.241.86',
+ '::1',
+ 'fe80::',
+ '2001::',
].each do |value|
describe value.inspect do
let(:params) {{ value: value }}
@@ -18,7 +25,10 @@ if Puppet.version.to_f >= 4.5
'nope',
'77',
'4.4.4',
- '2000:7334'
+ '2000:7334',
+ '::ffff:2.3.4',
+ '::ffff:257.1.2.3',
+ '::ffff:12345678901234567890.1.26',
].each do |value|
describe value.inspect do
let(:params) {{ value: value }}
diff --git a/spec/aliases/unixpath_spec.rb b/spec/aliases/unixpath_spec.rb
index aee161d..7824cb6 100644
--- a/spec/aliases/unixpath_spec.rb
+++ b/spec/aliases/unixpath_spec.rb
@@ -7,6 +7,8 @@ if Puppet.version.to_f >= 4.5
/usr2/username/bin:/usr/local/bin:/usr/bin:.
/var/tmp
/Users/helencampbell/workspace/puppetlabs-stdlib
+ /var/ůťƒ8
+ /var/ネット
}.each do |value|
describe value.inspect do
let(:params) {{ value: value }}
@@ -27,7 +29,9 @@ if Puppet.version.to_f >= 4.5
"C:/whatever",
"\\var\\tmp",
"\\Users/hc/wksp/stdlib",
- "*/Users//nope"
+ "*/Users//nope",
+ "var\ůťƒ8",
+ "var\ネット"
].each do |value|
describe value.inspect do
let(:params) {{ value: value }}
diff --git a/spec/aliases/windowspath_spec.rb b/spec/aliases/windowspath_spec.rb
index c13794e..b8ddcb7 100644
--- a/spec/aliases/windowspath_spec.rb
+++ b/spec/aliases/windowspath_spec.rb
@@ -10,6 +10,8 @@ if Puppet.version.to_f >= 4.5
X:/foo/bar
X:\\foo\\bar
\\\\host\\windows
+ X:/var/ůťƒ8
+ X:/var/ネット
}.each do |value|
describe value.inspect do
let(:params) {{ value: value }}
@@ -30,7 +32,9 @@ if Puppet.version.to_f >= 4.5
"httds://notquiteright.org",
"/usr2/username/bin:/usr/local/bin:/usr/bin:.",
"C;//notright/here",
- "C:noslashes"
+ "C:noslashes",
+ "C:ネット",
+ "C:ůťƒ8"
].each do |value|
describe value.inspect do
let(:params) {{ value: value }}
@@ -38,7 +42,6 @@ if Puppet.version.to_f >= 4.5
end
end
end
-
end
end
end
diff --git a/spec/functions/concat_spec.rb b/spec/functions/concat_spec.rb
index 0e67a60..6ab1b6e 100755
--- a/spec/functions/concat_spec.rb
+++ b/spec/functions/concat_spec.rb
@@ -11,8 +11,11 @@ describe 'concat' do
it { is_expected.to run.with_params(['1','2','3'],[['4','5'],'6']).and_return(['1','2','3',['4','5'],'6']) }
it { is_expected.to run.with_params(['1','2'],['3','4'],['5','6']).and_return(['1','2','3','4','5','6']) }
it { is_expected.to run.with_params(['1','2'],'3','4',['5','6']).and_return(['1','2','3','4','5','6']) }
+
+context 'should run with UTF8 and double byte characters' do
it { is_expected.to run.with_params([{"a" => "b"}], {"c" => "d", "e" => "f"}).and_return([{"a" => "b"}, {"c" => "d", "e" => "f"}]) }
- it { is_expected.to run.with_params(['ấ','β','c'],['đ','ể','ƒ']).and_return(['ấ','β','c','đ','ể','ƒ']) }
+ it { is_expected.to run.with_params(['ấ','β','©'],['đ','ể','文字列']).and_return(['ấ','β','©','đ','ể','文字列']) }
+end
it "should leave the original array intact" do
argument1 = ['1','2','3']
diff --git a/spec/functions/defined_with_params_spec.rb b/spec/functions/defined_with_params_spec.rb
index e2f3abe..a0db0b7 100755
--- a/spec/functions/defined_with_params_spec.rb
+++ b/spec/functions/defined_with_params_spec.rb
@@ -11,6 +11,11 @@ describe 'defined_with_params' do
it { is_expected.to run.with_params('User[dan]', {}).and_return(true) }
it { is_expected.to run.with_params('User[bob]', {}).and_return(false) }
it { is_expected.to run.with_params('User[dan]', {'foo' => 'bar'}).and_return(false) }
+
+ context 'should run with UTF8 and double byte characters' do
+ it { is_expected.to run.with_params('User[ĵĭмოү]', {}).and_return(false) }
+ it { is_expected.to run.with_params('User[ポーラ]', {}).and_return(false) }
+ end
end
describe 'when compared against a resource with attributes' do
diff --git a/spec/functions/dig44_spec.rb b/spec/functions/dig44_spec.rb
index 4f7408d..a7b8a3d 100644
--- a/spec/functions/dig44_spec.rb
+++ b/spec/functions/dig44_spec.rb
@@ -25,6 +25,18 @@ describe 'dig44' do
}
end
+ let(:utf8_data) do
+ {
+ 'ẵ' => {
+ 'в' => [
+ '©',
+ 'ĝ',
+ 'に',
+ ]
+ }
+ }
+ end
+
context 'single values' do
it 'should exist' do
is_expected.not_to be_nil
@@ -100,6 +112,20 @@ describe 'dig44' do
it 'should return "nil" if value is not found and no default value is provided' do
is_expected.to run.with_params(data, %w(a 1)).and_return(nil)
end
+ end
+
+ context 'Internationalization (i18N) values' do
+
+ it 'should be able to return a unicode character' do
+ is_expected.to run.with_params(utf8_data, ['ẵ', 'в', 0]).and_return('©')
+ end
+ it 'should be able to return a utf8 character' do
+ is_expected.to run.with_params(utf8_data, ['ẵ', 'в', 1]).and_return('ĝ')
+ end
+
+ it 'should be able to return a double byte character' do
+ is_expected.to run.with_params(utf8_data, ['ẵ', 'в', 2]).and_return('に')
+ end
end
end
diff --git a/spec/functions/dos2unix_spec.rb b/spec/functions/dos2unix_spec.rb
index 9c84703..97abae7 100644
--- a/spec/functions/dos2unix_spec.rb
+++ b/spec/functions/dos2unix_spec.rb
@@ -29,12 +29,19 @@ describe 'dos2unix' do
end
end
- context 'Converting from unix to unix format' do
- sample_text = "Hello\nWorld\n"
- desired_output = "Hello\nWorld\n"
+ context 'Internationalization (i18N) values' do
+ sample_text_utf8 = "Ħ℮ļłǿ\r\nשׁөŕłđ\r\n"
+ desired_output_utf8 = "Ħ℮ļłǿ\nשׁөŕłđ\n"
- it 'should output unix format' do
- should run.with_params(sample_text).and_return(desired_output)
+ sample_text_doublebyte = "こんにちは\r\n世界\r\n"
+ desired_output_doublebyte = "こんにちは\n世界\n"
+
+ it 'should output uft8 string' do
+ should run.with_params(sample_text_utf8).and_return(desired_output_utf8)
+ end
+
+ it 'should output double byte string' do
+ should run.with_params(sample_text_doublebyte).and_return(desired_output_doublebyte)
end
end
end
diff --git a/spec/functions/ensure_packages_spec.rb b/spec/functions/ensure_packages_spec.rb
index 5d97684..6f94d72 100755
--- a/spec/functions/ensure_packages_spec.rb
+++ b/spec/functions/ensure_packages_spec.rb
@@ -36,9 +36,16 @@ describe 'ensure_packages' do
context 'given hash of packages' do
before { subject.call([{"foo" => { "provider" => "rpm" }, "bar" => { "provider" => "gem" }}, { "ensure" => "present"}]) }
+ before { subject.call([{"パッケージ" => { "ensure" => "absent"}}]) }
+ before { subject.call([{"ρǻ¢κầģẻ" => { "ensure" => "absent"}}]) }
# this lambda is required due to strangeness within rspec-puppet's expectation handling
it { expect(lambda { catalogue }).to contain_package('foo').with({'provider' => 'rpm', 'ensure' => 'present'}) }
it { expect(lambda { catalogue }).to contain_package('bar').with({'provider' => 'gem', 'ensure' => 'present'}) }
+
+ context 'should run with UTF8 and double byte characters' do
+ it { expect(lambda { catalogue }).to contain_package('パッケージ').with({'ensure' => 'absent'}) }
+ it { expect(lambda { catalogue }).to contain_package('ρǻ¢κầģẻ').with({'ensure' => 'absent'}) }
+ end
end
end
diff --git a/spec/functions/getparam_spec.rb b/spec/functions/getparam_spec.rb
index e4ef9e6..522ed3b 100755
--- a/spec/functions/getparam_spec.rb
+++ b/spec/functions/getparam_spec.rb
@@ -24,4 +24,12 @@ describe 'getparam' do
it { is_expected.to run.with_params('User[one]', 'shell').and_return('/bin/sh') }
it { is_expected.to run.with_params('User[one]', 'managehome').and_return(false) }
end
+
+ describe 'when compared against a user resource with UTF8 and double byte params' do
+ let(:pre_condition) { 'user { ["三", "ƒốưř"]: ensure => present }' }
+
+ it { is_expected.to run.with_params('User[三]', 'ensure').and_return('present') }
+ it { is_expected.to run.with_params('User[ƒốưř]', 'ensure').and_return('present') }
+
+ end
end
diff --git a/spec/functions/is_mac_address_spec.rb b/spec/functions/is_mac_address_spec.rb
index 5f76a91..c1e33b8 100755
--- a/spec/functions/is_mac_address_spec.rb
+++ b/spec/functions/is_mac_address_spec.rb
@@ -9,6 +9,12 @@ describe 'is_mac_address' do
it { is_expected.to run.with_params('00:00:00:00:00:0g').and_return(false) }
it { is_expected.to run.with_params('').and_return(false) }
it { is_expected.to run.with_params('one').and_return(false) }
+
+ context 'function can handle UTF8 and double byte characters' do
+ it { is_expected.to run.with_params('ƒốưř').and_return(false) }
+ it { is_expected.to run.with_params('三+').and_return(false) }
+ end
+
it {
pending "should properly typecheck its arguments"
is_expected.to run.with_params(1).and_return(false)
diff --git a/spec/functions/keys_spec.rb b/spec/functions/keys_spec.rb
index 2e009dc..fc7d6d8 100755
--- a/spec/functions/keys_spec.rb
+++ b/spec/functions/keys_spec.rb
@@ -16,4 +16,9 @@ describe 'keys' do
result = subject.call([{ 'key1' => 'value1', 'key2' => 'value2' }])
expect(result).to match_array(['key1', 'key2'])
end
+
+ it 'should run with UTF8 and double byte characters' do
+ result = subject.call([{ 'ҝểү' => '√ẳŀμệ', 'キー' => '値' }])
+ expect(result).to match_array(['ҝểү', 'キー'])
+ end
end
diff --git a/spec/functions/load_module_metadata_spec.rb b/spec/functions/load_module_metadata_spec.rb
index 841cd7d..9496fcb 100755
--- a/spec/functions/load_module_metadata_spec.rb
+++ b/spec/functions/load_module_metadata_spec.rb
@@ -10,6 +10,15 @@ describe 'load_module_metadata' do
allow(File).to receive(:read).with(/\/(stdlib|test)\/metadata.json/, {:encoding=>"utf-8"}).and_return('{"name": "puppetlabs-stdlib"}')
allow(File).to receive(:read).with(/\/(stdlib|test)\/metadata.json/).and_return('{"name": "puppetlabs-stdlib"}')
end
+
+ context "when calling with valid utf8 and double byte character arguments" do
+ before :each do
+ allow(File).to receive(:read).with(/\/(stdlib|test)\/metadata.json/, {:encoding=>"utf-8"}).and_return('{"ĭďèʼnţĩƒіểя": "ċơņťęאּť ỡƒ ţħíš -
+この文字"}')
+ allow(File).to receive(:read).with(/\/(stdlib|test)\/metadata.json/).and_return('{"ĭďèʼnţĩƒіểя": "ċơņťęאּť ỡƒ ţħíš -
+この文字"}')
+ end
+
it "should json parse the file" do
if Puppet::Util::Platform.windows?
allow(scope).to receive(:function_get_module_path).with(['science']).and_return('C:/path/to/module/')
@@ -47,5 +56,6 @@ describe 'load_module_metadata' do
result = subject.call(['science', true])
expect(result).to eq({})
end
+ end
end
end
diff --git a/spec/functions/loadjson_spec.rb b/spec/functions/loadjson_spec.rb
index 26125bc..dbef805 100644
--- a/spec/functions/loadjson_spec.rb
+++ b/spec/functions/loadjson_spec.rb
@@ -23,6 +23,8 @@ describe 'loadjson' do
allow(PSON).to receive(:load).never
}
it { is_expected.to run.with_params(filename, {'default' => 'value'}).and_return({'default' => 'value'}) }
+ it { is_expected.to run.with_params(filename, {'đẽƒằưļŧ' => '٧ẵłựέ'}).and_return({'đẽƒằưļŧ' => '٧ẵłựέ'}) }
+ it { is_expected.to run.with_params(filename, {'デフォルト' => '値'}).and_return({'デフォルト' => '値'}) }
end
context 'when an existing file is specified' do
@@ -33,8 +35,8 @@ describe 'loadjson' do
'/tmp/doesexist'
end
}
- let(:data) { { 'key' => 'value' } }
- let(:json) { '{"key":"value"}' }
+ let(:data) { { 'key' => 'value', 'ķęŷ' => 'νậŀųề', 'キー' => '値'} }
+ let(:json) { '{"key":"value", {"ķęŷ":"νậŀųề" }, {"キー":"値" }' }
before {
allow(File).to receive(:exists?).with(filename).and_return(true).once
allow(File).to receive(:read).with(filename).and_return(json).once
diff --git a/spec/functions/loadyaml_spec.rb b/spec/functions/loadyaml_spec.rb
index 9f16a1a..e9428e3 100755
--- a/spec/functions/loadyaml_spec.rb
+++ b/spec/functions/loadyaml_spec.rb
@@ -11,11 +11,13 @@ describe 'loadyaml' do
YAML.expects(:load_file).never
}
it { is_expected.to run.with_params(filename, {'default' => 'value'}).and_return({'default' => 'value'}) }
+ it { is_expected.to run.with_params(filename, {'đẽƒằưļŧ' => '٧ẵłựέ'}).and_return({'đẽƒằưļŧ' => '٧ẵłựέ'}) }
+ it { is_expected.to run.with_params(filename, {'デフォルト' => '値'}).and_return({'デフォルト' => '値'}) }
end
context 'when an existing file is specified' do
let(:filename) { '/tmp/doesexist' }
- let(:data) { { 'key' => 'value' } }
+ let(:data) { { 'key' => 'value', 'ķęŷ' => 'νậŀųề', 'キー' => '値'} }
before {
File.expects(:exists?).with(filename).returns(true).once
YAML.expects(:load_file).with(filename).returns(data).once
diff --git a/spec/functions/parsejson_spec.rb b/spec/functions/parsejson_spec.rb
index a01f1f6..7b07e49 100755
--- a/spec/functions/parsejson_spec.rb
+++ b/spec/functions/parsejson_spec.rb
@@ -12,12 +12,12 @@ describe 'parsejson' do
context 'with correct JSON data' do
- it 'should be able to parse a JSON data with a Hash' do
+ it 'should be able to parse JSON data with a Hash' do
is_expected.to run.with_params('{"a":"1","b":"2"}').
and_return({'a'=>'1', 'b'=>'2'})
end
- it 'should be able to parse a JSON data with an Array' do
+ it 'should be able to parse JSON data with an Array' do
is_expected.to run.with_params('["a","b","c"]').
and_return(['a', 'b', 'c'])
end
@@ -29,11 +29,16 @@ describe 'parsejson' do
and_return({})
end
- it 'should be able to parse a JSON data with a mixed structure' do
+ it 'should be able to parse JSON data with a mixed structure' do
is_expected.to run.with_params('{"a":"1","b":2,"c":{"d":[true,false]}}').
and_return({'a' =>'1', 'b' => 2, 'c' => { 'd' => [true, false] } })
end
+ it 'should be able to parse JSON data with a UTF8 and double byte characters' do
+ is_expected.to run.with_params('{"×":"これ","ý":"記号","です":{"©":["Á","ß"]}}').
+ and_return({'×' =>'これ', 'ý' => '記号', 'です' => { '©' => ['Á', 'ß'] } })
+ end
+
it 'should not return the default value if the data was parsed correctly' do
is_expected.to run.with_params('{"a":"1"}', 'default_value').
and_return({'a' => '1'})
diff --git a/spec/functions/parseyaml_spec.rb b/spec/functions/parseyaml_spec.rb
index fa947ca..c2a138c 100755
--- a/spec/functions/parseyaml_spec.rb
+++ b/spec/functions/parseyaml_spec.rb
@@ -18,21 +18,26 @@ describe 'parseyaml' do
and_return('just a string')
end
- it 'should be able to parse a YAML data with a Hash' do
+ it 'should be able to parse YAML data with a Hash' do
is_expected.to run.with_params("---\na: '1'\nb: '2'\n").
and_return({'a' => '1', 'b' => '2'})
end
- it 'should be able to parse a YAML data with an Array' do
+ it 'should be able to parse YAML data with an Array' do
is_expected.to run.with_params("---\n- a\n- b\n- c\n").
and_return(['a', 'b', 'c'])
end
- it 'should be able to parse a YAML data with a mixed structure' do
+ it 'should be able to parse YAML data with a mixed structure' do
is_expected.to run.with_params("---\na: '1'\nb: 2\nc:\n d:\n - :a\n - true\n - false\n").
and_return({'a' => '1', 'b' => 2, 'c' => {'d' => [:a, true, false]}})
end
+ it 'should be able to parse YAML data with a UTF8 and double byte characters' do
+ is_expected.to run.with_params("---\na: ×\nこれ: 記号\nです:\n ©:\n - Á\n - ß\n").
+ and_return({"a"=>"×", "これ"=>"記号", "です"=>{"©"=>["Á", "ß"]} })
+ end
+
it 'should not return the default value if the data was parsed correctly' do
is_expected.to run.with_params("---\na: '1'\n", 'default_value').
and_return({'a' => '1'})
diff --git a/spec/functions/range_spec.rb b/spec/functions/range_spec.rb
index 492cad4..ca569d5 100755
--- a/spec/functions/range_spec.rb
+++ b/spec/functions/range_spec.rb
@@ -79,6 +79,14 @@ describe 'range' do
it { is_expected.to run.with_params('01', '04').and_return([1, 2, 3, 4]) }
end
+ context 'with prefixed numbers as utf8 strings as bounds' do
+ it { is_expected.to run.with_params('ħөŝŧ01', 'ħөŝŧ04').and_return(['ħөŝŧ01', 'ħөŝŧ02', 'ħөŝŧ03', 'ħөŝŧ04']) }
+ end
+
+ context 'with prefixed numbers as double byte character strings as bounds' do
+ it { is_expected.to run.with_params('ホスト01', 'ホスト04').and_return(['ホスト01', 'ホスト02', 'ホスト03', 'ホスト04']) }
+ end
+
context 'with dash-range syntax' do
it { is_expected.to run.with_params('4-1').and_return([]) }
it { is_expected.to run.with_params('1-1').and_return([1]) }
diff --git a/spec/functions/seeded_rand_spec.rb b/spec/functions/seeded_rand_spec.rb
index 38e134e..ac108f4 100644
--- a/spec/functions/seeded_rand_spec.rb
+++ b/spec/functions/seeded_rand_spec.rb
@@ -50,4 +50,9 @@ describe 'seeded_rand' do
scope.function_seeded_rand([max, seed])
end
+
+ context 'should run with UTF8 and double byte characters' do
+ it { is_expected.to run.with_params(1000, 'ǿňè')}
+ it { is_expected.to run.with_params(1000, '文字列')}
+ end
end
diff --git a/spec/functions/squeeze_spec.rb b/spec/functions/squeeze_spec.rb
index 7f09c30..b267d9a 100755
--- a/spec/functions/squeeze_spec.rb
+++ b/spec/functions/squeeze_spec.rb
@@ -16,6 +16,12 @@ describe 'squeeze' do
it { is_expected.to run.with_params('aaaaaaaaabbbbbbbbbbcccccccccc', 'b-c').and_return('aaaaaaaaabc') }
end
+ context 'should run with UTF8 and double byte characters' do
+ it { is_expected.to run.with_params('ậậậậậậậậậậậậậậậậậậậậ').and_return('ậ') }
+ it { is_expected.to run.with_params('語語語語語語語', '語').and_return('語') }
+ it { is_expected.to run.with_params('ậậậậậậậậậậậậậậậậậ語語語語©©©©©', '©').and_return('ậậậậậậậậậậậậậậậậậ語語語語©') }
+ end
+
context 'when squeezing values in an array' do
it {
is_expected.to run \
diff --git a/spec/functions/validate_ipv6_address_spec.rb b/spec/functions/validate_ipv6_address_spec.rb
index 78810d4..137db36 100755
--- a/spec/functions/validate_ipv6_address_spec.rb
+++ b/spec/functions/validate_ipv6_address_spec.rb
@@ -29,6 +29,13 @@ describe 'validate_ipv6_address' do
it { is_expected.to run.with_params('3ffe:0505:0002::', '3ffe:0505:0002::2') }
it { is_expected.to run.with_params('::1/64') }
it { is_expected.to run.with_params('fe80::a00:27ff:fe94:44d6/64') }
+ it { is_expected.to run.with_params('fe80:0000:0000:0000:0204:61ff:fe9d:f156') }
+ it { is_expected.to run.with_params('fe80:0:0:0:204:61ff:fe9d:f156') }
+ it { is_expected.to run.with_params('fe80::204:61ff:fe9d:f156') }
+ it { is_expected.to run.with_params('fe80:0:0:0:0204:61ff:254.157.241.86') }
+ it { is_expected.to run.with_params('::1') }
+ it { is_expected.to run.with_params('fe80::') }
+ it { is_expected.to run.with_params('2001::') }
end
describe 'invalid inputs' do
@@ -38,6 +45,9 @@ describe 'validate_ipv6_address' do
it { is_expected.to run.with_params('0.0.0').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) }
it { is_expected.to run.with_params('0.0.0.256').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) }
it { is_expected.to run.with_params('0.0.0.0.0').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) }
+ it { is_expected.to run.with_params('::ffff:2.3.4').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) }
+ it { is_expected.to run.with_params('::ffff:257.1.2.3').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) }
+ it { is_expected.to run.with_params('::ffff:12345678901234567890.1.26').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) }
it { is_expected.to run.with_params('affe:beef').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) }
it { is_expected.to run.with_params('::1', {}).and_raise_error(Puppet::ParseError, /is not a string/) }
it { is_expected.to run.with_params('::1', true).and_raise_error(Puppet::ParseError, /is not a string/) }
diff --git a/spec/unit/puppet/type/file_line_spec.rb b/spec/unit/puppet/type/file_line_spec.rb
index c559e44..150149b 100755
--- a/spec/unit/puppet/type/file_line_spec.rb
+++ b/spec/unit/puppet/type/file_line_spec.rb
@@ -47,6 +47,24 @@ describe Puppet::Type.type(:file_line) do
:match => '^\s*foo=.*$'
)}.not_to raise_error
end
+ it 'should accept utf8 characters' do
+ expect {
+ Puppet::Type.type(:file_line).new(
+ :name => 'ƒồỗ',
+ :path => my_path,
+ :line => 'ƒồỗ=ьåя',
+ :match => '^ьåя=βļάħ$'
+ )}.not_to raise_error
+ end
+ it 'should accept double byte characters' do
+ expect {
+ Puppet::Type.type(:file_line).new(
+ :name => 'フーバー',
+ :path => my_path,
+ :line => 'この=それ',
+ :match => '^この=ああ$'
+ )}.not_to raise_error
+ end
it 'should accept posix filenames' do
file_line[:path] = tmp_path
expect(file_line[:path]).to eq(tmp_path)
@@ -69,7 +87,12 @@ describe Puppet::Type.type(:file_line) do
it 'should default to replace => true' do
expect(file_line[:replace]).to eq :true
end
-
+ it 'should default to encoding => UTF-8' do
+ expect(file_line[:encoding]).to eq 'UTF-8'
+ end
+ it 'should accept encoding => iso-8859-1' do
+ expect { Puppet::Type.type(:file_line).new(:name => 'foo', :path => tmp_path, :ensure => :present, :encoding => 'iso-8859-1', :line => 'bar') }.not_to raise_error
+ end
it "should autorequire the file it manages" do
catalog = Puppet::Resource::Catalog.new
file = Puppet::Type.type(:file).new(:name => tmp_path)
diff --git a/types/compat/ipv6.pp b/types/compat/ipv6.pp
index 18b148d..8b82f1a 100644
--- a/types/compat/ipv6.pp
+++ b/types/compat/ipv6.pp
@@ -1 +1 @@
-type Stdlib::Compat::Ipv6 = Pattern[/^(?:(?:[\da-f]{1,4}:){7}[\da-f]{1,4}|((?:[\da-f]{1,4}:){6})(\d+)\.(\d+)\.(\d+)\.(\d+))$/]
+type Stdlib::Compat::Ipv6 = Pattern[/\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$/]