[X] consume trailing spaces in markup (#9850)

- fixes #9212
This commit is contained in:
Stephane Delcroix 2020-03-09 20:41:18 +01:00 коммит произвёл GitHub
Родитель 0a84286656
Коммит 93cbdf2040
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 7 добавлений и 6 удалений

Просмотреть файл

@ -4,5 +4,5 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="using:Xamarin.Forms.Xaml.UnitTests" xmlns:local="using:Xamarin.Forms.Xaml.UnitTests"
x:Class="Xamarin.Forms.Xaml.UnitTests.Gh9212"> x:Class="Xamarin.Forms.Xaml.UnitTests.Gh9212">
<Label x:Name="label" Text="{local:Gh9212Markup 'Foo, Bar'}" /> <Label x:Name="label" Text="{local:Gh9212Markup 'Foo, Bar' }" />
</ContentPage> </ContentPage>

Просмотреть файл

@ -30,7 +30,7 @@ namespace Xamarin.Forms.Xaml.UnitTests
[TearDown] public void TearDown() => Device.PlatformServices = null; [TearDown] public void TearDown() => Device.PlatformServices = null;
[Test] [Test]
public void SingleQuoteInMarkupValue([Values(false, true)]bool useCompiledXaml) public void SingleQuoteAndTrailingSpaceInMarkupValue([Values(false, true)]bool useCompiledXaml)
{ {
var layout = new Gh9212(useCompiledXaml); var layout = new Gh9212(useCompiledXaml);
Assert.That(layout.label.Text, Is.EqualTo("Foo, Bar")); Assert.That(layout.label.Text, Is.EqualTo("Foo, Bar"));

Просмотреть файл

@ -122,7 +122,6 @@ namespace Xamarin.Forms.Xaml
protected Property ParseProperty(IServiceProvider serviceProvider, ref string remaining) protected Property ParseProperty(IServiceProvider serviceProvider, ref string remaining)
{ {
char next;
object value = null; object value = null;
string str_value; string str_value;
string name; string name;
@ -131,7 +130,7 @@ namespace Xamarin.Forms.Xaml
if (remaining[0] == '{') if (remaining[0] == '{')
return ParsePropertyExpression(null, serviceProvider, ref remaining); return ParsePropertyExpression(null, serviceProvider, ref remaining);
str_value = GetNextPiece(serviceProvider, ref remaining, out next); str_value = GetNextPiece(serviceProvider, ref remaining, out var next);
if (next == '=') { if (next == '=') {
remaining = remaining.TrimStart(); remaining = remaining.TrimStart();
if (remaining[0] == '{') if (remaining[0] == '{')
@ -147,7 +146,7 @@ namespace Xamarin.Forms.Xaml
return new Property { last = next == '}', name = name, strValue = str_value, value = value }; return new Property { last = next == '}', name = name, strValue = str_value, value = value };
} }
private Property ParsePropertyExpression(string prop, IServiceProvider serviceProvider, ref string remaining) Property ParsePropertyExpression(string prop, IServiceProvider serviceProvider, ref string remaining)
{ {
bool last; bool last;
var value = ParseExpression(ref remaining, serviceProvider); var value = ParseExpression(ref remaining, serviceProvider);
@ -165,7 +164,7 @@ namespace Xamarin.Forms.Xaml
return new Property { last = last, name = prop, strValue = value as string, value = value }; return new Property { last = last, name = prop, strValue = value as string, value = value };
} }
private string GetNextPiece(IServiceProvider serviceProvider, ref string remaining, out char next) string GetNextPiece(IServiceProvider serviceProvider, ref string remaining, out char next)
{ {
bool inString = false; bool inString = false;
int end = 0; int end = 0;
@ -182,6 +181,8 @@ namespace Xamarin.Forms.Xaml
{ {
inString = false; inString = false;
end ++; end ++;
while (remaining[end] == ' ')
end++;
break; break;
} }
} }