Skip to content

Commit 363b951

Browse files
authored
Merge pull request #152 from lee-m/unknown-prop
Fix UnknownProperty being used for known properties
2 parents d7cb3c1 + cea80cc commit 363b951

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

src/ExCSS.Tests/Cases.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,5 +1013,14 @@ public void StyleSheetWithInitialCommentShouldWorkWithTriviaActive()
10131013
Assert.IsType<Comment>(comment);
10141014
Assert.Equal(" Comment at the start ", ((Comment)comment).Data);
10151015
}
1016+
1017+
[Fact]
1018+
public void StylesheetIncludeUnknownDeclarationsWithKnownPropertyShouldNotUseUnknownProperty()
1019+
{
1020+
var parser = new StylesheetParser(includeUnknownDeclarations: true);
1021+
var document = parser.Parse(@"body { border-width: 0; }");
1022+
1023+
Assert.IsNotType<UnknownProperty>(((StyleRule)document.Rules[0]).Style.Children.First());
1024+
}
10161025
}
10171026
}

src/ExCSS/Parser/StylesheetComposer.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -620,10 +620,13 @@ public Property CreateDeclarationWith(Func<string, Property> createProperty, ref
620620

621621
if (propertyName.Length > 0)
622622
{
623-
property = _parser.Options.IncludeUnknownDeclarations ||
624-
_parser.Options.AllowInvalidValues
625-
? new UnknownProperty(propertyName)
626-
: createProperty(propertyName);
623+
property = createProperty(propertyName);
624+
625+
if (property == null
626+
&& (_parser.Options.IncludeUnknownDeclarations || _parser.Options.AllowInvalidValues))
627+
{
628+
property = new UnknownProperty(propertyName);
629+
}
627630

628631
if (property == null)
629632
RaiseErrorOccurred(ParseError.UnknownDeclarationName, start);

0 commit comments

Comments
 (0)