@@ -92,7 +92,7 @@ LogGroup 'Name' {
9292
9393LogGroup ' ImportantFilePatterns' {
9494 $defaultImportantFilePatterns = @ (' ^src/' , ' ^README\.md$' )
95- if ($settings .ImportantFilePatterns -and $settings.ImportantFilePatterns.Count -gt 0 ) {
95+ if ($null -ne $settings.ImportantFilePatterns ) {
9696 $importantFilePatterns = @ ($settings.ImportantFilePatterns )
9797 Write-Host " Using ImportantFilePatterns from settings file: [$ ( $importantFilePatterns -join ' , ' ) ]"
9898 } elseif (-not [string ]::IsNullOrWhiteSpace($importantFilePatternsInput )) {
@@ -102,6 +102,15 @@ LogGroup 'ImportantFilePatterns' {
102102 $importantFilePatterns = $defaultImportantFilePatterns
103103 Write-Host " Using default ImportantFilePatterns: [$ ( $importantFilePatterns -join ' , ' ) ]"
104104 }
105+
106+ # Validate that all patterns are valid regular expressions
107+ foreach ($pattern in $importantFilePatterns ) {
108+ try {
109+ [void ][regex ]::new($pattern )
110+ } catch {
111+ throw " Invalid regex in ImportantFilePatterns: '$pattern '. $_ "
112+ }
113+ }
105114}
106115
107116$settings = [pscustomobject ]@ {
@@ -290,7 +299,8 @@ LogGroup 'Calculate Job Run Conditions:' {
290299 # Add a comment to open PRs explaining why build/test is skipped (best-effort, may fail if permissions not granted)
291300 if ($isOpenOrUpdatedPR ) {
292301 $patternRows = ($importantPatterns | ForEach-Object {
293- " | `` $_ `` | Matches files where path matches this pattern |"
302+ $escapedPattern = $_.Replace (' |' , ' \|' ).Replace(' ``' , ' \``' )
303+ " | `` $escapedPattern `` | Matches files where path matches this pattern |"
294304 }) -join " `n "
295305 $commentBody = @"
296306### No Significant Changes Detected
0 commit comments