Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get-FolderSize using FolderName parameter fails when a name contains regex symbols #24

Open
karlronsaria opened this issue Mar 28, 2021 · 1 comment

Comments

@karlronsaria
Copy link

Hi!

I love this tool, and I've been using it for a while now. I ran into a problem when I tried using it on my Program Files. When I enter

Get-FolderSize -FolderName Notepad++

I get the error

parsing "Notepad++" - Nested quantifier +.
At C:\Program Files\WindowsPowerShell\Modules\PSFolderSize\1.6.9\Functions\Private\Get-FolderList.ps1:58 char:21
+                     ($_.BaseName -match "$FolderName") -and
+                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (:) [], ArgumentException
    + FullyQualifiedErrorId : System.ArgumentException

I noticed this is caused by lines 54 and 65 in PSFolderSize/PSFolderSize/Functions/Private/Get-FolderList.ps1.

($_.FullName -match ".+$FolderName.+")   -and 
($_.BaseName -match "$FolderName") -and 

I was able to fix it by using [Regex]::Escape, recommended in https://stackoverflow.com/questions/23651862/powershell-how-to-escape-all-regex-characters-from-a-string.

($_.FullName -match (".+" + [Regex]::Escape($FolderName) + ".+")) -and 
($_.BaseName -match [Regex]::Escape($FolderName)) -and 

Thank you for your time.

@gngrninja
Copy link
Owner

I will work on adding this in, thanks for the report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants