Skip to content

Preserve whitespace-only argument values when loading XAML (STUD-80981) - #403

Open
PavelDrg wants to merge 1 commit into
developfrom
fix/xaml_parser_preserve_whitespace
Open

Preserve whitespace-only argument values when loading XAML (STUD-80981)#403
PavelDrg wants to merge 1 commit into
developfrom
fix/xaml_parser_preserve_whitespace

Conversation

@PavelDrg

@PavelDrg PavelDrg commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Description

A whitespace-only value in an Invoke Workflow File argument — e.g. a single space — is silently dropped when the workflow XAML is loaded. The value reaches disk correctly as <InArgument x:TypeArguments="x:String" xml:space="preserve"> </InArgument>, but the parser discards it on load, so the argument comes back empty and the next save persists the loss.

Root cause

XamlPullParser.Logic_IsDiscardableWhitespace decides whether whitespace-only text at the end of an element is significant. For elements with a content property it only keeps the whitespace when that property is a string or a whitespace-significant collection. InArgument<T> declares both a content property (Expression) and a type converter, so the content-property branch discards the whitespace before the type-converter branch — which would have kept it — is ever consulted. The original comment in that method already describes the intended behavior: .NET 3.0 surfaced whitespace for type-convertible content properties as long as the content property had not been set.

Fix

  • The content-property branch now falls through to the same type-converter check used for elements without a content property: preserved whitespace-only content is surfaced as initialization text when the element is type convertible, no real properties forced constructor use, and nothing has been assigned to the content property. The surfaced text flows through the existing initialization-text path, so InArgumentConverter receives the whitespace and produces Literal<string> with the original value.
  • A new ContentPropertyAssigned flag on XamlParserFrame tracks whether the current element's content property has already received content. PreviousChildType cannot serve this purpose because the implicit EndMember emitted after each content item resets it. The gate keeps documents with inherited xml:space="preserve" and child-element expressions (<InArgument><VisualBasicValue/> </InArgument>) loading exactly as before.

Property elements and attribute-set properties were already excluded via ForcedToUseConstructor, and frames are Reset() on recycling, so no stale state is possible.

Tests

Added to TestCases.Workflows/XamlTests.cs, running in both the JIT and AOT expression-compilation variants:

  • an end-to-end workflow where whitespace-only argument values (space, double space, tab) round-trip through Assign and come back intact — compiled only for net6.0, since the net6.0-windows test build uses the WPF System.Xaml which does not have the fix
  • a guard that a document-wide xml:space='preserve' with a child-element expression still loads

Suites run locally: TestCases.Workflows 261+255 passed, TestCases.Xaml 92+92, TestCases.Activities 770+770 — zero failures. System.Xaml.TestCases has a pre-existing compile error on develop (XamlObjectWriterTest.cs:2129, CS1503 with recent SDKs) unrelated to this change.

Jira

https://uipath.atlassian.net/browse/STUD-80981

Context: review discussion on https://github.com/UiPath/Studio/pull/29107 concluded the proper fix belongs here in the parser, where the whitespace is actually dropped, rather than in a Studio-side load repair.

🤖 Generated with Claude Code

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@PavelDrg
PavelDrg marked this pull request as draft August 3, 2026 13:47
@PavelDrg
PavelDrg requested a review from david-barzi August 3, 2026 13:59
@PavelDrg
PavelDrg marked this pull request as ready for review August 3, 2026 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants