Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions dsc/tests/dsc_expressions.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -505,4 +505,22 @@ resources:
$out.results[0].name | Should -Be 'SERVICE-api'
}
}

It "Expression that cannot be parsed is treated as string literal: '<expression>'" -TestCases @(
@{ expression = '' }
@{ expression = ' ' }
) {
param($expression)
$yaml = @"
`$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
resources:
- name: test
type: Microsoft.DSC.Debug/Echo
properties:
output: '$expression'
"@
$out = dsc config get -i $yaml 2>$TestDrive/error.log | ConvertFrom-Json
$LASTEXITCODE | Should -Be 0 -Because (Get-Content $TestDrive/error.log -Raw | Out-String)
$out.results[0].result.actualState.output | Should -BeExactly $expression
}
}
5 changes: 5 additions & 0 deletions lib/dsc-lib/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ impl Statement {
return Ok(Value::String(statement.to_string()));
}

// if statement is empty or just whitespace, return as string without parsing
if statement.trim().is_empty() {
return Ok(Value::String(statement.to_string()));
}

let Some(tree) = &mut self.parser.parse(statement, None) else {
return Err(DscError::Parser(t!("parser.failedToParse", statement = statement).to_string()));
};
Expand Down
Loading