Skip to content
This repository was archived by the owner on Sep 27, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions PSSwagger/PSSwagger.Resources.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,6 @@ ConvertFrom-StringData @'
InvalidPSMetaFlattenParameter=Flatten property is specified as 'true' for an invalid parameter '{0}' with type '{1}'.
InvalidHeaderFileExtension=Header '{0}' file extension should be '.txt'.
InvalidHeaderFilePath=The specified value '{0}' for Header parameter is should be a valid file path.
HeaderContentTwoHyphenWarning=The specified Header content has '--', replacing '--' with '=='.
###PSLOC
'@
8 changes: 8 additions & 0 deletions PSSwagger/PSSwagger.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -1114,6 +1114,14 @@ function Get-HeaderContent {
}
}

# Escape block comment character sequence, if any, using the PowerShell escape character, grave-accent(`).
$HeaderContent = $HeaderContent.Replace('<#', '<`#').Replace('#>', '#`>')

if ($HeaderContent -match '--') {
Write-Warning -Message $LocalizedData.HeaderContentTwoHyphenWarning
$HeaderContent = $HeaderContent.Replace('--', '==')
}

return $HeaderContent
}

Expand Down
18 changes: 18 additions & 0 deletions Tests/PSSwagger.Unit.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,24 @@ Describe "PSSwagger Unit Tests" -Tag @('BVT', 'DRT', 'UnitTest', 'P0') {
It "Get-HeaderContent should return MICROSOFT_APACHE_NO_CODEGEN header content with '-Header MICROSOFT_APACHE_NO_CODEGEN'" {
Get-HeaderContent -SwaggerDict @{Info = @{Header = 'MICROSOFT_APACHE_NO_CODEGEN'}} | Should BeExactly $MicrosoftApacheLicenseHeader
}

It 'Get-HeaderContent should escape <#' {
Get-HeaderContent -SwaggerDict @{Info = @{Header = 'Header content with <#'}} | Should BeExactly 'Header content with <`#'
}

It 'Get-HeaderContent should escape #>' {
Get-HeaderContent -SwaggerDict @{Info = @{Header = 'Header content with #>'}} | Should BeExactly 'Header content with #`>'
}

It 'Get-HeaderContent should replace -- with ==' {
Get-HeaderContent -SwaggerDict @{Info = @{Header = 'Header content with --'}} -WarningVariable wv -WarningAction SilentlyContinue | Should BeExactly 'Header content with =='
$wv | Should not BeNullOrEmpty
$wv.Message -match '==' | Should Be $true
}

It "Get-HeaderContent should escape '<#' and '#>', and replace '--' with '=='" {
Get-HeaderContent -SwaggerDict @{Info = @{Header = 'Header content with <# PS comment #> and --.'}} -WarningAction SilentlyContinue | Should BeExactly 'Header content with <`# PS comment #`> and ==.'
}
}

Context "Get-CSharpModelName Unit Tests" {
Expand Down