From d7363ea87a2a1d724355530420043243ff30d929 Mon Sep 17 00:00:00 2001 From: Sam Erde Date: Tue, 15 Oct 2024 12:07:27 -0400 Subject: [PATCH] Add JSON extension validation to parameter definition. --- src/PSPreworkout/Public/Out-JsonFile.ps1 | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/PSPreworkout/Public/Out-JsonFile.ps1 b/src/PSPreworkout/Public/Out-JsonFile.ps1 index 7328386..6edbe05 100644 --- a/src/PSPreworkout/Public/Out-JsonFile.ps1 +++ b/src/PSPreworkout/Public/Out-JsonFile.ps1 @@ -38,6 +38,7 @@ function Out-JsonFile { # Full path and filename to save the JSON to. [Parameter(Position = 1)] + [ValidatePattern('\.json$')] [string] $FilePath ) @@ -45,11 +46,6 @@ function Out-JsonFile { begin { # Validate the file path and extension. if ($FilePath) { - # Ensure the $FilePath provided includes a .json extension. - if ([System.IO.Path]::GetExtension($FilePath) -ne '.json') { - $FilePath = "${FilePath}.json" - } - # Ensure that a working directory is included in filepath. if ([string]::IsNullOrEmpty([System.IO.Path]::GetDirectoryName($FilePath))) { $FilePath = Join-Path -Path (Get-Location -PSProvider FileSystem).Path -ChildPath $FilePath