Skip to content

Conversation

@vbreuss
Copy link
Member

@vbreuss vbreuss commented Sep 6, 2025

This PR fixes the default encoding behavior in file write and append methods to use UTF-8 without BOM (byte order mark) instead of the system default encoding when no encoding is explicitly specified. This improves cross-platform compatibility.

Key Changes:

  • Modified file write/append methods to use UTF-8 encoding without preamble as default
  • Consolidated encoding logic into a single WriteText helper method
  • Added comprehensive tests to verify UTF-8 encoding behavior across all affected methods

when no encoding is specified in File write or append methods
@vbreuss vbreuss self-assigned this Sep 6, 2025
@vbreuss vbreuss added the bug Something isn't working label Sep 6, 2025
Copilot AI review requested due to automatic review settings September 6, 2025 15:37
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes the default encoding behavior in file write and append methods to use UTF-8 without BOM (byte order mark) instead of the system default encoding when no encoding is explicitly specified. This addresses issue #843 and improves cross-platform compatibility.

Key Changes:

  • Modified file write/append methods to use UTF-8 encoding without preamble as default
  • Consolidated encoding logic into a single WriteText helper method
  • Added comprehensive tests to verify UTF-8 encoding behavior across all affected methods

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
Source/Testably.Abstractions.Testing/FileSystem/FileMock.cs Refactored file write/append methods to use UTF-8 as default and consolidated logic into WriteText helper
Tests/Testably.Abstractions.Tests/FileSystem/File/WriteAllTextTests.cs Added tests verifying UTF-8 encoding and improved code formatting
Tests/Testably.Abstractions.Tests/FileSystem/File/WriteAllTextAsyncTests.cs Added tests for async text writing with UTF-8 encoding verification
Tests/Testably.Abstractions.Tests/FileSystem/File/WriteAllLinesTests.cs Added tests for line writing methods with UTF-8 encoding verification
Tests/Testably.Abstractions.Tests/FileSystem/File/WriteAllLinesAsyncTests.cs Added tests for async line writing with UTF-8 encoding and improved formatting
Tests/Testably.Abstractions.Tests/FileSystem/File/AppendAllTextTests.cs Added tests for text appending with UTF-8 encoding verification
Tests/Testably.Abstractions.Tests/FileSystem/File/AppendAllTextAsyncTests.cs Added tests for async text appending with UTF-8 encoding verification
Tests/Testably.Abstractions.Tests/FileSystem/File/AppendAllLinesTests.cs Added tests for line appending with UTF-8 encoding verification
Tests/Testably.Abstractions.Tests/FileSystem/File/AppendAllLinesAsyncTests.cs Added tests for async line appending with UTF-8 encoding verification

@sonarqubecloud
Copy link

sonarqubecloud bot commented Sep 6, 2025

@github-actions
Copy link

github-actions bot commented Sep 6, 2025

Test Results

    37 files  ±  0      37 suites  ±0   20m 45s ⏱️ -14s
44 075 tests +371  41 650 ✅ +371  2 425 💤 ±0  0 ❌ ±0 
85 682 runs  +372  76 695 ✅ +372  8 987 💤 ±0  0 ❌ ±0 

Results for commit dddacdf. ± Comparison against base commit 78b0421.

This pull request removes 35765 and adds 36136 tests. Note that renamed tests count towards both.
Testably.Abstractions.AccessControl.Tests.DirectoryInfoAclExtensionsTests+MockFileSystemTests ‑ SetAccessControl_ShouldNotUpdateTimes(path: "path01d46b97-9347-4592-a1bf-36454d0cc931")
Testably.Abstractions.AccessControl.Tests.DirectoryInfoAclExtensionsTests+MockFileSystemTests ‑ SetAccessControl_ShouldNotUpdateTimes(path: "path237e1037-63df-4e0a-aaee-58aead07239c")
Testably.Abstractions.AccessControl.Tests.DirectoryInfoAclExtensionsTests+MockFileSystemTests ‑ SetAccessControl_ShouldNotUpdateTimes(path: "path67e5fcfc-542c-4f05-9683-85bbcc6fa56c")
Testably.Abstractions.AccessControl.Tests.DirectoryInfoAclExtensionsTests+MockFileSystemTests ‑ SetAccessControl_ShouldNotUpdateTimes(path: "patha28c2a20-0c0b-4b87-954c-37b6fbd56f74")
Testably.Abstractions.AccessControl.Tests.DirectoryInfoAclExtensionsTests+MockFileSystemTests ‑ SetAccessControl_ShouldNotUpdateTimes(path: "patha385e8be-4c27-4f30-bc44-cd8fa9b27e60")
Testably.Abstractions.AccessControl.Tests.DirectoryInfoAclExtensionsTests+MockFileSystemTests ‑ SetAccessControl_ShouldNotUpdateTimes(path: "pathbf34c1dd-f9d2-48bc-98d5-bed94f3d9363")
Testably.Abstractions.AccessControl.Tests.DirectoryInfoAclExtensionsTests+MockFileSystemTests ‑ SetAccessControl_ShouldNotUpdateTimes(path: "pathdc6ac87b-4b9f-49bc-8ad6-5a6a8994c106")
Testably.Abstractions.AccessControl.Tests.DirectoryInfoAclExtensionsTests+RealFileSystemTests ‑ SetAccessControl_ShouldNotUpdateTimes(path: "path1d4d700d-d508-49e8-b120-d6c9237790de")
Testably.Abstractions.AccessControl.Tests.DirectoryInfoAclExtensionsTests+RealFileSystemTests ‑ SetAccessControl_ShouldNotUpdateTimes(path: "path274bf425-4ec7-474f-947b-2af6ef7b4a34")
Testably.Abstractions.AccessControl.Tests.DirectoryInfoAclExtensionsTests+RealFileSystemTests ‑ SetAccessControl_ShouldNotUpdateTimes(path: "path32b2716d-938c-4ba2-8488-de84719f3db5")
…
Testably.Abstractions.AccessControl.Tests.DirectoryInfoAclExtensionsTests+MockFileSystemTests ‑ SetAccessControl_ShouldNotUpdateTimes(path: "path0a226c94-820a-4f6c-8fef-4e8f48b2f8c0")
Testably.Abstractions.AccessControl.Tests.DirectoryInfoAclExtensionsTests+MockFileSystemTests ‑ SetAccessControl_ShouldNotUpdateTimes(path: "path0b6818b2-7ed5-410d-93e0-16d5c5ae9e2a")
Testably.Abstractions.AccessControl.Tests.DirectoryInfoAclExtensionsTests+MockFileSystemTests ‑ SetAccessControl_ShouldNotUpdateTimes(path: "path7eea03f2-2347-4a76-b9dc-c15572c0e0bf")
Testably.Abstractions.AccessControl.Tests.DirectoryInfoAclExtensionsTests+MockFileSystemTests ‑ SetAccessControl_ShouldNotUpdateTimes(path: "path99a81b76-453b-46c9-aa24-e45559b45692")
Testably.Abstractions.AccessControl.Tests.DirectoryInfoAclExtensionsTests+MockFileSystemTests ‑ SetAccessControl_ShouldNotUpdateTimes(path: "pathb2a0e310-3bbd-4e2a-a233-664e6d543876")
Testably.Abstractions.AccessControl.Tests.DirectoryInfoAclExtensionsTests+MockFileSystemTests ‑ SetAccessControl_ShouldNotUpdateTimes(path: "pathb65fc3d1-84f5-4de7-8913-9e64f07e1bb0")
Testably.Abstractions.AccessControl.Tests.DirectoryInfoAclExtensionsTests+MockFileSystemTests ‑ SetAccessControl_ShouldNotUpdateTimes(path: "pathdb932a9a-4221-4a07-84f6-a1a81a4ff132")
Testably.Abstractions.AccessControl.Tests.DirectoryInfoAclExtensionsTests+RealFileSystemTests ‑ SetAccessControl_ShouldNotUpdateTimes(path: "path34243ace-650d-4242-bb17-58ac9c7ab9b1")
Testably.Abstractions.AccessControl.Tests.DirectoryInfoAclExtensionsTests+RealFileSystemTests ‑ SetAccessControl_ShouldNotUpdateTimes(path: "path3bb609b1-f9f0-4e68-ad3b-36da6122fd6b")
Testably.Abstractions.AccessControl.Tests.DirectoryInfoAclExtensionsTests+RealFileSystemTests ‑ SetAccessControl_ShouldNotUpdateTimes(path: "path6ebbf531-25dc-4a11-9dcf-5187bf716e45")
…
This pull request removes 1784 skipped tests and adds 1784 skipped tests. Note that renamed tests count towards both.
Testably.Abstractions.AccessControl.Tests.DirectoryInfoAclExtensionsTests+MockFileSystemTests ‑ SetAccessControl_ShouldNotUpdateTimes(path: "path01d46b97-9347-4592-a1bf-36454d0cc931")
Testably.Abstractions.AccessControl.Tests.DirectoryInfoAclExtensionsTests+MockFileSystemTests ‑ SetAccessControl_ShouldNotUpdateTimes(path: "path237e1037-63df-4e0a-aaee-58aead07239c")
Testably.Abstractions.AccessControl.Tests.DirectoryInfoAclExtensionsTests+MockFileSystemTests ‑ SetAccessControl_ShouldNotUpdateTimes(path: "patha28c2a20-0c0b-4b87-954c-37b6fbd56f74")
Testably.Abstractions.AccessControl.Tests.DirectoryInfoAclExtensionsTests+MockFileSystemTests ‑ SetAccessControl_ShouldNotUpdateTimes(path: "patha385e8be-4c27-4f30-bc44-cd8fa9b27e60")
Testably.Abstractions.AccessControl.Tests.DirectoryInfoAclExtensionsTests+RealFileSystemTests ‑ SetAccessControl_ShouldNotUpdateTimes(path: "path1d4d700d-d508-49e8-b120-d6c9237790de")
Testably.Abstractions.AccessControl.Tests.DirectoryInfoAclExtensionsTests+RealFileSystemTests ‑ SetAccessControl_ShouldNotUpdateTimes(path: "path32b2716d-938c-4ba2-8488-de84719f3db5")
Testably.Abstractions.AccessControl.Tests.DirectoryInfoAclExtensionsTests+RealFileSystemTests ‑ SetAccessControl_ShouldNotUpdateTimes(path: "path7b1f4a05-a9fb-4c7b-b054-5ad28604a6fb")
Testably.Abstractions.AccessControl.Tests.DirectoryInfoAclExtensionsTests+RealFileSystemTests ‑ SetAccessControl_ShouldNotUpdateTimes(path: "pathb8c46517-0da4-4cce-a6a6-bb741df22da6")
Testably.Abstractions.Testing.Tests.FileSystem.FileMockTests ‑ GetUnixFileMode_SafeFileHandle_ShouldThrowPlatformNotSupportedExceptionOnWindows(path: "path34e2ccd4-4be6-4078-9fad-7d1d25abca7c")
Testably.Abstractions.Testing.Tests.FileSystem.FileMockTests ‑ GetUnixFileMode_SafeFileHandle_ShouldThrowPlatformNotSupportedExceptionOnWindows(path: "path7bf753fa-381d-4080-bef5-2dcf10d65238")
…
Testably.Abstractions.AccessControl.Tests.DirectoryInfoAclExtensionsTests+MockFileSystemTests ‑ SetAccessControl_ShouldNotUpdateTimes(path: "path7eea03f2-2347-4a76-b9dc-c15572c0e0bf")
Testably.Abstractions.AccessControl.Tests.DirectoryInfoAclExtensionsTests+MockFileSystemTests ‑ SetAccessControl_ShouldNotUpdateTimes(path: "path99a81b76-453b-46c9-aa24-e45559b45692")
Testably.Abstractions.AccessControl.Tests.DirectoryInfoAclExtensionsTests+MockFileSystemTests ‑ SetAccessControl_ShouldNotUpdateTimes(path: "pathb2a0e310-3bbd-4e2a-a233-664e6d543876")
Testably.Abstractions.AccessControl.Tests.DirectoryInfoAclExtensionsTests+MockFileSystemTests ‑ SetAccessControl_ShouldNotUpdateTimes(path: "pathdb932a9a-4221-4a07-84f6-a1a81a4ff132")
Testably.Abstractions.AccessControl.Tests.DirectoryInfoAclExtensionsTests+RealFileSystemTests ‑ SetAccessControl_ShouldNotUpdateTimes(path: "path34243ace-650d-4242-bb17-58ac9c7ab9b1")
Testably.Abstractions.AccessControl.Tests.DirectoryInfoAclExtensionsTests+RealFileSystemTests ‑ SetAccessControl_ShouldNotUpdateTimes(path: "path3bb609b1-f9f0-4e68-ad3b-36da6122fd6b")
Testably.Abstractions.AccessControl.Tests.DirectoryInfoAclExtensionsTests+RealFileSystemTests ‑ SetAccessControl_ShouldNotUpdateTimes(path: "path8eb37fca-9779-4a47-bc1c-7c0f81b77b58")
Testably.Abstractions.AccessControl.Tests.DirectoryInfoAclExtensionsTests+RealFileSystemTests ‑ SetAccessControl_ShouldNotUpdateTimes(path: "pathfbea2c2d-1a59-4d6e-bebd-564bd94bfb3c")
Testably.Abstractions.Testing.Tests.FileSystem.FileMockTests ‑ GetUnixFileMode_SafeFileHandle_ShouldThrowPlatformNotSupportedExceptionOnWindows(path: "path443d2591-7d58-4ab6-9eba-9c92ad321cd3")
Testably.Abstractions.Testing.Tests.FileSystem.FileMockTests ‑ GetUnixFileMode_SafeFileHandle_ShouldThrowPlatformNotSupportedExceptionOnWindows(path: "path8f3e215b-13ff-4dee-81d6-037f98083523")
…

@vbreuss vbreuss merged commit e2cffb6 into main Sep 6, 2025
14 checks passed
@vbreuss vbreuss deleted the topic/fix-default-encoding branch September 6, 2025 16:05
@github-actions
Copy link

github-actions bot commented Sep 6, 2025

This is addressed in release v4.3.3.

This was referenced Sep 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working state: released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: FileMock.WriteAllLines use system encoding instead of UTF8 without BOM

2 participants