Skip to content

Commit 0891a2f

Browse files
committed
Fixed parsing of background none #65
1 parent 39544e9 commit 0891a2f

File tree

3 files changed

+89
-1
lines changed

3 files changed

+89
-1
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,30 @@ public void CssBackgroundRedLegal()
613613
Assert.AreEqual("rgba(255, 0, 0, 1)", property.Value);
614614
}
615615

616+
[Test]
617+
public void CssBackgroundNoneLegal()
618+
{
619+
var snippet = "background: none";
620+
var property = ParseDeclaration(snippet);
621+
Assert.AreEqual("background", property.Name);
622+
Assert.IsFalse(property.IsImportant);
623+
Assert.IsFalse(property.IsInherited);
624+
Assert.IsTrue(property.HasValue);
625+
Assert.AreEqual("none", property.Value);
626+
}
627+
628+
[Test]
629+
public void CssBackgroundNoneColoredLegal()
630+
{
631+
var snippet = "background: none rgb(1, 2, 3)";
632+
var property = ParseDeclaration(snippet);
633+
Assert.AreEqual("background", property.Name);
634+
Assert.IsFalse(property.IsImportant);
635+
Assert.IsFalse(property.IsInherited);
636+
Assert.IsTrue(property.HasValue);
637+
Assert.AreEqual("none rgba(1, 2, 3, 1)", property.Value);
638+
}
639+
616640
[Test]
617641
public void CssBackgroundWhiteImageLegal()
618642
{

src/AngleSharp.Css/Declarations/BackgroundDeclaration.cs

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,56 @@ sealed class BackgroundAggregator : IValueAggregator, IValueConverter
3434
{
3535
public ICssValue Convert(StringSource source)
3636
{
37+
// [ <bg-layer> , ]* <final-bg-layer>
38+
// where:
39+
// <bg-layer> = <bg-image> || <bg-position> [ / <bg-size> ]? || <repeat-style> || <attachment> || <box> || <box>
40+
// <final-bg-layer> = <'background-color'> || <bg-image> || <bg-position> [ / <bg-size> ]? || <repeat-style> || <attachment> || <box> || <box>
41+
// where:
42+
// <bg-image> = none | <image>
43+
// <bg-position> = [ [ left | center | right | top | bottom | <length-percentage> ] | [ left | center | right | <length-percentage> ] [ top | center | bottom | <length-percentage> ] | [ center | [ left | right ] <length-percentage>? ] && [ center | [ top | bottom ] <length-percentage>? ] ]
44+
// <bg-size> = [ <length-percentage> | auto ]{1,2} | cover | contain
45+
// <repeat-style> = repeat-x | repeat-y | [ repeat | space | round | no-repeat ]{1,2}
46+
// <attachment> = scroll | fixed | local
47+
// <box> = border-box | padding-box | content-box
48+
// <image> = <url> | <image()> | <image-set()> | <element()> | <paint()> | <cross-fade()> | <gradient>
49+
// <length-percentage> = <length> | <percentage>
50+
// <image()> = image( <image-tags>? [ <image-src>? , <color>? ]! )
51+
// <image-set()> = image-set( <image-set-option># )
52+
// <element()> = element( <id-selector> )
53+
// <paint()> = paint( <ident>, <declaration-value>? )
54+
// <cross-fade()> = cross-fade( <cf-mixing-image> , <cf-final-image>? )
55+
// <gradient> = <linear-gradient()> | <repeating-linear-gradient()> | <radial-gradient()> | <repeating-radial-gradient()> | <conic-gradient()>
56+
// <image-tags> = ltr | rtl
57+
// <image-src> = <url> | <string>
58+
// <color> = <rgb()> | <rgba()> | <hsl()> | <hsla()> | <hex-color> | <named-color> | currentcolor | <deprecated-system-color>
59+
// <image-set-option> = [ <image> | <string> ] <resolution>
60+
// <id-selector> = <hash-token>
61+
// <cf-mixing-image> = <percentage>? && <image>
62+
// <cf-final-image> = <image> | <color>
63+
// <linear-gradient()> = linear-gradient( [ <angle> | to <side-or-corner> ]? , <color-stop-list> )
64+
// <repeating-linear-gradient()> = repeating-linear-gradient( [ <angle> | to <side-or-corner> ]? , <color-stop-list> )
65+
// <radial-gradient()> = radial-gradient( [ <ending-shape> || <size> ]? [ at <position> ]? , <color-stop-list> )
66+
// <repeating-radial-gradient()> = repeating-radial-gradient( [ <ending-shape> || <size> ]? [ at <position> ]? , <color-stop-list> )
67+
// <conic-gradient()> = conic-gradient( [ from <angle> ]? [ at <position> ]?, <angular-color-stop-list> )
68+
// <rgb()> = rgb( <percentage>{3} [ / <alpha-value> ]? ) | rgb( <number>{3} [ / <alpha-value> ]? ) | rgb( <percentage>#{3} , <alpha-value>? ) | rgb( <number>#{3} , <alpha-value>? )
69+
// <rgba()> = rgba( <percentage>{3} [ / <alpha-value> ]? ) | rgba( <number>{3} [ / <alpha-value> ]? ) | rgba( <percentage>#{3} , <alpha-value>? ) | rgba( <number>#{3} , <alpha-value>? )
70+
// <hsl()> = hsl( <hue> <percentage> <percentage> [ / <alpha-value> ]? ) | hsl( <hue>, <percentage>, <percentage>, <alpha-value>? )
71+
// <hsla()> = hsla( <hue> <percentage> <percentage> [ / <alpha-value> ]? ) | hsla( <hue>, <percentage>, <percentage>, <alpha-value>? )
72+
// <side-or-corner> = [ left | right ] || [ top | bottom ]
73+
// <color-stop-list> = [ <linear-color-stop> [, <linear-color-hint>]? ]# , <linear-color-stop>
74+
// <ending-shape> = circle | ellipse
75+
// <size> = closest-side | farthest-side | closest-corner | farthest-corner | <length> | <length-percentage>{2}
76+
// <position> = [ [ left | center | right ] || [ top | center | bottom ] | [ left | center | right | <length-percentage> ] [ top | center | bottom | <length-percentage> ]? | [ [ left | right ] <length-percentage> ] && [ [ top | bottom ] <length-percentage> ] ]
77+
// <angular-color-stop-list> = [ <angular-color-stop> [, <angular-color-hint>]? ]# , <angular-color-stop>
78+
// <alpha-value> = <number> | <percentage>
79+
// <hue> = <number> | <angle>
80+
// <linear-color-stop> = <color> <color-stop-length>?
81+
// <linear-color-hint> = <length-percentage>
82+
// <angular-color-stop> = <color> && <color-stop-angle>?
83+
// <angular-color-hint> = <angle-percentage>
84+
// <color-stop-length> = <length-percentage>{1,2}
85+
// <color-stop-angle> = <angle-percentage>{1,2}
86+
// <angle-percentage> = <angle> | <percentage>
3787
var layers = new List<CssBackgroundLayerValue>();
3888
var color = default(ICssValue);
3989
var pos = 0;
@@ -65,7 +115,7 @@ public ICssValue Convert(StringSource source)
65115

66116
if (image == null)
67117
{
68-
image = source.ParseImageSource();
118+
image = source.ParseImageSource() ?? (source.IsIdentifier(CssKeywords.None) ? new CssNoneValue() : null);
69119
c = source.SkipSpacesAndComments();
70120
}
71121

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace AngleSharp.Css.Values
2+
{
3+
using AngleSharp.Css.Dom;
4+
using System;
5+
6+
sealed class CssNoneValue : ICssImageValue
7+
{
8+
public String Name => CssKeywords.None;
9+
10+
public ICssValue[] Arguments => Array.Empty<ICssValue>();
11+
12+
public String CssText => CssKeywords.None;
13+
}
14+
}

0 commit comments

Comments
 (0)