PowerToys icon indicating copy to clipboard operation
PowerToys copied to clipboard

[Bug fix] Add a format validation step before format conversion.

Open shuaiyuanxx opened this issue 1 year ago • 1 comments

Summary of the Pull Request

This PR aims to fix the bug #35225 by introducing a new method IsJson to determine if a given text is in JSON format. The IsJson method is then utilized in the ToJsonFromXmlOrCsvAsync method to optimize the processing logic. If the text is already in JSON format, it is returned directly without further conversion from XML or CSV.

PR Checklist

  • [x] Closes: #35225
  • [ ] Communication: I've discussed this with core contributors already. If work hasn't been agreed, this work might be rejected
  • [x] Tests: Added/updated and all pass
  • [ ] Localization: All end user facing strings can be localized
  • [ ] Dev docs: Added/updated
  • [ ] New binaries: Added on the required places
  • [ ] Documentation updated: If checked, please file a pull request on our docs repo and link it here: #xxx

Detailed Description of the Pull Request / Additional comments

Key Changes:

  1. Added System.Text.Json namespace.
  2. Implemented IsJson method to check if the text is in JSON format.
  3. Updated ToJsonFromXmlOrCsvAsync method to use IsJson and return the text directly if it is already JSON.

Validation Steps Performed

Manually tested

shuaiyuanxx avatar Dec 18 '24 04:12 shuaiyuanxx

Before you merge plese check this similar PR: #34151

htcfreek avatar Dec 18 '24 05:12 htcfreek