Skip to content

Commit

Permalink
Automatically add leading zero when single character hex for binary
Browse files Browse the repository at this point in the history
  • Loading branch information
Travis Fields committed May 1, 2014
1 parent 624c696 commit 738eea4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion acceptance/tests/resource/registry/should_manage_values.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class phase1 {
# Binary Values
registry_value { '#{keypath}\\SubKey1\\ValueBinary1':
type => binary,
data => "0${::fact_phase}",
data => "${::fact_phase}",
}
registry_value { '#{keypath}\\SubKey1\\ValueBinary2':
type => binary,
Expand Down
7 changes: 5 additions & 2 deletions lib/puppet/type/registry_value.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
**Autorequires:** Any parent registry key managed by Puppet will be
autorequired.
EOT
EOT

def self.title_patterns
[ [ /^(.*?)\Z/m, [ [ :path, lambda{|x| x} ] ] ] ]
[[/^(.*?)\Z/m, [[:path, lambda { |x| x }]]]]
end

ensurable
Expand Down Expand Up @@ -84,6 +84,9 @@ def self.title_patterns
fail("The data must be a valid QWORD: #{value}") unless val and (val.abs >> 64) <= 0
val
when :binary
if (value.respond_to?(:length) && value.length == 1) || (value.kind_of?(Integer) && value <= 9)
value = "0#{value}"
end
unless value.match(/^([a-f\d]{2} ?)*$/i)
fail("The data must be a hex encoded string of the form: '00 01 02 ...'")
end
Expand Down
6 changes: 6 additions & 0 deletions spec/unit/puppet/type/registry_value_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@
value[:data] = data
end
end
[9,'1','A'].each do |data|
it "should accept '#{data}' and have a leading zero" do
value[:type] = :binary
value[:data] = data
end
end

["\040\040", 'foobar', :true].each do |data|
it "should reject '#{data}'" do
Expand Down

0 comments on commit 738eea4

Please sign in to comment.