Title: Test-Path -Path $null should return $false · Issue #8076 · PowerShell/PowerShell · GitHub
Open Graph Title: Test-Path -Path $null should return $false · Issue #8076 · PowerShell/PowerShell
X Title: Test-Path -Path $null should return $false · Issue #8076 · PowerShell/PowerShell
Description: Test-Path will throw an error when the path is $null (or an empty string) instead of returning $false. The errors that we do get are parameter binding errors I find myself often running into errors with Test-Path because of empty or $nul...
Open Graph Description: Test-Path will throw an error when the path is $null (or an empty string) instead of returning $false. The errors that we do get are parameter binding errors I find myself often running into errors...
X Description: Test-Path will throw an error when the path is $null (or an empty string) instead of returning $false. The errors that we do get are parameter binding errors I find myself often running into errors...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/8076
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Test-Path -Path $null should return $false","articleBody":"Test-Path will throw an error when the path is `$null` (or an empty string) instead of returning `$false`.\r\n\r\nThe errors that we do get are parameter binding errors\r\n\r\nI find myself often running into errors with `Test-Path` because of empty or `$null` strings. Then I end up making my validation more complex to account for it.\r\n\r\n```\r\nif ( Test-Path -Path $Path)\r\n{\r\n # do something\r\n}\r\n\r\n# VS\r\n\r\nif ( $null -ne $Path -and ( Test-Path -Path $Path) )\r\n{\r\n # do something\r\n}\r\n```\r\nIt would be nice if it would just return `$false` (or offer a `-Quiet` parameter)\r\n\r\nSteps to reproduce\r\n------------------\r\n\r\n```powershell\r\n$path = Resolve-Path -Path '.\\*\\nothing'\r\nTest-Path $path\r\n```\r\n```powershell\r\nResolve-Path -Path '.\\*\\nothing' | Test-Path\r\n```\r\n\r\nExpected behavior\r\n-----------------\r\n\r\n```none\r\nFalse\r\n```\r\n\r\nActual behavior\r\n---------------\r\n\r\n```none\r\nError: Test-Path : Cannot bind argument to parameter 'Path' because it is null.\r\n```\r\n\r\nEnvironment data\r\n----------------\r\n\r\n```powershell\r\n\u003e $PSVersionTable\r\nPSVersion 6.1.0\r\nPSEdition Core\r\nGitCommitId 6.1.0\r\nOS Microsoft Windows 10.0.16299\r\nPlatform Win32NT\r\nPSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}\r\nPSRemotingProtocolVersion 2.3\r\nSerializationVersion 1.1.0.1\r\nWSManStackVersion 3.0\r\n```\r\n","author":{"url":"https://github.com/KevinMarquette","@type":"Person","name":"KevinMarquette"},"datePublished":"2018-10-18T23:50:26.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":7},"url":"https://github.com/8076/PowerShell/issues/8076"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:192c4c84-402b-6f8c-d0f5-48c97702a67a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9F8E:11B626:260829:34D6D6:6A59C3FA |
| html-safe-nonce | 3014f42bd9711709a57669540502e34d8b8b1b817070f380fb0456e5cd51bae6 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RjhFOjExQjYyNjoyNjA4Mjk6MzRENkQ2OjZBNTlDM0ZBIiwidmlzaXRvcl9pZCI6Ijc3MzI2MTYyNzQ5MDg5MjI4NzQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 1e3a97fad38d1a3fb57fe74e9df8ed29649550b8baf582c44dc32c65d1b1e337 |
| hovercard-subject-tag | issue:371755831 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PowerShell/PowerShell/8076/issue_layout |
| twitter:image | https://opengraph.githubassets.com/28de7817e7982f6faf9bfba152d81e7ff6ba83e73146fae074bfa13f84669216/PowerShell/PowerShell/issues/8076 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/28de7817e7982f6faf9bfba152d81e7ff6ba83e73146fae074bfa13f84669216/PowerShell/PowerShell/issues/8076 |
| og:image:alt | Test-Path will throw an error when the path is $null (or an empty string) instead of returning $false. The errors that we do get are parameter binding errors I find myself often running into errors... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | KevinMarquette |
| hostname | github.com |
| expected-hostname | github.com |
| None | ba3976babb66479b1c943a8edc0777d96157da48fadc0161f9ddb219deee8353 |
| turbo-cache-control | no-preview |
| go-import | github.com/PowerShell/PowerShell git https://github.com/PowerShell/PowerShell.git |
| octolytics-dimension-user_id | 11524380 |
| octolytics-dimension-user_login | PowerShell |
| octolytics-dimension-repository_id | 49609581 |
| octolytics-dimension-repository_nwo | PowerShell/PowerShell |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 49609581 |
| octolytics-dimension-repository_network_root_nwo | PowerShell/PowerShell |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | ab680789ae4a316cdaf0d5a292a1760140931cc4 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width