Skip to content
Open
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
4 changes: 3 additions & 1 deletion src/Controls/src/SourceGen/KnownMarkups.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,9 @@ internal static bool ProvideValueForStyleSheetExtension(ElementNode markupNode,

if (styleNode != null)
{
value = $"global::Microsoft.Maui.Controls.StyleSheets.StyleSheet.FromString(@\"{(styleNode as ValueNode)!.Value as string}\")";
// Escape quotes for verbatim string literal (@"") by doubling them
var styleContent = ((styleNode as ValueNode)!.Value as string)?.Replace("\"", "\"\"") ?? "";
value = $"global::Microsoft.Maui.Controls.StyleSheets.StyleSheet.FromString(@\"{styleContent}\")";
return true;
}
else // sourceNode != null
Expand Down
26 changes: 26 additions & 0 deletions src/Controls/tests/Xaml.UnitTests/Issues/Maui33867.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Microsoft.Maui.Controls.Xaml.UnitTests.Maui33867">
<!-- Test: Inline StyleSheet with CDATA content (from StyleSheetsPage) -->
<ContentPage.Resources>
<StyleSheet>
<![CDATA[
stacklayout {
-maui-spacing: 15;
}
entry {
background-color: red;
-maui-placeholder: "CSS Placeholder";
-maui-placeholder-color: blue;
}
]]>
</StyleSheet>
</ContentPage.Resources>
<StackLayout Padding="30,60,30,30">
<Label x:Name="testLabel" Text="3 red text boxes spaced apart with a blue placeholder." />
<Entry />
<Entry />
<Entry />
</StackLayout>
</ContentPage>
47 changes: 47 additions & 0 deletions src/Controls/tests/Xaml.UnitTests/Issues/Maui33867.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using Xunit;

using static Microsoft.Maui.Controls.Xaml.UnitTests.MockSourceGenerator;

namespace Microsoft.Maui.Controls.Xaml.UnitTests;

public partial class Maui33867 : ContentPage
{
public Maui33867() => InitializeComponent();

[Collection("Issue")]
public class Tests
{
[Theory]
[XamlInflatorData]
internal void InlineStyleSheetWithCDATA(XamlInflator inflator)
{
// This test reproduces issue #33867:
// XSG doesn't correctly parse inline StyleSheet elements with CDATA sections.
if (inflator == XamlInflator.SourceGen)
{
var result = CreateMauiCompilation()
.WithAdditionalSource(
"""
namespace Microsoft.Maui.Controls.Xaml.UnitTests;
public partial class Maui33867 : ContentPage
{
public Maui33867() => InitializeComponent();
}
""")
.RunMauiSourceGenerator(typeof(Maui33867));

// Verify no compilation errors
Assert.Empty(result.Diagnostics);
}
else
{
var page = new Maui33867(inflator);
Assert.NotNull(page);
Assert.NotNull(page.testLabel);
}
Comment on lines +39 to +44
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we should actually inflate the page even with source gen, right? This else is incorrect.

}
}
}
Loading