Skip to content

Commit

Permalink
Merge pull request #95 from salvaom/fix/powershell-amperstand-escape
Browse files Browse the repository at this point in the history
Fix "&" being escaped on PoweShell's environment variables (#93)
  • Loading branch information
salvaom authored Feb 14, 2020
2 parents 860c5b6 + 489b137 commit cb1c71c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Change Log


## 2.40.4 (2020-02-13)

**Notes**

This update brings fixes the character "&" being escaped on PowerShell's shell plugin. ([\#93](https://github.com/mottosso/bleeding-rez/issues/93) )


## 2.40.3 (2019-08-15)
[Source](https://github.com/nerdvegas/rez/tree/2.40.3) | [Diff](https://github.com/nerdvegas/rez/compare/2.40.2...2.40.3)

Expand Down
2 changes: 1 addition & 1 deletion src/rez/utils/_version.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@


# Update this value to version up Rez. Do not place anything else in this file.
_rez_version = "2.40.3"
_rez_version = "2.40.4"


# Copyright 2013-2016 Allan Johns.
Expand Down
18 changes: 15 additions & 3 deletions src/rezplugins/shell/powershell.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ def get_output(self, style=OutputStyle.file):
script = '&& '.join(lines)
return script

@staticmethod
def _escape_quotes(s):
return s.replace('"', '`"').replace("'", "`'")

def escape_string(self, value):
"""Escape the <, >, ^, and & special characters reserved by Windows.
Expand All @@ -172,9 +176,17 @@ def escape_string(self, value):
str: The value escaped for Windows.
"""
if isinstance(value, EscapedString):
return value.formatted(self._escaper)
return self._escaper(value)
value = EscapedString.promote(value)
value = value.expanduser()
result = ''

for is_literal, txt in value.strings:
if is_literal:
txt = self._escape_quotes(self._escape_vars(txt))
else:
txt = self._escape_quotes(txt)
result += txt
return result

def setenv(self, key, value):
value = self.escape_string(value)
Expand Down

0 comments on commit cb1c71c

Please sign in to comment.