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

[Bug]: GetEdk2RelativePathFromAbsolutePath() Can Silently Return Non-POSIX Path #207

Closed
makubacki opened this issue Nov 11, 2022 · 0 comments · Fixed by #372
Closed

[Bug]: GetEdk2RelativePathFromAbsolutePath() Can Silently Return Non-POSIX Path #207

makubacki opened this issue Nov 11, 2022 · 0 comments · Fixed by #372
Labels
bug Something isn't working

Comments

@makubacki
Copy link
Member

Contact Details

No response

Describe the Bug

GetEdk2RelativePathFromAbsolutePath() is currently defined as follows:

        """Given an absolute path return a edk2 path relative to workspace or packagespath.

        Note: absolute path must be in the OS specific path form
        Note: the relative path will be in POSIX-like path form

        Args:
            abspath (os.PathLike): absolute path to a file or directory. Path must contain OS specific separator.

        Returns:
            (os.PathLike): POSIX-like relative path to workspace or packagespath
            (None): abspath is none
            (None): path is not valid
        """

It requires an OS-specific path (to the current OS) to be given as input. However, it does not return an exception or other fail in a well-defined way if path given does not conform to the current OS. It likely returns a non-POSIX path.

So, this is not a bug with the function in the case the user passes the expected path format but a bug in validating the function input values.

Reproduction steps

The following code demonstrates the problem if run on Linux since it passes a Windows style path to the function.

        p = f"{ws_pkg_abs}\\module_2\\X64\\TestFile.inf"
        expected_rel_from_abs_path = PurePath(os.path.join(ws_p_name, "module_2", "X64", "TestFile.inf")).as_posix()
        actual_rel_from_abs_path = pathobj.GetEdk2RelativePathFromAbsolutePath(p)
>       self.assertEqual(expected_rel_from_abs_path, actual_rel_from_abs_path)
E       AssertionError: 'WSTestPkg/module_2/X64/TestFile.inf' != 'WSTestPkg\\module_2\\X64\\TestFile.inf'
E       - WSTestPkg/module_2/X64/TestFile.inf
E       ?          ^        ^   ^
E       + WSTestPkg\module_2\X64\TestFile.inf

Expected behavior

The function should ensure that it handles input in a predictable and well-defined manner.

Execution Environment

No response

Pip packages

No response

Additional context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant