Skip to content

Commit

Permalink
Fix IndexError on command fieldtype
Browse files Browse the repository at this point in the history
  • Loading branch information
Poeloe committed Jul 26, 2024
1 parent 61bb734 commit 993e318
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
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

0 comments on commit 993e318

Please sign in to comment.