Repository navigation
[AdvancedPaste] Harden ToJsonFromXmlOrCsvAsync against clipboard read failures - #48124
Merged
Gordon Lam (yeelam-gordon) merged 1 commit intoMay 26, 2026
Conversation
… failures - Wrap clipboardData.GetTextAsync() in try/catch and return string.Empty on failure, matching the documented `returns empty string on any failure` contract of ToJsonFromXmlOrCsvAsync. - Update the matching unit test to decode input bytes as UTF-8 via Encoding.UTF8.GetString(input) and consume the awaited Task via GetAwaiter().GetResult(), for consistency with sibling tests in the same solution. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Gordon Lam (yeelam-gordon)
requested review from
Copilot and
leileizhang (lei9444)
and removed request for
leileizhang (lei9444)
May 26, 2026 00:55
Contributor
There was a problem hiding this comment.
Pull request overview
Hardens AdvancedPaste’s JSON conversion helper to uphold its non-throwing behavior when clipboard text retrieval fails, and updates the associated fuzz test to correctly interpret fuzz inputs as UTF-8 text while preserving exception types.
Changes:
- Wrap
DataPackageView.GetTextAsync()inToJsonFromXmlOrCsvAsyncwith try/catch and returnstring.Emptyon failure. - Update fuzz test input handling to
Encoding.UTF8.GetString(input)to actually exercise the helper with provided bytes. - Update fuzz test task consumption to use
GetAwaiter().GetResult()to avoidAggregateExceptionwrapping.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/modules/AdvancedPaste/AdvancedPaste/Helpers/JsonHelper.cs | Prevents clipboard text read failures from escaping as exceptions by returning string.Empty. |
| src/modules/AdvancedPaste/AdvancedPaste.FuzzTests/FuzzTests.cs | Improves fuzz input decoding and exception surfacing behavior for the JSON helper. |
Boliang Zhang (LegendaryBlair)
approved these changes
May 26, 2026
Gordon Lam (yeelam-gordon)
deleted the
dev/yeelam/advancedpaste-jsonhelper-input-handling
branch
May 26, 2026 02:59
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ToJsonFromXmlOrCsvAsyncinAdvancedPaste/Helpers/JsonHelper.csdocuments that it never throws and returns an empty string on any failure. The clipboard read at the top of the method (clipboardData.GetTextAsync()) was not wrapped, so a transient clipboard failure could surface as an exception to callers, contrary to the documented contract.This PR:
GetTextAsync()in a try/catch and returnsstring.Emptyon failure, matching the pattern already used by the JSON/XML/CSV parsing branches further down in the same method.Encoding.UTF8.GetString(input)) and consume the awaited task viaGetAwaiter().GetResult(), for consistency with sibling tests elsewhere in the solution.Validation
AdvancedPaste.sln. (Note: my machine has a pre-existing NuGet SDK resolver issue unrelated to this change — the same baseline fails onmainfor me. CI should be the source of truth.)