Title: PSParser Tokenize with Switch Default fails · Issue #13462 · PowerShell/PowerShell · GitHub
Open Graph Title: PSParser Tokenize with Switch Default fails · Issue #13462 · PowerShell/PowerShell
X Title: PSParser Tokenize with Switch Default fails · Issue #13462 · PowerShell/PowerShell
Description: Trouble when trying to Tokenize a script containing a Switch-statement with a Default case in Powershell 7.1.0-preview.5. This works as expected in Powershell 7.0.3 (stable). If one does comment-out the default case, it works as expected...
Open Graph Description: Trouble when trying to Tokenize a script containing a Switch-statement with a Default case in Powershell 7.1.0-preview.5. This works as expected in Powershell 7.0.3 (stable). If one does comment-ou...
X Description: Trouble when trying to Tokenize a script containing a Switch-statement with a Default case in Powershell 7.1.0-preview.5. This works as expected in Powershell 7.0.3 (stable). If one does comment-ou...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/13462
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"PSParser Tokenize with Switch Default fails","articleBody":"Trouble when trying to Tokenize a script containing a Switch-statement with a Default case in Powershell 7.1.0-preview.5. This works as expected in Powershell 7.0.3 (stable). If one does comment-out the default case, it works as expected. This has been reproduced on more than one computer.\r\n\r\n## Steps to reproduce\r\nCreate a file containing a simple function that has a switch-statement with a default case (see below). Save that file. Then try to tokenize that file (also see below) from a console running Powershell 7.1.0-preview.5.\r\n\r\n```powershell\r\n# Save this as a file called 'TEST.ps1'\r\nFunction Test {\r\n Param (\r\n $String\r\n )\r\n\r\n Switch ($String) {\r\n \"test\" {\r\n \"sfdsf\"\r\n }\r\n\r\n \"test2\" {\r\n \"sfdsf\"\r\n }\r\n\r\n default {\r\n \"sdfsdf\"\r\n }\r\n }\r\n}\r\n```\r\n\r\n```powershell\r\n# From a Powershell 7.1.0-preview.5 prompt execute the following:\r\n$scripts = Get-ChildItem -Path \"C:\\__TEMP\\TEST.ps1\"\r\n\r\nForeach ($file in $scripts) {\r\n $contents = Get-Content -Path $file.fullname -ErrorAction Stop\r\n $errors = $null\r\n $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)\r\n $errors.Count -eq 0\r\n}\r\n```\r\n\r\n## Expected behavior\r\n\r\n```none\r\nTrue\r\n```\r\n\r\n## Actual behavior\r\n\r\n```powershell\r\nMethodInvocationException:\r\nLine |\r\n 4 | $null = [System.Management.Automation.PSParser]::Tokenize($conten …\r\n | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n | Exception calling \"Tokenize\" with \"2\" argument(s): \"Index was outside the bounds of the array.\"\r\nTrue\r\n```\r\n\r\n## Environment data\r\n\r\n\u003c!-- provide the output of $PSVersionTable -->\r\n\r\n```none\r\n\r\nName Value\r\n---- -----\r\nPSVersion 7.1.0-preview.5\r\nPSEdition Core\r\nGitCommitId 7.1.0-preview.5\r\nOS Microsoft Windows 10.0.19041\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```\r\n","author":{"url":"https://github.com/LAltinell","@type":"Person","name":"LAltinell"},"datePublished":"2020-08-17T11:13:17Z","url":"https://github.com/PowerShell/PowerShell/issues/13462"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:15190e8b-f474-fa37-6fd7-66475bbd9ffe |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9E90:1F8C6B:791D3A:AB509A:6AFE1730 |
| html-safe-nonce | 81fd28f37e4e7a8376596b722571c94634be1dd68aa4fd1a0e2ba6052242c0c1 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RTkwOjFGOEM2Qjo3OTFEM0E6QUI1MDlBOjZBRkUxNzMwIiwidmlzaXRvcl9pZCI6Ijg4NDc1NTk2ODE1MzU1MTQ0MTYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 3ef7d46a94f1ddb43e7f272100e001c0d5b65e8a62f86c2ac597cd80b3b4aa15 |
| hovercard-subject-tag | issue:680153583 |
| 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/13462/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e045b4d1934986bf3cc79ffd62277cc3d760f10bb8fad71b1048f651c62bdc5d/PowerShell/PowerShell/issues/13462 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e045b4d1934986bf3cc79ffd62277cc3d760f10bb8fad71b1048f651c62bdc5d/PowerShell/PowerShell/issues/13462 |
| og:image:alt | Trouble when trying to Tokenize a script containing a Switch-statement with a Default case in Powershell 7.1.0-preview.5. This works as expected in Powershell 7.0.3 (stable). If one does comment-ou... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | LAltinell |
| hostname | github.com |
| expected-hostname | github.com |
| None | 3cd8a1d79ccbf9aecac62781f79072482a49047fb982b8c9e2ad4aca8bf6a9af |
| 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 | 05539640a34afe6142a519483d78ddd766a1304a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width