Skip to content

Commit

Permalink
fix expand
Browse files Browse the repository at this point in the history
  • Loading branch information
mcorino committed Jan 6, 2024
1 parent 52626e3 commit 3f481f8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
23 changes: 15 additions & 8 deletions lib/wx/core/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -520,24 +520,31 @@ def get_path(path_str)
end
protected :get_path

EXPAND_RE = if Wx::PLATFORM == 'WXMSW'
/(\\)?([$][{(]?|%)(\w+)([})%])?/
else
/(\\)?([$][{(]?)(\w+)([})])?/
end
private_constant :EXPAND_RE

def expand(val)
if root.expanding_env_vars? && ::String === val
brackets = '{('
brackets << '%' if Wx::PLATFORM == 'WXMSW'
val.gsub!(/([\\])?\$([#{brackets}])?(\w+)([})%])?/) do |s|
val.gsub(EXPAND_RE) do |s|
if $1.nil? &&
(($2.nil? && $4.nil?) ||
($2 == '{' && $4 == '}') ||
($2 == '(' && $4 == ')') ||
(win && $2 == '%' && $4 == '%')) &&
(($2[0] == '$' &&
($2.size == 1 && $4.nil?) ||
($2[1] == '(' && $4 == ')') ||
($2[1] == '{' && $4 == '}'))||
($2[0] == '%' && $4 == '%')) &&
ENV[$3]
$1 ? $1+ENV[$3] : ENV[$3]
else
$1 ? s[1,s.size] : s
end
end
else
val
end
val
end
protected :expand

Expand Down
2 changes: 0 additions & 2 deletions tests/test_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,6 @@ def run_env_var_tests(cfg)
# disable env var expansion
cfg.expand_env_vars = false
begin
cfg['/Environment/HOME'] = '$HOME'

assert_equal('$HOME', cfg.Environment['HOME'])
ensure
# re-enable
Expand Down

0 comments on commit 3f481f8

Please sign in to comment.