Skip to content

Fix parse error in Windows PowerShell #136

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

Merged
merged 1 commit into from
Apr 12, 2025
Merged

Conversation

johlju
Copy link
Contributor

@johlju johlju commented Feb 22, 2025

This will fix issue #135.

In Windows PowerShell this will not work:

@{
    Version       = if (($V = $BuildInfo.SemVer.Split("+")[0].Split("-", 2)[0])) {
                        [version]$V
                    }
    Prerelease    = $BuildInfo.SemVer.Split("+")[0].Split("-", 2)[1]
    BuildMetadata = $BuildInfo.SemVer.Split("+", 2)[1]
}

but this will:

@{
    Prerelease    = $BuildInfo.SemVer.Split("+")[0].Split("-", 2)[1]
    BuildMetadata = $BuildInfo.SemVer.Split("+", 2)[1]
    Version       = if (($V = $BuildInfo.SemVer.Split("+")[0].Split("-", 2)[0])) {
                        [version]$V
                    }
}

By moving the Version property at the end there is no parse error.

This error does not occur on PowerShell 7.x. It handles if-blocks in hashtables better apparently.

@dan-hughes
Copy link

@Jaykul, any chance you can get this merged? Anything testing with PS5 is failing currently.

@Jaykul
Copy link
Member

Jaykul commented Apr 12, 2025

Holy cow, I thought we already merged this ...

@Jaykul Jaykul merged commit b4d5aaf into PoshCode:main Apr 12, 2025
4 checks passed
@johlju johlju deleted the fix/issue-135 branch April 13, 2025 08:40
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

Successfully merging this pull request may close these issues.

3 participants