diff --git a/dsc/tests/dsc_expressions.tests.ps1 b/dsc/tests/dsc_expressions.tests.ps1 index 6086346cb..51d1d417c 100644 --- a/dsc/tests/dsc_expressions.tests.ps1 +++ b/dsc/tests/dsc_expressions.tests.ps1 @@ -505,4 +505,22 @@ resources: $out.results[0].name | Should -Be 'SERVICE-api' } } + + It "Expression that cannot be parsed is treated as string literal: ''" -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 + } } diff --git a/lib/dsc-lib/src/parser/mod.rs b/lib/dsc-lib/src/parser/mod.rs index db6553b41..d6d1713ca 100644 --- a/lib/dsc-lib/src/parser/mod.rs +++ b/lib/dsc-lib/src/parser/mod.rs @@ -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())); };