public void ParseInlineStyleWithToleratedInvalidValueShouldReturnThatValue() { var html = "<div style=\"background-image: url(javascript:alert(1))\"></div>"; var options = new CssParserOptions { IsIncludingUnknownDeclarations = true, IsIncludingUnknownRules = true, IsToleratingInvalidConstraints = true, IsToleratingInvalidValues = true }; var config = Configuration.Default.WithCss(e => e.Options = options); var parser = new HtmlParser(config); var dom = parser.Parse(html); var div = dom.QuerySelector<IHtmlElement>("div"); Assert.AreEqual(1, div.Style.Length); Assert.AreEqual("background-image", div.Style[0]); Assert.AreEqual("url(\"javascript:alert(1)\")", div.Style.BackgroundImage); }
public void ParseInlineStyleWithUnknownDeclarationShouldBeAbleToRemoveThatDeclaration() { var html = @"<DIV STYLE='background: url(""javascript:alert(foo)"")'>"; var options = new CssParserOptions { IsIncludingUnknownDeclarations = true, IsIncludingUnknownRules = true, IsToleratingInvalidConstraints = true, IsToleratingInvalidValues = true }; var config = Configuration.Default.WithCss(e => e.Options = options); var parser = new HtmlParser(config); var dom = parser.Parse(html); var div = dom.QuerySelector<IHtmlElement>("div"); Assert.AreEqual(1, div.Style.Length); Assert.AreEqual("background", div.Style[0]); div.Style.RemoveProperty("background"); Assert.AreEqual(0, div.Style.Length); }
public void CssParseMediaAndMsViewPortWithUnknownRules() { var options = new CssParserOptions() { IsIncludingUnknownDeclarations = true, IsIncludingUnknownRules = true, IsToleratingInvalidConstraints = true, IsToleratingInvalidValues = true }; var css = "@media screen and (max-width: 400px) { @-ms-viewport { width: 320px; } } .dsip { display: block; }"; var doc = ParseStyleSheet(css, options); var result = doc.CssText; Assert.AreEqual("@media screen and (max-width: 400px) { @-ms-viewport { width: 320px; } }\r\n.dsip { display: block; }", result); }
/// <summary> /// Creates a new parser with the custom options and configuration. /// </summary> /// <param name="options">The options to use.</param> /// <param name="configuration">The configuration to use.</param> public CssParser(CssParserOptions options, IConfiguration configuration) { _options = options; _config = configuration; }
/// <summary> /// Creates a new parser with the custom options. /// </summary> /// <param name="options">The options to use.</param> public CssParser(CssParserOptions options) : this(options, Configuration.Default) { }
/// <summary> /// Creates a new parser with the custom options and configuration. /// </summary> /// <param name="options">The options to use.</param> /// <param name="configuration">The configuration to use.</param> public CssParser(CssParserOptions options, IConfiguration configuration) { _options = options; _configuration = configuration ?? Configuration.Default; }
/// <summary> /// Creates a new style engine. /// </summary> public CssStyleEngine() { _options = new CssParserOptions(); }
public void StyleSheetWithInitialCommentShouldWorkWithTriviaActive() { var options = new CssParserOptions { IsStoringTrivia = true }; var parser = new CssParser(options); var document = parser.ParseStylesheet(@"/* Comment at the start */ body { font-size: 10pt; }"); var comment = document.Children.First(); Assert.IsInstanceOf<ICssComment>(comment); Assert.AreEqual(" Comment at the start ", ((ICssComment)comment).Data); }
public void CssParseMsViewPortWithUnknownRules() { var options = new CssParserOptions() { IsIncludingUnknownDeclarations = true, IsIncludingUnknownRules = true, IsToleratingInvalidConstraints = true, IsToleratingInvalidValues = true }; var css = "@-ms-viewport{width:device-width} .dsip { display: block; }"; var doc = ParseStyleSheet(css, options); var result = doc.ToCss(); Assert.AreEqual("@-ms-viewport{width:device-width}\r\n.dsip { display: block }", result); }
internal static CssProperty ParseDeclaration(String source, CssParserOptions options) { var parser = new CssParser(options); return parser.ParseDeclaration(source); }
internal static ICssStyleSheet ParseStyleSheet(String source, CssParserOptions options) { var parser = new CssParser(options); return parser.ParseStylesheet(source); }