Title: Get-Content -Raw neglects to read the last character, if it is a LF · Issue #4980 · PowerShell/PowerShell · GitHub
Open Graph Title: Get-Content -Raw neglects to read the last character, if it is a LF · Issue #4980 · PowerShell/PowerShell
X Title: Get-Content -Raw neglects to read the last character, if it is a LF · Issue #4980 · PowerShell/PowerShell
Description: Steps to reproduce Save the following to t.Tests.ps1 and invoke with ./t.Tests.ps1: Describe "Get-Content -Raw test" { BeforeAll { Push-Location TestDrive:/ $lfTextUnterminated = "a`nb" $lfText = "a`nb`n" $crlfTextUnterminated = "a`r`nb"...
Open Graph Description: Steps to reproduce Save the following to t.Tests.ps1 and invoke with ./t.Tests.ps1: Describe "Get-Content -Raw test" { BeforeAll { Push-Location TestDrive:/ $lfTextUnterminated = "a`nb" $lfText = "...
X Description: Steps to reproduce Save the following to t.Tests.ps1 and invoke with ./t.Tests.ps1: Describe "Get-Content -Raw test" { BeforeAll { Push-Location TestDrive:/ $lfTextUnterminated = "a`...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/4980
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Get-Content -Raw neglects to read the last character, if it is a LF","articleBody":"Steps to reproduce\r\n------------------\r\n\r\nSave the following to `t.Tests.ps1` and invoke with `./t.Tests.ps1`:\r\n\r\n```powershell\r\nDescribe \"Get-Content -Raw test\" {\r\n BeforeAll {\r\n Push-Location TestDrive:/\r\n $lfTextUnterminated = \"a`nb\"\r\n $lfText = \"a`nb`n\"\r\n $crlfTextUnterminated = \"a`r`nb\"\r\n $crlfText = \"a`r`nb`r`n\"\r\n Set-Content -Encoding Ascii -NoNewline 'lf.txt' -value $lfText\r\n Set-Content -Encoding Ascii -NoNewline 'crlf.txt' -value $crlfText\r\n Set-Content -Encoding Ascii -NoNewline 'lf-nt.txt' -value $lfTextUnterminated\r\n Set-Content -Encoding Ascii -NoNewline 'crlf-nt.txt' -value $crlfTextUnterminated\r\n }\r\n It \"Reads LF-terminated files in full.\" {\r\n Get-Content -Raw 'lf.txt' | Should BeExactly $lfText\r\n }\r\n It \"Reads CRLF-terminated files in full.\" {\r\n Get-Content -Raw 'crlf.txt' | Should BeExactly $crlfText\r\n }\r\n It \"Reads LF-separated files without trailing newline in full.\" {\r\n Get-Content -Raw 'lf-nt.txt' | Should BeExactly $lfTextUnterminated\r\n }\r\n It \"Reads CRLF-separated files without trailing newline in full.\" {\r\n Get-Content -Raw 'crlf-nt.txt' | Should BeExactly $crlfTextUnterminated\r\n }\r\n AfterAll {\r\n Remove-Item -LiteralPath 'lf.txt', 'lf-nt.txt', 'crlf.txt', 'crlf-nt.txt'\r\n Pop-Location\r\n }\r\n}\r\n```\r\n\r\nExpected behavior\r\n-----------------\r\n\r\nAll tests should pass.\r\n\r\nActual behavior\r\n---------------\r\n\r\nThe files ending in an LF character are read without that last character.\r\nNote that Windows Powershell is _not_ affected.\r\n\r\n```none\r\n...\r\n [-] Reads LF-terminated files in full. 47ms\r\n Expected string length 4 but was 3. Strings differ at index 3.\r\n Expected: {a\\nb\\n}\r\n But was: {a\\nb}\r\n ---------------^\r\n at line: 18 in /Users/mklement/Desktop/pg/t.Tests.ps1\r\n 18: Get-Content -Raw 'lf.txt' | Should BeExactly $lfText\r\n [-] Reads CRLF-terminated files in full. 20ms\r\n Expected string length 6 but was 5. Strings differ at index 5.\r\n Expected: {a\\r\\nb\\r\\n}\r\n But was: {a\\r\\nb\\r}\r\n -------------------^\r\n at line: 21 in /Users/mklement/Desktop/pg/t.Tests.ps1\r\n 21: Get-Content -Raw 'crlf.txt' | Should BeExactly $crlfText\r\n...\r\n```\r\n\r\nEnvironment data\r\n----------------\r\n\r\n\u003c!-- provide the output of $PSVersionTable -->\r\n\r\n```powershell\r\nPowerShell Core v6.0.0-beta.7 on macOS 10.12.6\r\nPowerShell Core v6.0.0-beta.7 on Ubuntu 16.04.3 LTS\r\nPowerShell Core v6.0.0-beta.7 on Microsoft Windows 10 Pro (64-bit; v10.0.15063)\r\n```\r\n","author":{"url":"https://github.com/mklement0","@type":"Person","name":"mklement0"},"datePublished":"2017-10-03T02:16:56Z","url":"https://github.com/PowerShell/PowerShell/issues/4980"}
| 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:9c8a3837-7ab4-3d5d-6f17-fb18c30ec8ff |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D1E4:160EF7:9AF26D:DE9387:6AFD9EF1 |
| html-safe-nonce | 5400d548d128c89f02a653104d2afaffa358fdbe9fd27c9d7b3b8892c835114a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMUU0OjE2MEVGNzo5QUYyNkQ6REU5Mzg3OjZBRkQ5RUYxIiwidmlzaXRvcl9pZCI6IjI0MDA4OTI1NjE0MTQ1Mjg3NTMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 5d7552f8ba20a6192c7e51ea9532275d5a77949fbd77837653fdeaf13cfe8393 |
| hovercard-subject-tag | issue:262284064 |
| 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/4980/issue_layout |
| twitter:image | https://opengraph.githubassets.com/fed0f09187ac5ae3f8568866b4dad4758b4a52ec1cdcc9ba07b100dfbe79c419/PowerShell/PowerShell/issues/4980 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/fed0f09187ac5ae3f8568866b4dad4758b4a52ec1cdcc9ba07b100dfbe79c419/PowerShell/PowerShell/issues/4980 |
| og:image:alt | Steps to reproduce Save the following to t.Tests.ps1 and invoke with ./t.Tests.ps1: Describe "Get-Content -Raw test" { BeforeAll { Push-Location TestDrive:/ $lfTextUnterminated = "a`nb" $lfText = "... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mklement0 |
| hostname | github.com |
| expected-hostname | github.com |
| None | bc86424ef34a73b386237872800e922d149d65ba907f63d6f150a2dcb8433bea |
| 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 | 927a6c5ab1c32b38830f1b9d3050c0b9e9aa92e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width