Skip to content

Commit

Permalink
Merge pull request #10 from wild-devops/develop
Browse files Browse the repository at this point in the history
Fix filters bug with ':' in input
  • Loading branch information
wild-devops authored Dec 4, 2021
2 parents 658bf43 + a3fefd6 commit 594980c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[![GitHub workflows (all tests)](https://github.com/wild-devops/pwshake/workflows/all%20tests/badge.svg)](../../actions/workflows/tests.yml)
[![GitHub release (latest by date)](https://img.shields.io/github/v/release/wild-devops/pwshake)](../../releases/tag/v1.5.2)
[![GitHub release (latest by date)](https://img.shields.io/github/v/release/wild-devops/pwshake)](../../releases/tag/v1.5.3)
[![PowerShell Gallery](https://img.shields.io/powershellgallery/v/pwshake)](https://www.powershellgallery.com/packages/pwshake)
[![PowerShell Gallery](https://img.shields.io/powershellgallery/dt/pwshake)](https://www.powershellgallery.com/packages/pwshake)

Expand Down Expand Up @@ -123,7 +123,7 @@ invoke_tasks:
attributes:
pwshake_module_path: /path/to/pwshake/module/source
pwshake_path: /absolute/path/to/your/working/directory
pwshake_version: 1.5.2
pwshake_version: 1.5.3
work_dir: /absolute/path/to/process/working/directory
pwshake_log_path: /absolute/path/to/your/working/directory/my_pwshake.log
some_attribute: this is an attribute value
Expand Down
4 changes: 2 additions & 2 deletions pwshake/pwshake.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'pwshake.psm1'

# Version number of this module.
ModuleVersion = '1.5.2'
ModuleVersion = '1.5.3'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down Expand Up @@ -52,7 +52,7 @@

# Modules that must be imported into the global environment prior to importing this module
RequiredModules = @(
@{ModuleName = "powershell-yaml"; RequiredVersion = "0.4.0"; Guid = "6a75a662-7f53-425a-9777-ee61284407da" }
@{ModuleName = "powershell-yaml"; RequiredVersion = "0.4.2"; Guid = "6a75a662-7f53-425a-9777-ee61284407da" }
)

# Assemblies that must be loaded prior to importing this module
Expand Down
4 changes: 2 additions & 2 deletions pwshake/scripts/Interpolate-Attributes.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ function Interpolate-Attributes {
do {
foreach ($substitute in (Get-Matches $json $regex 'subst')) {
"Interpolate-Attributes:$($counter):`$substitute:$substitute" | f-log-dbg
if ($substitute -match '^\$\((?<eval>.*)\)$') {
if ($substitute -match '(?ms)^\$\((?<eval>.*)\)$') {
"Interpolate-Attributes:$($counter):`$eval:{$($matches.eval)}" | f-log-dbg
$value = "`"$($matches.eval)`"" | ConvertFrom-Json | Invoke-Expression
} elseif ($substitute -match '^(?<filter>\$\S+):(?<input>.*)') {
} elseif ($substitute -match '(?ms)^(?<filter>\$\S+?):(?<input>.*)$') {
"Interpolate-Attributes:$($counter):`$filter:{$($matches.filter)}:`$input:{$($matches.input)}" | f-log-dbg
$value = "`"$($matches.input)`"" | ConvertFrom-Json | & f-$($matches.filter)
"Interpolate-Attributes:$($counter):`$value:{$value}" | f-log-dbg
Expand Down
14 changes: 13 additions & 1 deletion tests/Interpolate-Attributes.Context.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Context "Interpolate-Attributes" {
@{When='{{a}}';And='dev';Then='.dev'}
@{When='{{b}}';And='dev';Then='.dev'}
) {param($When, $And, $Then)
$subst = '{{$("' + $When + '" | ? {$_} | % {".$_"})}}'
$subst = '{{$("' + $When + '" | ? {$_} | % {' + [Environment]::NewLine + '".$_"})}}'
(Interpolate-Attributes @{
attributes = @{
a = $And
Expand Down Expand Up @@ -133,4 +133,16 @@ Context "Interpolate-Attributes" {
$actual.attributes.b | Should -Be $chars
$actual.attributes.c | Should -Be $chars
}

It "Should substitute filters with multiple ':' separators and multiline input" {
$expected = "https://some.url/?other`nvalue1:value2"

Interpolate-Attributes @{
attributes = @{a="{{b}}";b='{{$secured:{{c}}}}';c=$expected};
} | New-Variable -Name actual

$actual.attributes.a | Should -Be $expected
$actual.attributes.b | Should -Be $expected
$actual.attributes.c | Should -Be $expected
}
}

0 comments on commit 594980c

Please sign in to comment.