Skip to content

Commit b9aef4c

Browse files
committed
Fixed appending eof character #123
1 parent 3b89d01 commit b9aef4c

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Released on tbd.
44

55
- Updated to use AngleSharp 1.0
66
- Fixed issue when updating shorthands with invalid values (#129)
7+
- Fixed issue with appended EOF character in `CssText` (#123)
78

89
# 0.17.0
910

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

+34
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,40 @@ public void EscapePropertyNames_UnknownDeclaration_Issue120()
106106
Assert.AreEqual(css, generatedCss);
107107
}
108108

109+
[Test]
110+
public void CssTextShouldNotAddReplacementCharacter_Issue123()
111+
{
112+
var html = @"<span style=""background-image: var(--urlSpellingErrorV2,url(&quot;https://www.example.com/))"">Ipsum</span>";
113+
var dom = html.ToHtmlDocument(Configuration.Default.WithCss(new CssParserOptions
114+
{
115+
IsIncludingUnknownDeclarations = true,
116+
IsIncludingUnknownRules = true,
117+
IsToleratingInvalidSelectors = true,
118+
}));
119+
var div = dom.Body?.FirstElementChild;
120+
var style = div.GetStyle();
121+
var css = style.ToCss();
122+
123+
Assert.AreEqual("background-image: var(--urlSpellingErrorV2,url(\"https://www.example.com/))", css);
124+
}
125+
126+
[Test]
127+
public void CssTextShouldNotTrailingSemicolonCharacter_Issue123()
128+
{
129+
var html = @"<span style=""color: red;"">Ipsum</span>";
130+
var dom = html.ToHtmlDocument(Configuration.Default.WithCss(new CssParserOptions
131+
{
132+
IsIncludingUnknownDeclarations = true,
133+
IsIncludingUnknownRules = true,
134+
IsToleratingInvalidSelectors = true,
135+
}));
136+
var div = dom.Body?.FirstElementChild;
137+
var style = div.GetStyle();
138+
var css = style.ToCss();
139+
140+
Assert.AreEqual("color: rgba(255, 0, 0, 1)", css);
141+
}
142+
109143
[Test]
110144
public void BorderWithEmptyPx_Issue129()
111145
{

src/AngleSharp.Css/Parser/CssTokenizer.cs

+5
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ public String ContentFrom(Int32 position)
7070
{
7171
var token = Data(current);
7272

73+
if (Current is Symbols.EndOfFile)
74+
{
75+
Back();
76+
}
77+
7378
if (token.Type == CssTokenType.Whitespace)
7479
{
7580
spaced++;

0 commit comments

Comments
 (0)