From c613a377b6bee8c7ebba5ffc3a8fe5318973e4ce Mon Sep 17 00:00:00 2001 From: "Parker, Peter G" Date: Thu, 18 Feb 2016 15:55:56 -0500 Subject: [PATCH] Refs #59 - Support escaped qoutation marks thereby allowing spaces in JVM Options. --- lib/puppet/provider/asadmin.rb | 4 ++-- lib/puppet/provider/jvmoption/asadmin.rb | 3 ++- lib/puppet/type/jvmoption.rb | 4 ++-- spec/unit/puppet/type/jvmoption_spec.rb | 7 ++++++- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/puppet/provider/asadmin.rb b/lib/puppet/provider/asadmin.rb index b36e7e2..ee65b22 100644 --- a/lib/puppet/provider/asadmin.rb +++ b/lib/puppet/provider/asadmin.rb @@ -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? diff --git a/lib/puppet/provider/jvmoption/asadmin.rb b/lib/puppet/provider/jvmoption/asadmin.rb index a491965..ac64299 100644 --- a/lib/puppet/provider/jvmoption/asadmin.rb +++ b/lib/puppet/provider/jvmoption/asadmin.rb @@ -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') diff --git a/lib/puppet/type/jvmoption.rb b/lib/puppet/type/jvmoption.rb index 57736a6..5831526 100644 --- a/lib/puppet/type/jvmoption.rb +++ b/lib/puppet/type/jvmoption.rb @@ -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 diff --git a/spec/unit/puppet/type/jvmoption_spec.rb b/spec/unit/puppet/type/jvmoption_spec.rb index e27c150..53a66ee 100644 --- a/spec/unit/puppet/type/jvmoption_spec.rb +++ b/spec/unit/puppet/type/jvmoption_spec.rb @@ -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