PowerShell / PSResourceGet

PSResourceGet is the package manager for PowerShell
https://www.powershellgallery.com/packages/Microsoft.PowerShell.PSResourceGet
MIT License
473 stars 90 forks source link

`Find-PSResource -Repository 'PSGallery'` with NuGet version range returns no versions #1630

Open o-l-a-v opened 2 months ago

o-l-a-v commented 2 months ago

Prerequisites

Steps to reproduce

Find-PSResource -Repository 'PSGallery' -Name 'Az' -Version '(9,10)' returns nothing.

If using -Debug we can se that the API request looks like below, which to me looks fine.

I think this is a problem with the PowerShell Gallery API. It works with NuGet v3 API shim pwsh.gallery like so:

PS> Find-PSResource -Repository 'pwsh.gallery' -Name 'Az' -Version '(9,10)'

Name Version Prerelease Repository   Description
---- ------- ---------- ----------   -----------
Az   9.7.1              pwsh.gallery
Az   9.7.0              pwsh.gallery
Az   9.6.0              pwsh.gallery
Az   9.5.0              pwsh.gallery
Az   9.4.0              pwsh.gallery
Az   9.3.0              pwsh.gallery
Az   9.2.0              pwsh.gallery
Az   9.1.1              pwsh.gallery
Az   9.1.0              pwsh.gallery
Az   9.0.1              pwsh.gallery

PS>

Expected behavior

PS> Find-PSResource -Repository 'PSGallery' -Name 'Az' -Version '(9,10)'

Name Version Prerelease Repository Description
---- ------- ---------- ---------- -----------
Az   9.7.1              PSGallery  Microsoft Azure PowerShell - Cmdlets to manage resources in Azure. This module is compatible with PowerShell and Windows Pow…
Az   9.7.0              PSGallery  Microsoft Azure PowerShell - Cmdlets to manage resources in Azure. This module is compatible with PowerShell and Windows Pow…
Az   9.6.0              PSGallery  Microsoft Azure PowerShell - Cmdlets to manage resources in Azure. This module is compatible with PowerShell and Windows Pow…
Az   9.5.0              PSGallery  Microsoft Azure PowerShell - Cmdlets to manage resources in Azure. This module is compatible with PowerShell and Windows Pow…
Az   9.4.0              PSGallery  Microsoft Azure PowerShell - Cmdlets to manage resources in Azure. This module is compatible with PowerShell and Windows Pow…
Az   9.3.0              PSGallery  Microsoft Azure PowerShell - Cmdlets to manage resources in Azure. This module is compatible with PowerShell and Windows Pow…
Az   9.2.0              PSGallery  Microsoft Azure PowerShell - Cmdlets to manage resources in Azure. This module is compatible with PowerShell and Windows Pow…
Az   9.1.1              PSGallery  Microsoft Azure PowerShell - Cmdlets to manage resources in Azure. This module is compatible with PowerShell and Windows Pow…
Az   9.1.0              PSGallery  Microsoft Azure PowerShell - Cmdlets to manage resources in Azure. This module is compatible with PowerShell and Windows Pow…
Az   9.0.1              PSGallery  Microsoft Azure PowerShell - Cmdlets to manage resources in Azure. This module is compatible with PowerShell and Windows Pow…

PS>

Actual behavior

PS> Find-PSResource -Repository 'PSGallery' -Name 'Az' -Version '(9,10)'
PS>

Error details

No response

Environment data

PowerShell v7.4.1
Microsoft.PowerShell.PSResourceGet v1.0.4.1

Visuals

No response

kilasuit commented 2 months ago

if you run the query in the browser you get this error message image

if you take that query and properly encode it like this then you get results so should be a simple enough fix however perhaps also needs some cleanup


irm "https://www.powershellgallery.com/api/v2/FindPackagesById()?id=%27Az%27&$orderby=NormalizedVersion%20desc&$inlinecount=allpages&$skip=0&$filter=IsPrerelease%20eq%20false%20and%20Id%20eq%20%27Az%27%20and%20NormalizedVersion%20gt%20%279.0.0%27%20and%20NormalizedVersion%20lt%20%2710.0.0"
o-l-a-v commented 2 months ago

@kilasuit Somehow your PowerShell command gives results, but

  1. You haven't escaped $, and
  2. You're missing the last ' / %27.

Which gives a rather strange URI if:

"https://www.powershellgallery.com/api/v2/FindPackagesById()?id=%27Az%27&$orderby=NormalizedVersion%20desc&$inlinecount=allpages&$skip=0&$filter=IsPrerelease%20eq%20false%20and%20Id%20eq%20%27Az%27%20and%20NormalizedVersion%20gt%20%279.0.0%27%20and%20NormalizedVersion%20lt%20%2710.0.0" | clip

Gives

https://www.powershellgallery.com/api/v2/FindPackagesById()?id=%27Az%27&=NormalizedVersion%20desc&=allpages&=0&=IsPrerelease%20eq%20false%20and%20Id%20eq%20%27Az%27%20and%20NormalizedVersion%20gt%20%279.0.0%27%20and%20NormalizedVersion%20lt%20%2710.0.0

Which gives a result in the browser. But $filter etc. is stripped.

anamnavi commented 2 months ago

@o-l-a-v thanks for creating this issue, we're aware of this being an issue due to a version comparison bug. We have this in our backlog