コード例 #1
0
ファイル: Error.cs プロジェクト: JBTech/AngleSharp
 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);
 }
コード例 #2
0
ファイル: Error.cs プロジェクト: Wojdav/AngleSharp
 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);
 }
コード例 #3
0
ファイル: CssSheet.cs プロジェクト: howej/AngleSharp
 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);
 }
コード例 #4
0
ファイル: CssParser.cs プロジェクト: mganss/AngleSharp
 /// <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;
 }
コード例 #5
0
ファイル: CssParser.cs プロジェクト: mganss/AngleSharp
 /// <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)
 {
 }
コード例 #6
0
 /// <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;
 }
コード例 #7
0
 /// <summary>
 /// Creates a new style engine.
 /// </summary>
 public CssStyleEngine()
 {
     _options = new CssParserOptions();
 }
コード例 #8
0
ファイル: CssCases.cs プロジェクト: Wojdav/AngleSharp
        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);
        }
コード例 #9
0
ファイル: CssSheet.cs プロジェクト: fjwuyongzhi/AngleSharp
 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);
 }
コード例 #10
0
 /// <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;
 }
コード例 #11
0
 /// <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)
 {
 }
コード例 #12
0
 internal static CssProperty ParseDeclaration(String source, CssParserOptions options)
 {
     var parser = new CssParser(options);
     return parser.ParseDeclaration(source);
 }
コード例 #13
0
 internal static ICssStyleSheet ParseStyleSheet(String source, CssParserOptions options)
 {
     var parser = new CssParser(options);
     return parser.ParseStylesheet(source);
 }