Skip to content

Commit 3b89d01

Browse files
committed
Fixed serialization due to broken longhands #129
1 parent c8321b8 commit 3b89d01

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# 1.0.0
2+
3+
Released on tbd.
4+
5+
- Updated to use AngleSharp 1.0
6+
- Fixed issue when updating shorthands with invalid values (#129)
7+
18
# 0.17.0
29

310
Released on Sunday, January 15 2023.

src/AngleSharp.Css.Tests/Library/StringRepresentation.cs

+12
Original file line numberDiff line numberDiff line change
@@ -105,5 +105,17 @@ public void EscapePropertyNames_UnknownDeclaration_Issue120()
105105

106106
Assert.AreEqual(css, generatedCss);
107107
}
108+
109+
[Test]
110+
public void BorderWithEmptyPx_Issue129()
111+
{
112+
var html = "<div style=\"border-width:1px;border-right-width:px;\"></div>";
113+
var dom = html.ToHtmlDocument(Configuration.Default.WithCss());
114+
var div = dom.Body?.FirstElementChild;
115+
var style = div.GetStyle();
116+
var css = style.ToCss();
117+
118+
Assert.AreEqual("border-width: 1px", css);
119+
}
108120
}
109121
}

src/AngleSharp.Css/Dom/Internal/CssStyleDeclaration.cs

+13-3
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ private ICssProperty TryCreateShorthand(String shorthandName, IEnumerable<String
134134
TryCreateShorthand(name, serialized, usedProperties, force) :
135135
longhands.Where(m => m.Name == name).FirstOrDefault();
136136

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

321-
private ICssProperty CreateProperty(String propertyName) =>
322-
GetProperty(propertyName) ?? _context.CreateProperty(propertyName);
321+
private ICssProperty CreateProperty(String propertyName)
322+
{
323+
var newProperty = _context.CreateProperty(propertyName);
324+
var existing = GetProperty(propertyName);
325+
326+
if (existing is not null)
327+
{
328+
newProperty.RawValue = existing.RawValue;
329+
}
330+
331+
return newProperty;
332+
}
323333

324334
private void SetProperty(ICssProperty property)
325335
{

0 commit comments

Comments
 (0)