Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix IndexError on command fieldtype #128

Merged
merged 1 commit into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion flow/record/fieldtypes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,8 @@ def __new__(cls, value: str) -> command:
# an '%' for an environment variable
# r'\\' for a UNC path
# the strip and check for ":" on the second line is for `<drive_letter>:`
windows = value.startswith((r"\\", "%")) or value.lstrip("\"'")[1] == ":"
stripped_value = value.lstrip("\"'")
windows = value.startswith((r"\\", "%")) or (len(stripped_value) >= 2 and stripped_value[1] == ":")

if windows:
cls = windows_command
Expand Down
11 changes: 9 additions & 2 deletions tests/test_fieldtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1075,9 +1075,16 @@ def test_command_integration_none(tmp_path: pathlib.Path) -> None:
# Test a quoted path
(r"'c:\path to some exe' /d /a", r"c:\path to some exe", [r"/d /a"]),
# Test a unquoted path
(r"'c:\Program Files\hello.exe'", r"c:\Program Files\hello.exe", []),
(r"\Users\test\hello.exe", r"\Users\test\hello.exe", []),
# Test an unquoted path with a path as argument
(r"'c:\Program Files\hello.exe' c:\startmepls.exe", r"c:\Program Files\hello.exe", [r"c:\startmepls.exe"]),
(r"\Users\test\hello.exe c:\startmepls.exe", r"\Users\test\hello.exe", [r"c:\startmepls.exe"]),
# Test a quoted UNC path
(r"'\\192.168.1.2\Program Files\hello.exe'", r"\\192.168.1.2\Program Files\hello.exe", []),
# Test an unquoted UNC path
(r"\\192.168.1.2\Users\test\hello.exe /d /a", r"\\192.168.1.2\Users\test\hello.exe", [r"/d /a"]),
# Test an empty command string
(r"''", r"", []),
# Test None
(None, None, None),
],
)
Expand Down
Loading