Fix: backslash before {{ template marker treated as literal character#205
Fix: backslash before {{ template marker treated as literal character#205
{{ template marker treated as literal character#205Conversation
Co-authored-by: blindzero <13959569+blindzero@users.noreply.github.com>
{{ template marker treated as literal character
blindzero
left a comment
There was a problem hiding this comment.
The way with double-double (four) braces {{{{ is very counter-intuitive. Can we use any other way of proper escaping here and make sure that \ directly in front of {{ braces it just identified properly and a single literal within '...' string?
…ormally Co-authored-by: blindzero <13959569+blindzero@users.noreply.github.com>
Reverted back to How it works:
So these all work as expected: # Bug fix: backslash before a template is just a literal backslash
'DOMAIN\{{Request.IdentityKeys.sAMAccountName}}' → 'DOMAIN\jdoe'
# Escape still works for literal {{ (no valid path+}} follows)
'Literal \{{ braces here' → 'Literal {{ braces here'
# Mixed: escape + template in same string
'Literal \{{ and template {{Request.Input.Name}}' → 'Literal {{ and template TestName' |
blindzero
left a comment
There was a problem hiding this comment.
@copilot I am missing some documentation to describe this behavior properly. check existing docs for substitutions part
…s.md Co-authored-by: blindzero <13959569+blindzero@users.noreply.github.com>
Added in commit
|
blindzero
left a comment
There was a problem hiding this comment.
@copilot I am missing some documentation to describe this behavior properly. check existing docs for substitutions part
…e standalone spec file Co-authored-by: blindzero <13959569+blindzero@users.noreply.github.com>
Documentation is now in |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e5e28fc06c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Pull request overview
This pull request fixes a bug where template substitution failed when a backslash character appeared immediately before the {{ template marker, even when the backslash was intended as a literal character (e.g., in Windows domain paths like DOMAIN\{{Request.IdentityKeys.sAMAccountName}}).
Changes:
- Fixed the escape sequence detection logic to use a negative lookahead pattern that distinguishes between escape sequences (
\{{not followed by a valid path) and literal backslashes before templates (\{{path}}) - Added comprehensive test coverage for the backslash-before-template case
- Enhanced documentation in
docs/use/workflows.mdwith a complete "Template substitution" section explaining syntax, escaping, and backslash behavior
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/IdLE.Core/Private/Resolve-IdleTemplateString.ps1 |
Core fix: replaced lookbehind-based escape detection with normalization using negative lookahead; Unicode placeholder prevents escaped {{ from being matched as templates |
tests/fixtures/workflows/template-tests/template-backslash.psd1 |
New test fixture for backslash-before-template case (e.g., DOMAIN\{{...}}) |
tests/Core/Resolve-IdleWorkflowTemplates.Tests.ps1 |
Added test case validating that backslash before {{ is treated as literal when followed by valid template path |
docs/use/workflows.md |
Added comprehensive template substitution documentation with examples of backslash behavior and escaping rules |
…test Co-authored-by: blindzero <13959569+blindzero@users.noreply.github.com>
Template strings with a backslash immediately before
{{(e.g. Windows domain paths likeDOMAIN\{{Request.IdentityKeys.sAMAccountName}}) threw a false "Unbalanced braces" error because the regex used(?<!\\)\{\{— treating\as an escape prefix that suppressed the opening brace count while}}was still counted.Changes
\{{remains the escape syntax for a literal{{in output. A negative lookahead regex restricted to the exact set of allowed roots distinguishes between an escape and a literal backslash before a template:\{{not followed by a valid allowed-root path+}}produces{{in output;\{{Request.<allowedRoot>...}}treats\as a literal character and resolves the template normally. Sequences like\{{Request.InvalidRoot}}or\{{Request..Bad}}are correctly escaped (same "unbalanced braces" error as original code — not sent to template parsing).(?<!\\)negative lookbehind from all regex patterns inResolve-IdleTemplateString.ps1. Template matching no longer treats\as special.\{{(escape form only) is replaced with a Unicode Private Use Area placeholder (U+E001) before matching, then restored to{{after resolution. Brace counts and error messages both operate on the normalized form; error messages display the original user-supplied value.template-escaped.psd1andtemplate-escaped-mixed.psd1use the\{{escape syntax (unchanged from original). Newtemplate-backslash.psd1andtemplate-escaped-invalid-root.psd1fixtures added.'DOMAIN\{{Request.IdentityKeys.sAMAccountName}}'resolves to'DOMAIN\jdoe'. Added regression test asserting\{{Request.InvalidRoot}}throws "Unbalanced braces" (not a path/root error), locking in backward-compatible behavior.docs/use/workflows.mdcovering syntax, allowed roots, pure vs. mixed placeholders, backslash behaviour, escaping rules, and validation errors.Original prompt
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.