Fix website not loading on Safari
It's caused by lookahead regex used in dash comment regex for inlining PowerShell. This commit changes dash comment inlining. - Change regex to one without lookahead. - Add more test cases for inlining dash comment in tricky situations. - Refactor makeInlineComment to be it's own function to easily test other regex options. - Document all regex alternatives. - Remove redundant null check (`||`) with adding safe navigation operator (`?`) to allow variable before check to be null instead of throwing exception.
This commit is contained in:
@@ -283,7 +283,7 @@ function getCommentCases(): IPipeTestCase[] {
|
||||
),
|
||||
},
|
||||
{
|
||||
name: 'can convert comment with inline comment parts',
|
||||
name: 'can convert comment with inline comment parts inside',
|
||||
input: getWindowsLines(
|
||||
'$text+= #Comment with < inside',
|
||||
'$text+= #Comment ending with >',
|
||||
@@ -295,14 +295,28 @@ function getCommentCases(): IPipeTestCase[] {
|
||||
'$text+= <# Comment with <# inline comment #> #>',
|
||||
),
|
||||
},
|
||||
{
|
||||
name: 'can convert comment with inline comment parts around', // Pretty uncommon
|
||||
input: getWindowsLines(
|
||||
'Write-Host "hi" # Comment ending line inline comment but not one #>',
|
||||
'Write-Host "hi" #>Comment starting like inline comment end but not one',
|
||||
// Following line does not compile as valid PowerShell referring to missing #> for inline comment
|
||||
'Write-Host "hi" <#Comment starting like inline comment start but not one',
|
||||
),
|
||||
expectedOutput: getSingleLinedOutput(
|
||||
'Write-Host "hi" <# Comment ending line inline comment but not one #> #>',
|
||||
'Write-Host "hi" <# >Comment starting like inline comment end but not one #>',
|
||||
'Write-Host "hi" <<# Comment starting like inline comment start but not one #>',
|
||||
),
|
||||
},
|
||||
{
|
||||
name: 'converts empty hash comment',
|
||||
input: getWindowsLines(
|
||||
'Write-Host "Lorem ipsus" #',
|
||||
'Write-Host "Comment without text" #',
|
||||
'Write-Host "Non-empty line"',
|
||||
),
|
||||
expectedOutput: getSingleLinedOutput(
|
||||
'Write-Host "Lorem ipsus" <##>',
|
||||
'Write-Host "Comment without text" <##>',
|
||||
'Write-Host "Non-empty line"',
|
||||
),
|
||||
},
|
||||
@@ -318,7 +332,7 @@ function getCommentCases(): IPipeTestCase[] {
|
||||
),
|
||||
},
|
||||
{
|
||||
name: 'trims whitespaces around from match',
|
||||
name: 'trims whitespaces around comment',
|
||||
input: getWindowsLines(
|
||||
'# Comment with whitespaces around ',
|
||||
'#\tComment with tabs around\t\t',
|
||||
|
||||
Reference in New Issue
Block a user