karate icon indicating copy to clipboard operation
karate copied to clipboard

prettyprint trims whitespace from XML node values

Open bouncysteve opened this issue 7 months ago • 0 comments

This issue is related to https://github.com/karatelabs/karate/issues/2385. The fix for #2385 prevented whitespace being trimmed from actual xml request/response values by using a copy of the xml string when logging with prettyprint. It created a separate problem that the node values used in the request/response and the values logged/written to the report can be different where leading/trailing whitespace is involved.

Whitespace in xml node values is significant, and should be accurately represented in logs/reports. This causes particular problems when trying to debug problems in systems where whitespace is significant.

The problem can be seen by running the following feature snippet with prettyprint enabled and observing that the value of setForecastRequestXml logged/printed does not match the actual value:


@scratchpad
Feature: whitespace preservation

Scenario:
 * def setForecastRequestXml = 
"""
<myroot>
    <myelement>T </myelement>
</myroot>
"""
 * match setForecastRequestXml //myelement == 'T '
 * karate.log(setForecastRequestXml)
 * match setForecastRequestXml //myelement == 'T '

Proposed solution is to remove the call to trimWhiteSpace in XmlUtils.toString(node, #pretty).

bouncysteve avatar Nov 24 '23 12:11 bouncysteve