Repository: PowerShell/PowerShell
File: src/System.Management.Automation/namespaces/FileSystemProvider.cs (C#)

Code before:
                    bool isDirectory = false;
                    string strTargetPath = value?.ToString();

                    if (string.IsNullOrEmpty(strTargetPath))
                    {
                        throw PSTraceSource.NewArgumentNullException(nameof(value));
                    }

                    bool exists = false;

                    // It is legal to create symbolic links to non-existing targets on
                    // both Windows and Linux. It is not legal to create hard links to
                    // non-existing targets on either Windows or Linux.
                    try
                    {
                        if (itemType == ItemType.SymbolicLink)
                        {
                            exists = true;

                            // unify directory separators to be consistent with the rest of PowerShell even on non-Windows platforms;
                            // do this before resolving the target, otherwise e.g. `.\test` would break on Linux, since the combined
                            // path below would be something like `/path/to/cwd/.\test`
                            strTargetPath = strTargetPath.Replace(StringLiterals.AlternatePathSeparator, StringLiterals.DefaultPathSeparator);

                            // check if the target is a file or directory
                            var normalizedTargetPath = Path.Combine(Path.GetDirectoryName(path)!, strTargetPath);
                            GetFileSystemInfo(normalizedTargetPath, out isDirectory);
                        }
                        else
                        {
                            // for hardlinks we resolve the target to an absolute path
                            if (!IsAbsolutePath(strTargetPath))
                            {
                                // there is already a check before here so that strTargetPath should only resolve to 1 path
                                strTargetPath = SessionState.Path.GetResolvedPSPathFromPSPath(strTargetPath).FirstOrDefault()?.Path;
                            }

                            exists = GetFileSystemInfo(strTargetPath, out isDirectory) != null;
                        }
                    }
                    catch (Exception e)
                    {
                        WriteError(new ErrorRecord(e, "AccessException", ErrorCategory.PermissionDenied, strTargetPath));
                        return;
                    }

                    if (!exists)
                    {
                        string message = StringUtil.Format(FileSystemProviderStrings.ItemNotFound, strTargetPath);
                        WriteError(new ErrorRecord(new ItemNotFoundException(message), "ItemNotFound", ErrorCategory.ObjectNotFound, strTargetPath));
                        return;

Review comment (suggestion):
```suggestion
                            var normalizedTargetPath = Path.Combine(Path.GetDirectoryName(path), strTargetPath);
```
Reference null-able is not enforced here.

Code after:
                    bool isDirectory = false;
                    string strTargetPath = value?.ToString();

                    if (string.IsNullOrEmpty(strTargetPath))
                    {
                        throw PSTraceSource.NewArgumentNullException(nameof(value));
                    }

                    bool exists = false;

                    // It is legal to create symbolic links to non-existing targets on
                    // both Windows and Linux. It is not legal to create hard links to
                    // non-existing targets on either Windows or Linux.
                    try
                    {
                        if (itemType == ItemType.SymbolicLink)
                        {
                            exists = true;

                            // unify directory separators to be consistent with the rest of PowerShell even on non-Windows platforms;
                            // do this before resolving the target, otherwise e.g. `.\test` would break on Linux, since the combined
                            // path below would be something like `/path/to/cwd/.\test`
                            strTargetPath = strTargetPath.Replace(StringLiterals.AlternatePathSeparator, StringLiterals.DefaultPathSeparator);

                            // check if the target is a file or directory
                            var normalizedTargetPath = Path.Combine(Path.GetDirectoryName(path), strTargetPath);
                            GetFileSystemInfo(normalizedTargetPath, out isDirectory);
                        }
                        else
                        {
                            // for hardlinks we resolve the target to an absolute path
                            if (!IsAbsolutePath(strTargetPath))
                            {
                                // there is already a check before here so that strTargetPath should only resolve to 1 path
                                strTargetPath = SessionState.Path.GetResolvedPSPathFromPSPath(strTargetPath).FirstOrDefault()?.Path;
                            }

                            exists = GetFileSystemInfo(strTargetPath, out isDirectory) != null;
                        }
                    }
                    catch (Exception e)
                    {
                        WriteError(new ErrorRecord(e, "AccessException", ErrorCategory.PermissionDenied, strTargetPath));
                        return;
                    }

                    if (!exists)
                    {
                        string message = StringUtil.Format(FileSystemProviderStrings.ItemNotFound, strTargetPath);
                        WriteError(new ErrorRecord(new ItemNotFoundException(message), "ItemNotFound", ErrorCategory.ObjectNotFound, strTargetPath));
                        return;