winget-cli icon indicating copy to clipboard operation
winget-cli copied to clipboard

Case-folding of "ProductCode" field

Open denelon opened this issue 3 years ago • 3 comments

Brief description of your issue

The client calls a REST source and passes in the productCode in lowercase. It's doing "Exact" matching when it probably should be doing "caseInsesnsitive" as referenced in:

  • https://github.com/microsoft/winget-cli-restsource/issues/166

Steps to reproduce

Add a manifest with a product code containing an upper case productCode to the REST source. Attempt to get a matching result with the client.

Expected behavior

A match is returned

Actual behavior

No match is returned.

Environment

winget --info                                                                   in pwsh at 10:54:42
Windows Package Manager (Preview) v1.4.2161-preview
Copyright (c) Microsoft Corporation. All rights reserved.

Windows: Windows.Desktop v10.0.25212.1000
System Architecture: X64
Package: Microsoft.DesktopAppInstaller v1.19.2161.0

Logs: %LOCALAPPDATA%\Packages\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\LocalState\DiagOutputDir

Links
---------------------------------------------------------------------------
Privacy Statement   https://aka.ms/winget-privacy
License Agreement   https://aka.ms/winget-license
Third Party Notices https://aka.ms/winget-3rdPartyNotice
Homepage            https://aka.ms/winget
Windows Store Terms https://www.microsoft.com/en-us/storedocs/terms-of-sale

Group Policy                               State
---------------------------------------------------
Enable Windows App Installer Hash Override Disabled

denelon avatar Sep 29 '22 16:09 denelon

I can't read C++ but in the spirit of Hacktoberfest I tried to look into this. I've found what I think are two possible sources of this problem, depending on what is called by what when:

First, this comment and code in WorkflowBase.cpp seems to imply ProductCodes are intentionally always searched "Exact": https://github.com/microsoft/winget-cli/blob/8d0996fc4921261b3eb46b0351793f53e8e918f4/src/AppInstallerCLICore/Workflows/WorkflowBase.cpp#L472-L477

and then further down the same file we have some more interesting logic that always searches for ProductCodes with MatchType "Exact", but does make an exception for portable packages specifically and treats those correctly with CaseInsensitive: https://github.com/microsoft/winget-cli/blob/8d0996fc4921261b3eb46b0351793f53e8e918f4/src/AppInstallerCLICore/Workflows/WorkflowBase.cpp#L1073-L1081

Then there's also some sussy stuff in ARPCorrelation.cpp, but to me it reads like these searches are only comparing the current ARP state to a cached/prior ARP state so maybe this code doesn't actually interact with a remote source:

https://github.com/microsoft/winget-cli/blob/8d0996fc4921261b3eb46b0351793f53e8e918f4/src/AppInstallerRepositoryCore/ARPCorrelation.cpp#L193-L223

If the issue really is in WorkflowBase.cpp where I pointed to I could open a PR, but my C++ skills won't go much beyond replacing MatchType::Exact with MatchType::CaseInsensitive so if there's a lot of other impacted or related code, or special exceptions would have to be made I couldn't do that.

jantari avatar Oct 05 '22 19:10 jantari

@ryfu-msft the origin of this came from winget-cli-restsource. Does this look like it's sufficient, or would more work be involved (test cases impacted)?

denelon avatar Oct 05 '22 20:10 denelon

Is there an update on this?

jantari avatar Feb 18 '24 00:02 jantari