Skip to content

Commit

Permalink
Fixed empty strings in powershell by using pwsh instead of powershell
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-van committed Apr 25, 2023
1 parent bde165c commit e592952
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 14 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ Also, while this library is in Python, it aims to be a reference implementation
## Known limitations

* ASCII control codes are not supported. This notably includes `\t`, `\r` and `\n`. (There doest't seem to have proper ways to encode these characters in CMD nor Powershell anyway.)
* Empty strings are not supported in Powershell. (It doesn't seem to be possible at all to pass an empty string as a command line argument in that *super well designed* language.)

## About non-ASCII characters

Expand Down
2 changes: 1 addition & 1 deletion test_ressources/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def run_echoer_with_powershell_through_script(str):
f.write(cmd_file_content)

# perform the call
subprocess.check_call(["powershell", cmd_file_name], stdout=subprocess.DEVNULL)
subprocess.check_call(["pwsh", cmd_file_name], stdout=subprocess.DEVNULL)

# get the results
with open(output_file_path, 'r', encoding="utf-8", newline='') as f:
Expand Down
15 changes: 6 additions & 9 deletions test_win_cmd_escaper.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,6 @@ def test_double_quotes(self):
self._test_str('"\\\\')
self._test_str('"\\\\\\')

def test_latin_1(self):
self._test_str('Aéèàù')

def test_emoji(self):
self._test_str('😊❤️😍😁👍')

class CmdScriptTests(unittest.TestCase, AllTests):

def escape(self, str):
Expand All @@ -119,7 +113,7 @@ def escape(self, str):
def run_echoer(self, str):
return test_utils.run_echoer_with_cmd_through_script(str)

class CmdPythonSubprocessTests(unittest.TestCase, AllTests):
class CmdDirectTests(unittest.TestCase, AllTests):

def escape(self, str):
return win_cmd_escaper.escape_cmd_argument_direct(str)
Expand All @@ -136,5 +130,8 @@ def escape(self, str):
def run_echoer(self, str):
return test_utils.run_echoer_with_powershell_through_script(str)

def test_empty(self):
self._test_unsupported("")
def test_latin_1(self):
self._test_str('Aéèàù')

def test_emoji(self):
self._test_str('😊❤️😍😁👍')
4 changes: 1 addition & 3 deletions win_cmd_escaper.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ def escape_powershell_argument_script(str):
"""
Escapes an argument for Powershell.
"""
if str == "":
raise ValueError("Empty strings are not supported")


acc = ""
for i in range(len(str)):
c = str[i]
Expand Down

0 comments on commit e592952

Please sign in to comment.