Repository navigation
Restoring autoConvert behavior in Clipboard APIs - #11837
Conversation
|
Requesting @JeremyKuhne for review. |
There was a problem hiding this comment.
Pull request overview
This PR restores the pre-.NET 10 Clipboard retrieval behavior by ensuring autoConvert is only enabled for formats that historically relied on it (FileDrop and Bitmap), preventing unintended text format conversion that can result in mojibake.
Changes:
- Update
Clipboard.GetTypedDataIfAvailable<T>to useIsDataFormatAutoConvert(format)instead of always enablingautoConvert. - Add a unit test asserting
Clipboard.GetText(...)does not auto-convert betweenTextandUnicodeText.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/System/Windows/ClipboardTests.cs | Adds coverage to verify GetText does not auto-convert between auto-convertible text formats. |
| src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/clipboard.cs | Fixes the regression by applying the existing IsDataFormatAutoConvert policy to typed clipboard retrieval APIs. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
For reference, similar commit for WinForms: dotnet/winforms#14893 |
|
/backport to release/10.0 |
|
Started backporting to |
Restoring autoConvert behavior in Clipboard APIs (#11837) * Restoring autoConvert to .NET 8.0 in Clipboard APIs * Added unit test * Also setting autoConvert to false in one of the TryGetData overload. * Formatting Co-authored-by: Shyam Gupta <[email protected]>
|
/backport to release/11.0 |
|
Started backporting to |
Restoring autoConvert behavior in Clipboard APIs (#11837) * Restoring autoConvert to .NET 8.0 in Clipboard APIs * Added unit test * Also setting autoConvert to false in one of the TryGetData overload. * Formatting Co-authored-by: Shyam Gupta <[email protected]>
- UPSTREAM-PROVENANCE.md §1.1:逐件字节验证 —— 6414 件里 6384 件与 1cfc37f 逐字节相同、 29 件仅换行不同(非 git 搬入的伪影)、1 件是本仓刻意改的 .gitattributes、954 件为已登记裁剪 ⇒ 精确 commit 由「未定」改为「已钉死」,并给出复算命令 - README:上游出处那条改为「已钉死」;目录导航里写明「账一:构建只读 upstream/wpf/**,根目录那份不使用」 并指出 53 MB 的 windows-results.json 只能在 Windows 侧重录(账三口径) - ROUTES.md §8:把「上游化/去重」标为按裁定暂缓(只保持现状 + 文档写清)
Fixes one issue in dotnet/winforms#14322
Description
Till .NET 9.0,
autoConvertwas set to true only forFileDropandBitmapscenarios. However, since .NET 10, it is being set to true forGetAudioStream,GetFileDropList,GetImage, andGetTextAPIs inside the private methodGetTypedDataIfAvailable. This causes issues with GetText API with mojibake characters as described in bug dotnet/winforms#14322Customer Impact
There is no way for the app to know whether the clipboard contents were corrupted or if there is any problem with the API as it didn't get the desired data.
Regression
Yes - from .NET 9.0
Testing
Created a WPF app to write unicode data on the clipboard and another app to read it. Before the changes, the reader app returned several hits for mojibake characters. After fix, there were none.
Risk
This should be a very low risk change as this behavior was working fine in 9.0 and previous versions.
Microsoft Reviewers: Open in CodeFlow