Skip to content

Commit 493f71d

Browse files
authored
Merge pull request #84 from AngleSharp/devel
Release 0.16.2
2 parents 63c7785 + e549e0b commit 493f71d

File tree

19 files changed

+255
-39
lines changed

19 files changed

+255
-39
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
# 0.16.2
2+
3+
Released on Thursday, November 4 2021.
4+
5+
- Fixed issue with unbalanced grid areas and rows (#82)
6+
- Fixed small numbers to be transformed into negative exponentials (#80)
7+
- Fixed issue handling exponential unit values (#79)
8+
- Fixed `InvalidCastException` in template merging with CSS variables (#83)
9+
110
# 0.16.1
211

312
Released on Wednesday, August 11 2021.

src/AngleSharp.Css.Tests/AngleSharp.Css.Tests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFrameworks>netcoreapp2.1</TargetFrameworks>
3+
<TargetFrameworks>net5.0</TargetFrameworks>
44
<SignAssembly>true</SignAssembly>
55
<AssemblyOriginatorKeyFile>Key.snk</AssemblyOriginatorKeyFile>
66
<IsPackable>false</IsPackable>
7-
<LangVersion>9.0</LangVersion>
7+
<LangVersion>9</LangVersion>
88
<AssemblyName>AngleSharp.Css.Tests</AssemblyName>
99
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> <!-- https://github.com/Tyrrrz/GitHubActionsTestLogger/issues/5 -->
1010
</PropertyGroup>

src/AngleSharp.Css.Tests/Declarations/CssMarginProperty.cs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,54 @@ public void CssMarginLeftLengthLegal()
1818
Assert.AreEqual("15px", property.Value);
1919
}
2020

21+
[Test]
22+
public void CssMarginLeftTinyValue_Issue80()
23+
{
24+
var snippet = "margin-left: 0.00001px";
25+
var property = ParseDeclaration(snippet);
26+
Assert.AreEqual("margin-left", property.Name);
27+
Assert.IsFalse(property.IsImportant);
28+
Assert.IsFalse(property.IsInherited);
29+
Assert.IsTrue(property.HasValue);
30+
Assert.AreEqual("0.00001px", property.Value);
31+
}
32+
33+
[Test]
34+
public void CssMarginLeftExponentialValue_Issue79()
35+
{
36+
var snippet = "margin-left: 1E5px";
37+
var property = ParseDeclaration(snippet);
38+
Assert.AreEqual("margin-left", property.Name);
39+
Assert.IsFalse(property.IsImportant);
40+
Assert.IsFalse(property.IsInherited);
41+
Assert.IsTrue(property.HasValue);
42+
Assert.AreEqual("100000px", property.Value);
43+
}
44+
45+
[Test]
46+
public void CssMarginLeftExponentialValueWithPlus_Issue79()
47+
{
48+
var snippet = "margin-left: 1E+5px";
49+
var property = ParseDeclaration(snippet);
50+
Assert.AreEqual("margin-left", property.Name);
51+
Assert.IsFalse(property.IsImportant);
52+
Assert.IsFalse(property.IsInherited);
53+
Assert.IsTrue(property.HasValue);
54+
Assert.AreEqual("100000px", property.Value);
55+
}
56+
57+
[Test]
58+
public void CssMarginLeftExponentialValueWithMinus_Issue79()
59+
{
60+
var snippet = "margin-left: 1E-2px";
61+
var property = ParseDeclaration(snippet);
62+
Assert.AreEqual("margin-left", property.Name);
63+
Assert.IsFalse(property.IsImportant);
64+
Assert.IsFalse(property.IsInherited);
65+
Assert.IsTrue(property.HasValue);
66+
Assert.AreEqual("0.01px", property.Value);
67+
}
68+
2169
[Test]
2270
public void CssMarginLeftInitialLegal()
2371
{

src/AngleSharp.Css.Tests/Parsing/StyleSheet.cs

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,140 @@ public async Task ParseEmptySheet_Issue42()
1515
var sheet = await parser.ParseStyleSheetAsync(sheetCode);
1616
Assert.IsNotNull(sheet);
1717
}
18+
19+
[Test]
20+
public async Task ParseStyleSheetAndBack_Issue82()
21+
{
22+
var css = @"
23+
.root {
24+
position: absolute;
25+
top: 0;
26+
left: 0;
27+
width: calc(100% - 10px);
28+
height: calc(100% - 10px);
29+
padding: 5px;
30+
}
31+
32+
.container {
33+
width: 100%;
34+
height: 100%;
35+
display: grid;
36+
grid-template-columns: 1fr 1fr;
37+
grid-template-rows: 240px calc(100% - 360px) 100px;
38+
grid-template-areas: 'header info' 'quantity info' 'footerOk footerCancel';
39+
row-gap: 10px;
40+
font-size: 26px;
41+
}
42+
43+
.destination {
44+
grid-area: header;
45+
width: calc(100% - 20px);
46+
height: calc(100% - 20px);
47+
margin: 10px;
48+
display: grid;
49+
grid-template-columns: auto auto auto;
50+
grid-template-rows: 150px 50px;
51+
grid-template-areas:
52+
""sourcerp image destrp""
53+
""sourcele image destle"";
54+
}
55+
56+
.quantitygrid {
57+
width: 100%;
58+
height: 100%;
59+
display: grid;
60+
grid-template-columns: auto auto auto;
61+
grid-template-rows: 150px 100px;
62+
grid-template-areas: 'minus number plus';
63+
}
64+
65+
.headergrid {
66+
width: 100%;
67+
height: 100%;
68+
display: grid;
69+
grid-template-columns: 1fr 1fr 1fr;
70+
grid-template-rows: 1fr 1fr;
71+
grid-template-areas: 'sourceplace space destinationplace' 'sourcelc space destinationlc';
72+
}
73+
74+
#info td + td {
75+
font-size: 24px;
76+
}
77+
78+
input {
79+
animation-duration: 2s;
80+
font-family: inherit;
81+
background-color: white;
82+
}
83+
84+
td {
85+
padding: 5px;
86+
}
87+
88+
paper-button {
89+
padding: 0;
90+
background-color: var(--kx-dark);
91+
box-sizing: border-box;
92+
display: flex;
93+
align-items: center;
94+
justify-content: center;
95+
color: white;
96+
/*font-weight: bolder;*/
97+
}
98+
99+
@keyframes errorAnimation {
100+
0% {
101+
background-color: white;
102+
}
103+
104+
1% {
105+
background-color: red;
106+
}
107+
108+
100% {
109+
background-color: white;
110+
}
111+
}
112+
113+
input:invalid {
114+
color: red;
115+
}
116+
";
117+
var parser = new CssParser();
118+
var formatter = new MinifyStyleFormatter();
119+
var ss = await parser.ParseStyleSheetAsync(css);
120+
var newCss = ss.ToCss(formatter);
121+
Assert.IsNotNull(newCss);
122+
}
123+
124+
[Test]
125+
public async Task CastingException_Issue83()
126+
{
127+
var css = @"
128+
.kardex-wrapper {
129+
height: 100vh;
130+
width: 100vw;
131+
display: grid;
132+
grid-template-rows: var(--header-height) 10px 1fr;
133+
grid-template-columns: var(--nav-width) 1fr;
134+
grid-template-areas: ""navheader header"" ""navheader content"" ""nav content"";
135+
}
136+
137+
header {
138+
grid-area: header;
139+
font-family: KardexMOT-Light, sans-serif;
140+
background-color: var(--kx-bg);
141+
color: var(--kx-text-light);
142+
display: grid;
143+
grid-template-rows: var(--header-height);
144+
grid-template-columns: 1fr 1fr 1fr;
145+
}
146+
";
147+
var parser = new CssParser();
148+
var formatter = new MinifyStyleFormatter();
149+
var ss = await parser.ParseStyleSheetAsync(css);
150+
var newCss = ss.ToCss(formatter);
151+
Assert.IsNotNull(newCss);
152+
}
18153
}
19154
}

src/AngleSharp.Css/Declarations/GridTemplateDeclaration.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ public ICssValue Merge(ICssValue[] values)
5252
}
5353
else if (cols != null || rows != null || areas != null)
5454
{
55-
return new CssGridTemplateValue(rows, cols, areas);
55+
if (cols is not CssReferenceValue && rows is not CssReferenceValue && areas is not CssReferenceValue)
56+
{
57+
return new CssGridTemplateValue(rows, cols, areas);
58+
}
5659
}
5760

5861
return null;

src/AngleSharp.Css/FormatValue.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace AngleSharp.Css
2+
{
3+
using System;
4+
using System.Globalization;
5+
6+
static class FormatValue
7+
{
8+
public const String DoubleFixedPoint = "0.###################################################################################################################################################################################################################################################################################################################################################";
9+
10+
public static String CssStringify(this Double value) => value.ToString(DoubleFixedPoint, CultureInfo.InvariantCulture);
11+
}
12+
}

src/AngleSharp.Css/Parser/CssTokenizer.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
namespace AngleSharp.Css.Parser
22
{
33
using AngleSharp.Common;
4-
using AngleSharp.Dom;
54
using AngleSharp.Css.Dom.Events;
65
using AngleSharp.Css.Parser.Tokens;
6+
using AngleSharp.Dom;
77
using AngleSharp.Text;
88
using System;
99
using System.Globalization;
@@ -807,7 +807,7 @@ private CssToken NumberRest()
807807
{
808808
StringBuffer.Append(current);
809809
}
810-
else if (current.IsNameStart())
810+
else if (current != 'e' && current != 'E' && current.IsNameStart())
811811
{
812812
StringBuffer.Append(current);
813813
return Dimension();
@@ -871,7 +871,7 @@ private CssToken NumberFraction()
871871
{
872872
StringBuffer.Append(current);
873873
}
874-
else if (current.IsNameStart())
874+
else if (current != 'e' && current != 'E' && current.IsNameStart())
875875
{
876876
StringBuffer.Append(current);
877877
return Dimension();
@@ -949,6 +949,11 @@ private CssToken SciNotation()
949949
{
950950
StringBuffer.Append(current);
951951
}
952+
else if (current.IsNameStart() || IsValidEscape(current))
953+
{
954+
StringBuffer.Append(current);
955+
return Dimension();
956+
}
952957
else
953958
{
954959
Back();

src/AngleSharp.Css/Parser/Micro/UnitParser.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,9 @@ private static Unit UnitStart(StringSource source)
316316
return null;
317317
}
318318

319+
private static Boolean IsDimension(StringSource source, Char current) =>
320+
current != 'e' && current != 'E' && (current.IsNameStart() || source.IsValidEscape());
321+
319322
private static Unit UnitRest(StringSource source, StringBuilder buffer)
320323
{
321324
var current = source.Next();
@@ -326,7 +329,7 @@ private static Unit UnitRest(StringSource source, StringBuilder buffer)
326329
{
327330
buffer.Append(current);
328331
}
329-
else if (current.IsNameStart() || source.IsValidEscape())
332+
else if (IsDimension(source, current))
330333
{
331334
var number = buffer.ToString();
332335
return Dimension(source, number, buffer.Clear());
@@ -378,7 +381,7 @@ private static Unit UnitFraction(StringSource source, StringBuilder buffer)
378381
{
379382
buffer.Append(current);
380383
}
381-
else if (current.IsNameStart() || source.IsValidEscape())
384+
else if (IsDimension(source, current))
382385
{
383386
var number = buffer.ToString();
384387
return Dimension(source, number, buffer.Clear());
@@ -421,7 +424,7 @@ private static Unit Dimension(StringSource source, String number, StringBuilder
421424
}
422425
else if (source.IsValidEscape())
423426
{
424-
current = source.Next();
427+
source.Next();
425428
buffer.Append(source.ConsumeEscape());
426429
}
427430
else
@@ -443,6 +446,11 @@ private static Unit SciNotation(StringSource source, StringBuilder buffer)
443446
{
444447
buffer.Append(current);
445448
}
449+
else if (current.IsNameStart() || source.IsValidEscape())
450+
{
451+
var number = buffer.ToString();
452+
return Dimension(source, number, buffer.Clear());
453+
}
446454
else
447455
{
448456
return new Unit(buffer.ToPool(), String.Empty);

src/AngleSharp.Css/Values/Composites/CssGridTemplateValue.cs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,20 +67,23 @@ public String CssText
6767
}
6868
else if (_areas != null)
6969
{
70-
var areas = ((CssTupleValue)_areas).Items;
71-
var rowItems = ((CssTupleValue)_rows).Items;
70+
var areas = (_areas as CssTupleValue)?.Items;
71+
var rowItems = (_rows as CssTupleValue)?.Items;
7272
var newRows = new List<ICssValue>();
7373

74-
for (var i = 0; i < rowItems.Length; i++)
74+
if (rowItems != null && areas != null)
7575
{
76-
var area = areas[i];
77-
var item = rowItems[i] as CssTupleValue;
78-
79-
if (item != null && area != null)
76+
for (var i = 0; i < rowItems.Length; i++)
8077
{
81-
var newItems = new List<ICssValue>(item.Items);
82-
newItems.Insert(1, area);
83-
newRows.Add(new CssTupleValue(newItems.ToArray()));
78+
var area = areas.Length > i ? areas[i] : null;
79+
var item = rowItems[i] as CssTupleValue;
80+
81+
if (item != null && area != null)
82+
{
83+
var newItems = new List<ICssValue>(item.Items);
84+
newItems.Insert(1, area);
85+
newRows.Add(new CssTupleValue(newItems.ToArray()));
86+
}
8487
}
8588
}
8689

src/AngleSharp.Css/Values/Primitives/Angle.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
namespace AngleSharp.Css.Values
22
{
3-
using AngleSharp.Css.Dom;
43
using System;
5-
using System.Globalization;
64

75
/// <summary>
86
/// Represents an angle object.
@@ -66,7 +64,7 @@ public Angle(Double value, Unit unit)
6664
/// <summary>
6765
/// Gets the CSS text representation.
6866
/// </summary>
69-
public String CssText => String.Concat(_value.ToString(CultureInfo.InvariantCulture), UnitString);
67+
public String CssText => String.Concat(_value.CssStringify(), UnitString);
7068

7169
/// <summary>
7270
/// Gets the value of the angle.

src/AngleSharp.Css/Values/Primitives/Fraction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public Fraction(Double value, Unit unit)
3535
/// <summary>
3636
/// Gets the CSS text representation.
3737
/// </summary>
38-
public String CssText => String.Concat(_value.ToString(CultureInfo.InvariantCulture), UnitString);
38+
public String CssText => String.Concat(_value.CssStringify(), UnitString);
3939

4040
/// <summary>
4141
/// Gets the value of fraction.

0 commit comments

Comments
 (0)