Skip to content

Bug: convert_path_to_unix_path does not handle empty string input #32

Description

@bnusunny

Description

The convert_path_to_unix_path function in samcli/lib/utils/path_utils.py does not handle empty string input correctly. Passing an empty string returns "." instead of "".

Steps to reproduce

from samcli.lib.utils.path_utils import convert_path_to_unix_path
result = convert_path_to_unix_path("")
print(repr(result))  # prints '.' instead of ''

Expected behavior

An empty string input should return an empty string.

Actual behavior

PureWindowsPath("").as_posix() returns "." (the current directory), which is incorrect when the intent is to pass through an empty/unset path value.

Fix

Add an early return for empty input:

def convert_path_to_unix_path(path: str) -> str:
    if not path:
        return path
    return PureWindowsPath(path).as_posix()

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions