From 0fc2e1fcad9a355f465761bc51c0d5d562da1014 Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Fri, 22 May 2026 17:35:19 -0700 Subject: [PATCH 1/3] Fix allowing empty string to be passed to resources --- dsc/tests/dsc_expressions.tests.ps1 | 14 ++++++++++++++ lib/dsc-lib/src/parser/mod.rs | 3 ++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/dsc/tests/dsc_expressions.tests.ps1 b/dsc/tests/dsc_expressions.tests.ps1 index 6086346cb..b618663ac 100644 --- a/dsc/tests/dsc_expressions.tests.ps1 +++ b/dsc/tests/dsc_expressions.tests.ps1 @@ -505,4 +505,18 @@ resources: $out.results[0].name | Should -Be 'SERVICE-api' } } + + It 'Expression that cannot be parsed is treated as string literal' { + $yaml = @' +$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json +resources: +- name: test + type: Microsoft.DSC.Debug/Echo + properties: + output: '' +'@ + $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 -BeNullOrEmpty + } } diff --git a/lib/dsc-lib/src/parser/mod.rs b/lib/dsc-lib/src/parser/mod.rs index db6553b41..cf572b1ea 100644 --- a/lib/dsc-lib/src/parser/mod.rs +++ b/lib/dsc-lib/src/parser/mod.rs @@ -56,7 +56,8 @@ impl Statement { }; let root_node = tree.root_node(); if root_node.is_error() { - return Err(DscError::Parser(t!("parser.failedToParseRoot", statement = statement).to_string())); + // if root node is error, treat as string literal + return Ok(Value::String(statement.to_string())); } if root_node.kind() != "statement" { return Err(DscError::Parser(t!("parser.invalidStatement", statement = statement).to_string())); From d2b1bf9fc1c8b46cc109021a80d0486e0941008d Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Fri, 22 May 2026 17:45:07 -0700 Subject: [PATCH 2/3] add test for just whitespace --- dsc/tests/dsc_expressions.tests.ps1 | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/dsc/tests/dsc_expressions.tests.ps1 b/dsc/tests/dsc_expressions.tests.ps1 index b618663ac..51d1d417c 100644 --- a/dsc/tests/dsc_expressions.tests.ps1 +++ b/dsc/tests/dsc_expressions.tests.ps1 @@ -506,17 +506,21 @@ resources: } } - It 'Expression that cannot be parsed is treated as string literal' { - $yaml = @' -$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json + 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: '' -'@ + 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 -BeNullOrEmpty + $out.results[0].result.actualState.output | Should -BeExactly $expression } } From b3bc7be49b206952d4c5587d3680f2c50421c7eb Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Fri, 22 May 2026 18:20:31 -0700 Subject: [PATCH 3/3] change fix --- lib/dsc-lib/src/parser/mod.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/dsc-lib/src/parser/mod.rs b/lib/dsc-lib/src/parser/mod.rs index cf572b1ea..d6d1713ca 100644 --- a/lib/dsc-lib/src/parser/mod.rs +++ b/lib/dsc-lib/src/parser/mod.rs @@ -51,13 +51,17 @@ 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())); }; let root_node = tree.root_node(); if root_node.is_error() { - // if root node is error, treat as string literal - return Ok(Value::String(statement.to_string())); + return Err(DscError::Parser(t!("parser.failedToParseRoot", statement = statement).to_string())); } if root_node.kind() != "statement" { return Err(DscError::Parser(t!("parser.invalidStatement", statement = statement).to_string()));