Skip to content

Commit

Permalink
Fixed serialization due to broken longhands AngleSharp#129
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianRappl committed Jun 14, 2023
1 parent c8321b8 commit 3b89d01
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# 1.0.0

Released on tbd.

- Updated to use AngleSharp 1.0
- Fixed issue when updating shorthands with invalid values (#129)

# 0.17.0

Released on Sunday, January 15 2023.
Expand Down
12 changes: 12 additions & 0 deletions src/AngleSharp.Css.Tests/Library/StringRepresentation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,17 @@ public void EscapePropertyNames_UnknownDeclaration_Issue120()

Assert.AreEqual(css, generatedCss);
}

[Test]
public void BorderWithEmptyPx_Issue129()
{
var html = "<div style=\"border-width:1px;border-right-width:px;\"></div>";
var dom = html.ToHtmlDocument(Configuration.Default.WithCss());
var div = dom.Body?.FirstElementChild;
var style = div.GetStyle();
var css = style.ToCss();

Assert.AreEqual("border-width: 1px", css);
}
}
}
16 changes: 13 additions & 3 deletions src/AngleSharp.Css/Dom/Internal/CssStyleDeclaration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ private ICssProperty TryCreateShorthand(String shorthandName, IEnumerable<String
TryCreateShorthand(name, serialized, usedProperties, force) :
longhands.Where(m => m.Name == name).FirstOrDefault();

if (property != null)
if (property?.Value is not null)
{
usedProperties.Add(name);
count = count + 1;
Expand Down Expand Up @@ -318,8 +318,18 @@ internal void UpdateDeclarations(IEnumerable<ICssProperty> decls) =>
private ICssProperty GetPropertyShorthand(String name) =>
TryCreateShorthand(name, Enumerable.Empty<String>(), new List<String>(), true);

private ICssProperty CreateProperty(String propertyName) =>
GetProperty(propertyName) ?? _context.CreateProperty(propertyName);
private ICssProperty CreateProperty(String propertyName)
{
var newProperty = _context.CreateProperty(propertyName);
var existing = GetProperty(propertyName);

if (existing is not null)
{
newProperty.RawValue = existing.RawValue;
}

return newProperty;
}

private void SetProperty(ICssProperty property)
{
Expand Down

0 comments on commit 3b89d01

Please sign in to comment.