Skip to content

Commit

Permalink
Add is_shell_path arg to escape_string overrides
Browse files Browse the repository at this point in the history
Add check and key conversion for shell pathed key based on arg

Signed-off-by: amorphousWaste <20346603+amorphousWaste@users.noreply.github.com>
  • Loading branch information
amorphousWaste authored and Jawabiscuit committed Sep 15, 2023
1 parent 640e44c commit c55ee1b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/rezplugins/shell/_utils/powershell_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def get_output(self, style=OutputStyle.file):
script = '&& '.join(lines)
return script

def escape_string(self, value, is_path=False):
def escape_string(self, value, is_path=False, is_shell_path=False):
value = EscapedString.promote(value)
value = value.expanduser()
result = ''
Expand All @@ -237,6 +237,8 @@ def escape_string(self, value, is_path=False):
else:
if is_path:
txt = self.normalize_paths(txt)
elif is_shell_path:
txt = self.as_shell_path(txt)

txt = self._escape_quotes(txt)
result += txt
Expand Down
10 changes: 8 additions & 2 deletions src/rezplugins/shell/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,18 @@ def get_output(self, style=OutputStyle.file):
script = '&& '.join(lines)
return script

def escape_string(self, value, is_path=False):
def escape_string(self, value, is_path=False, is_shell_path=False):
"""Escape the <, >, ^, and & special characters reserved by Windows.
is_path and is_shell_path are mutally exclusive.
Args:
value (str/EscapedString): String or already escaped string.
Returns:
str: The value escaped for Windows.
value (str): The value escaped for Windows.
is_path (bool): True if the value is path-like.
is_shell_path (bool): True if the value is a shell-path.
"""
value = EscapedString.promote(value)
Expand All @@ -239,6 +243,8 @@ def escape_string(self, value, is_path=False):
else:
if is_path:
txt = self.normalize_paths(txt)
elif is_shell_path:
txt = self.as_shell_path(txt)

txt = self._escaper(txt)
result += txt
Expand Down
6 changes: 4 additions & 2 deletions src/rezplugins/shell/csh.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def get_startup_sequence(cls, rcfile, norc, stdin, command):
source_bind_files=(not norc)
)

def escape_string(self, value, is_path=False):
def escape_string(self, value, is_path=False, is_shell_path=False):
value = EscapedString.promote(value)
value = value.expanduser()
result = ''
Expand All @@ -110,7 +110,9 @@ def escape_string(self, value, is_path=False):
txt = "'%s'" % txt
else:
if is_path:
txt = self.normalize_paths(txt)
txt = self.as_path(txt)
elif is_shell_path:
txt = self.as_shell_path(txt)

txt = txt.replace('"', '"\\""')
txt = txt.replace('!', '\\!')
Expand Down
6 changes: 5 additions & 1 deletion src/rezplugins/shell/sh.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def source(self, value):
value = self.escape_string(value)
self._addline('. %s' % value)

def escape_string(self, value, is_path=False):
def escape_string(self, value, is_path=False, is_shell_path=False):
value = EscapedString.promote(value)
value = value.expanduser()
result = ''
Expand All @@ -132,11 +132,15 @@ def escape_string(self, value, is_path=False):
else:
if is_path:
txt = self.normalize_paths(txt)
# txt = self.as_path(txt)
elif is_shell_path:
txt = self.as_shell_path(txt)

txt = txt.replace('\\', '\\\\')
txt = txt.replace('"', '\\"')
txt = '"%s"' % txt
result += txt

return result

def _saferefenv(self, key):
Expand Down

0 comments on commit c55ee1b

Please sign in to comment.