Skip to content

Commit d69e247

Browse files
author
Christopher Frost
committed
Parenthesis not allowed in JAVA_OPTS
This commit allows any special charecter including parenthesis to be used in the value of a JAVA_OPT obtained from either an environment variable or the java_opts configuration. [#86290602]
1 parent 0758382 commit d69e247

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

lib/java_buildpack/framework/java_opts.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,14 @@ def parsed_java_opts
6565
parsed_java_opts.concat @configuration[CONFIGURATION_PROPERTY].shellsplit if supports_configuration?
6666
parsed_java_opts.concat ENV[ENVIRONMENT_VARIABLE].shellsplit if supports_environment?
6767

68-
parsed_java_opts.map { |java_opt| java_opt.gsub(/([\s])/, '\\\\\1') }
68+
# parsed_java_opts.map { |java_opt| java_opt.gsub(/([\s])/, '\\\\\1') }
69+
parsed_java_opts.map do |java_opt|
70+
if /(?<key>.+)=(?<value>.+)/ =~ java_opt
71+
"#{key}=#{value.shellescape}"
72+
else
73+
java_opt
74+
end
75+
end
6976
end
7077

7178
def supports_configuration?

spec/java_buildpack/framework/java_opts_spec.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,19 @@
6262
expect(java_opts).to include('-Xdebug')
6363
expect(java_opts).to include('-Xnoagent')
6464
expect(java_opts).to include('-Xrunjdwp:transport=dt_socket,server=y,address=8000,suspend=y')
65-
expect(java_opts).to include('-XX:OnOutOfMemoryError=kill\ -9\ %p')
65+
expect(java_opts).to include('-XX:OnOutOfMemoryError=kill\ -9\ \%p')
66+
end
67+
end
68+
69+
context do
70+
let(:configuration) do
71+
{ 'java_opts' => '-Dtest=!£$%^&*(){}<>[];~`' }
72+
end
73+
74+
it 'escapes special characters' do
75+
component.release
76+
77+
expect(java_opts).to include('-Dtest=\\!\\£\\$\\%\\^\\&\\*\\(\\)\\{\\}\\<\\>\\[\\]\\;\\~\\`')
6678
end
6779
end
6880

0 commit comments

Comments
 (0)