iainbrighton/PScribo

HTML tables add   in place of empty string input

Closed this issue · 3 comments

v. 0.7.21.110

When passing an object to a table where the input is an empty string the HTML formatter enters a non-breaking space token ( ), and Word formats it as empty input. If i change it to $null instead of [string]::empty HTML formats it correctly but i get an error from word.

Here's the code to reproduce

$doc = Document -Name Table-Test {
    Section -Name htmlfail {
        $input = New-Object -type psobject | Select Prop1, Prop2, Prop3
        $input.prop1 = 'Ok'
        $input.prop2 = [string]::Empty
        $input.prop3 = 'also ok'
        $input | table -columns Prop1, Prop2, Prop3 -Headers 'Property 1', 'Property 2', 'Property 3'
    }
    Section -Name wordfail {
        $input = New-Object -type psobject | Select Prop1, Prop2, Prop3
        $input.prop1 = 'Ok'
        $input.prop2 = $null
        $input.prop3 = 'also ok'
        $input | table -columns Prop1, Prop2, Prop3 -Headers 'Property 1', 'Property 2', 'Property 3'
    }
}

$doc | export-document -format html,word -path .\

Here's the specific error I get from Word

PSMessageDetails      :
Exception             : System.Management.Automation.RuntimeException: You cannot call a method on a null-valued expression.
                           at CallSite.Target(Closure , CallSite , Object )
                           at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)
                           at CallSite.Target(Closure , CallSite , Object )
                           at OutWordTable<Process>(Closure , FunctionContext )
TargetObject          :
CategoryInfo          : InvalidOperation: (:) [], RuntimeException
FullyQualifiedErrorId : InvokeMethodOnNull
ErrorDetails          :
InvocationInfo        : System.Management.Automation.InvocationInfo
ScriptStackTrace      : at OutWordTable<Process>, <No file>: line 538
                        at OutWordSection<Process>, <No file>: line 86
                        at OutWord<Process>, <No file>: line 57
                        at Export-Document<Process>, <No file>: line 64
                        at <ScriptBlock>, <No file>: line 18
PipelineIterationInfo : {}

@jbruett Thanks for reporting - I had already picked up on the Word error, but not noticed the HTML output. Can you check whether the Dev branch fixes this for you?

Sure does! both examples above run, give expected output and no errors! thanks for the fast turnaround on this Iain!!!

Great work @iainbrighton! This was troubling me but I had thought it was my code. Everything looks good in your update. Any chance of pushing this to master and PSGallery as I have a demo coming in a couple of weeks? I'd love users to be able to get hold of this release after my demo.