Skip to content

Write-TemplateItem -Replace operator #113

Description

@ZanattaMichael

Within Write-TemplateItem you are using -Replace parameter to perform string replacement of the
placeholders and subsequent string values.

When ingesting large scripts with regex within them (using a scriptblock from a manifest), PowerShell malforms the replacement string, causing the template to be applied twitch within it. If this statement is only performing a string replacement and not requiring regex, can you please adjust to code to use the .Replace method instead?

PS I have encountered this issue with plaster as well.

foreach ($param in $Item.ContentParameterScript)
{
    $text = $text -replace "$($identifier)!$([regex]::Escape($param))!$($identifier)", $ParameterScript[$param]
}

Proposed Replacement:

foreach ($param in $Item.ContentParameterScript)
{
	$text = $text.Replace("$($identifier)!$([regex]::Escape($param))!$($identifier)", $ParameterScript[$param])
}

I can confirm that it is working correctly. (I may have made the adjustment to your psm1 locally. :-D :-D)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions