Skip to content

Commit

Permalink
Revert "Fixed empty strings in powershell by using pwsh instead of po…
Browse files Browse the repository at this point in the history
…wershell"

This reverts commit e592952.
  • Loading branch information
nicolas-van committed Apr 25, 2023
1 parent 644e32b commit 3c21010
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ 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(["pwsh", cmd_file_name], stdout=subprocess.DEVNULL)
subprocess.check_call(["powershell", 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: 9 additions & 6 deletions test_win_cmd_escaper.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ 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 @@ -113,7 +119,7 @@ def escape(self, str):
def run_echoer(self, str):
return test_utils.run_echoer_with_cmd_through_script(str)

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

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

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

def test_emoji(self):
self._test_str('😊❤️😍😁👍')
def test_empty(self):
self._test_unsupported("")
4 changes: 3 additions & 1 deletion win_cmd_escaper.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ 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 3c21010

Please sign in to comment.