Skip to content

Commit

Permalink
Refs #59 - Support escaped qoutation marks thereby allowing spaces in…
Browse files Browse the repository at this point in the history
… JVM Options.
  • Loading branch information
PeterParker committed Feb 18, 2016
1 parent eab5719 commit c613a37
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/puppet/provider/asadmin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ def asadmin_exec(passed_args)
end

def escape(value)
# Add three backslashes to escape the colon
return value.gsub(/:/) { '\\:' }
# Add backslashes to colons and already-escaped qoutes.
return value.gsub(/:/){ '\\:' }.gsub(/\"/) { '\\\\"' }
end

# def exists?
Expand Down
3 changes: 2 additions & 1 deletion lib/puppet/provider/jvmoption/asadmin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ def exists?
args << "list-jvm-options"
args << "--target" << @resource[:target] if @resource[:target]

#Remove escaped semi-colons for matching the jvm option name
#Remove escaped semi-colons and qoutes for matching the jvm option name
name = @resource[:name].sub "\\:" , ":"
name = name.gsub "\\\"" , "\""

asadmin_exec(args).each do |line|
line.sub!(/-XX: ([^\ ]+)/, '-XX:+\1')
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/type/jvmoption.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
isnamevar

validate do |value|
unless value =~ /^-(?:[\w\-.:\\+])+(?:=[\w\-\.\/${}\\:]+)?$/
raise ArgumentError, "%s is not a valid JVM option." % value
unless value =~ /^-(?:[\w\-.:\\+])+(?:=[\w\-\.\/${}\\:]+|=\\\".*\\\")?$/
raise ArgumentError, "%s is not a valid JVM option." % value
end
end
end
Expand Down
7 changes: 6 additions & 1 deletion spec/unit/puppet/type/jvmoption_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,13 @@
described_class.new(:option => '-Dtest.url=http\:www.gmail.com', :ensure => :present)[:option].should == '-Dtest.url=http\:www.gmail.com'
end

it "should not support spaces" do
it "should not support spaces in the option name" do
expect { described_class.new(:option => '-X Option', :ensure => :present) }.to raise_error(Puppet::Error, /-X Option is not a valid JVM option/)
expect { described_class.new(:option => '-X Option=value', :ensure => :present) }.to raise_error(Puppet::Error, /-X Option=value is not a valid JVM option/)
end

it "should support spaces contained within escaped double-qoutes in an option value" do
described_class.new(:option => '-XOption=\"a value\"', :ensure => :present)[:option].should == '-XOption=\"a value\"'
end
end

Expand Down

0 comments on commit c613a37

Please sign in to comment.