Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refs #59 - Support escaped quotation marks / spaces. #60

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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