Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,14 @@ internal void WriteObject(List<FormatValue> formatValueList)
// we always start with no indentation
_indentationManager.Clear();

bool hasContent = false;
foreach (FormatEntry fe in formatValueList)
{
if (fe.formatValueList.Count > 0)
{
hasContent = true;

// operate on each directive inside the list,
// carrying the indentation from invocation to invocation
GenerateFormatEntryDisplay(fe, 0);
}
// operate on each directive inside the list,
// carrying the indentation from invocation to invocation
GenerateFormatEntryDisplay(fe, 0);
}

// make sure that, if we have pending text in the buffer it gets flushed
if (hasContent)
{
WriteToScreen();
}
WriteToScreen();
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,11 @@ private void ExecuteFormatTokenList(TraversalInfo level,
// do the formatting and we will be done
if (cpt.control == null || cpt.control is FieldControlBody)
{
// Since it is a leaf node we just consider it an empty string and go
// on with formatting
if (val == null)
{
// Since it is a leaf node we just ignore it
return;
val = string.Empty;
}

FieldFormattingDirective fieldFormattingDirective = null;
Expand Down Expand Up @@ -779,3 +780,4 @@ private List<FormatValue> AddIndentationLevel(List<FormatValue> formatValueList)
private int _enumerationLimit;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -438,69 +438,3 @@ SelectScriptBlock
$ps.Streams.Error | Should -BeNullOrEmpty
}
}

Describe "Custom formatting returning nothing" -Tags "CI" {
BeforeAll {
$formatFilePath = Join-Path $TestDrive 'UpdateFormatDataTests.format.ps1xml'
$xmlContent = @'
<Configuration>
<ViewDefinitions>
<View>
<Name>Test</Name>
<ViewSelectedBy>
<TypeName>MyTestObject</TypeName>
</ViewSelectedBy>
<CustomControl>
<CustomEntries>
<CustomEntry>
<CustomItem>
<ExpressionBinding>
<ScriptBlock>
$null
</ScriptBlock>
</ExpressionBinding>
</CustomItem>
</CustomEntry>
</CustomEntries>
</CustomControl>
</View>
</ViewDefinitions>
</Configuration>
'@

Set-Content -Path $formatFilePath -Value $xmlContent
$ps = [powershell]::Create()
$iss = [initialsessionstate]::CreateDefault2()
$iss.Formats.Add($formatFilePath)
$rs = [runspacefactory]::CreateRunspace($iss)
$rs.Open()
$ps.Runspace = $rs
}

AfterAll {
$rs.Dispose()
$ps.Dispose()
}

It 'Newlines are not written if nothing is returned by custom format' {
$script = {
[PSCustomObject]@{
PSTypeName = 'MyTestObject'
Name = 'testing'
}
}

$null = $ps.AddScript($script).AddCommand('Out-String')
$ps.Streams.Error.Clear()

# one newline for start, one for grouping, and one for end
$expectedOutput = @'



'@ -replace '\r?\n', "^"

$ps.Invoke() -replace '\r?\n', "^" | Should -BeExactly $expectedOutput
$ps.Streams.Error | Should -BeNullOrEmpty
}
}