Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ public IPropertyValue Convert(IEnumerable<Token> value)
{
var enumerator = value.GetEnumerator();

while (enumerator.MoveNext() && enumerator.Current.Type == TokenType.Whitespace)
bool hasToken;

while ((hasToken = enumerator.MoveNext()) && enumerator.Current.Type == TokenType.Whitespace)
{
//Empty on purpose.
}

if (enumerator.Current.Type != TokenType.Ident || !_prefixKeywords.Contains(enumerator.Current.Data))
if (!hasToken || enumerator.Current.Type != TokenType.Ident || !_prefixKeywords.Contains(enumerator.Current.Data))
return null;

var consumedPrefix = enumerator.Current.Data;
Expand All @@ -42,7 +44,7 @@ public IPropertyValue Convert(IEnumerable<Token> value)

var result = _converter.Convert(remainingTokens);

if (result != null && result.CssText != _when)
if (result == null || result.CssText != _when)
return null;

return new ConditionalStartValue(consumedPrefix, result, value);
Expand Down
25 changes: 25 additions & 0 deletions Source/Test/HtmlRenderer.Test/Css/FlexboxTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Linq;
using HtmlRenderer.Test.CssEngineSupport;
using HtmlRenderer.Test.TestSupport;
using TheArtOfDev.HtmlRenderer.Core.CssEngine;

namespace HtmlRenderer.Test.Css;
Expand Down Expand Up @@ -99,6 +100,30 @@ public void JustifyContentIllegalPrefixValues(string value)
Assert.IsFalse(property.HasValue);
}

[TestMethod]
[DataRow("align-items: safe")]
[DataRow("align-self: unsafe")]
[DataRow("align-content: first")]
[DataRow("align-items: last")]
[DataRow("justify-content: first baseline")]
public void AlignmentPrefixWithoutKeywordIsRejected(string declaration)
{
var property = CssConstructionFunctions.ParseDeclaration(declaration);
Assert.IsFalse(property.HasValue);
}

[TestMethod]
[DataRow("align-items: safe")]
[DataRow("justify-self: safe right")]
[DataRow("place-self: center left")]
[DataRow("place-content: baseline")]
[DataRow("place-items: start legacy")]
public void AlignmentValueDoesntBreakTheDocument(string declaration)
{
var (root, _) = LayoutHarness.Layout(LayoutHarness.Wrap($"<div id='x' style='{declaration}'>text</div>"));
Assert.IsNotNull(LayoutHarness.FindById(root, "x"));
}

[TestMethod]
[DynamicData(nameof(FlexFlowExpandedTestValues))]
public void FlexFlowShorthandValueExpanded(string propertyValue, string expectedDirection, string expectedWrap)
Expand Down
Loading