Skip to content

Commit

Permalink
#314: Minor tweak to -is checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Badgerati committed Jul 30, 2019
1 parent 97a9eb7 commit 64bc35a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/Private/Authentication.ps1
Expand Up @@ -174,7 +174,7 @@ function Get-PodeAuthMiddlewareScript
$result = (Invoke-PodeScriptBlock -ScriptBlock $auth.Type.ScriptBlock -Arguments @($e, $auth.Type.Options) -Return -Splat)

# if data is a hashtable, then don't call validator (parser either failed, or forced a success)
if ($result -isnot 'hashtable') {
if ($result -isnot [hashtable]) {
$result += $auth.Options
$result = (Invoke-PodeScriptBlock -ScriptBlock $auth.ScriptBlock -Arguments $result -Return -Splat)
}
Expand Down
8 changes: 4 additions & 4 deletions src/Public/Responses.ps1
Expand Up @@ -345,7 +345,7 @@ function Write-PodeCsvResponse
}

'value' {
if ($Value -isnot 'string') {
if ($Value -isnot [string]) {
$Value = @(foreach ($v in $Value) {
New-Object psobject -Property $v
})
Expand Down Expand Up @@ -411,7 +411,7 @@ function Write-PodeHtmlResponse
}

'value' {
if ($Value -isnot 'string') {
if ($Value -isnot [string]) {
$Value = ($Value | ConvertTo-Html)
$Value = ($Value -join ([environment]::NewLine))
}
Expand Down Expand Up @@ -467,7 +467,7 @@ function Write-PodeJsonResponse
}

'value' {
if ($Value -isnot 'string') {
if ($Value -isnot [string]) {
$Value = ($Value | ConvertTo-Json -Depth 10 -Compress)
}
}
Expand Down Expand Up @@ -522,7 +522,7 @@ function Write-PodeXmlResponse
}

'value' {
if ($Value -isnot 'string') {
if ($Value -isnot [string]) {
$Value = @(foreach ($v in $Value) {
New-Object psobject -Property $v
})
Expand Down
8 changes: 4 additions & 4 deletions src/Public/Routes.ps1
Expand Up @@ -152,17 +152,17 @@ function Add-PodeRoute
if (!(Test-IsEmpty $Middleware)) {
@($Middleware) | ForEach-Object {
# check middleware is a type valid
if (($_ -isnot 'scriptblock') -and ($_ -isnot 'hashtable')) {
if (($_ -isnot [scriptblock]) -and ($_ -isnot [hashtable])) {
throw "One of the Route Middlewares supplied for the '[$($Method)] $($Path)' Route is an invalid type. Expected either ScriptBlock or Hashtable, but got: $($_.GetType().Name)"
}

# if middleware is hashtable, ensure the keys are valid (logic is a scriptblock)
if ($_ -is 'hashtable') {
if ($_ -is [hashtable]) {
if ($null -eq $_.Logic) {
throw "A Hashtable Middleware supplied for the '[$($Method)] $($Path)' Route has no Logic defined"
}

if ($_.Logic -isnot 'scriptblock') {
if ($_.Logic -isnot [scriptblock]) {
throw "A Hashtable Middleware supplied for the '[$($Method)] $($Path)' Route has has an invalid Logic type. Expected ScriptBlock, but got: $($_.Logic.GetType().Name)"
}
}
Expand All @@ -175,7 +175,7 @@ function Add-PodeRoute
$Middleware = @($Middleware)

for ($i = 0; $i -lt $Middleware.Length; $i++) {
if ($Middleware[$i] -is 'scriptblock') {
if ($Middleware[$i] -is [scriptblock]) {
$Middleware[$i] = @{
'Logic' = $Middleware[$i]
}
Expand Down
12 changes: 6 additions & 6 deletions src/Public/Utilities.ps1
Expand Up @@ -125,7 +125,7 @@ function Lock-PodeObject
return
}

if ($Object -is 'ValueType') {
if ($Object -is [valuetype]) {
throw 'Cannot lock value types'
}

Expand Down Expand Up @@ -657,23 +657,23 @@ function Test-IsEmpty
}

switch ($Value) {
{ $_ -is 'string' } {
{ $_ -is [string] } {
return [string]::IsNullOrWhiteSpace($Value)
}

{ $_ -is 'array' } {
{ $_ -is [array] } {
return ($Value.Length -eq 0)
}

{ $_ -is 'hashtable' } {
{ $_ -is [hashtable] } {
return ($Value.Count -eq 0)
}

{ $_ -is 'scriptblock' } {
{ $_ -is [scriptblock] } {
return ($null -eq $Value -or [string]::IsNullOrWhiteSpace($Value.ToString()))
}

{ $_ -is 'valuetype' } {
{ $_ -is [valuetype] } {
return $false
}
}
Expand Down

0 comments on commit 64bc35a

Please sign in to comment.