Skip to content

Commit

Permalink
Fixed appending eof character AngleSharp#123
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianRappl committed Jun 14, 2023
1 parent 3b89d01 commit b9aef4c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Released on tbd.

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

# 0.17.0

Expand Down
34 changes: 34 additions & 0 deletions src/AngleSharp.Css.Tests/Library/StringRepresentation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,40 @@ public void EscapePropertyNames_UnknownDeclaration_Issue120()
Assert.AreEqual(css, generatedCss);
}

[Test]
public void CssTextShouldNotAddReplacementCharacter_Issue123()
{
var html = @"<span style=""background-image: var(--urlSpellingErrorV2,url(&quot;https://www.example.com/))"">Ipsum</span>";
var dom = html.ToHtmlDocument(Configuration.Default.WithCss(new CssParserOptions
{
IsIncludingUnknownDeclarations = true,
IsIncludingUnknownRules = true,
IsToleratingInvalidSelectors = true,
}));
var div = dom.Body?.FirstElementChild;
var style = div.GetStyle();
var css = style.ToCss();

Assert.AreEqual("background-image: var(--urlSpellingErrorV2,url(\"https://www.example.com/))", css);
}

[Test]
public void CssTextShouldNotTrailingSemicolonCharacter_Issue123()
{
var html = @"<span style=""color: red;"">Ipsum</span>";
var dom = html.ToHtmlDocument(Configuration.Default.WithCss(new CssParserOptions
{
IsIncludingUnknownDeclarations = true,
IsIncludingUnknownRules = true,
IsToleratingInvalidSelectors = true,
}));
var div = dom.Body?.FirstElementChild;
var style = div.GetStyle();
var css = style.ToCss();

Assert.AreEqual("color: rgba(255, 0, 0, 1)", css);
}

[Test]
public void BorderWithEmptyPx_Issue129()
{
Expand Down
5 changes: 5 additions & 0 deletions src/AngleSharp.Css/Parser/CssTokenizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ public String ContentFrom(Int32 position)
{
var token = Data(current);

if (Current is Symbols.EndOfFile)
{
Back();
}

if (token.Type == CssTokenType.Whitespace)
{
spaced++;
Expand Down

0 comments on commit b9aef4c

Please sign in to comment.