Giter Club home page Giter Club logo

htmlunit-cssparser's Introduction

HtmlUnit

Version 4.2.0 / June 05, 2024

❤️ Sponsor

Maven Central OpenSSF Scorecard

Homepage

htmlunit.org

HtmlUnit@mastodon | HtmlUnit@Twitter

HtmlUnit Kanban Board

Check out HtmlUnit satellite projects, such as:

Note as well that you can use HtmlUnit with Selenium via their htmlunit-driver!

Sponsoring

Constantly updating and maintaining the HtmlUnit code base already takes a lot of time.

I would like to make 2 major extensions in the next few months

For doing this I need your sponsoring.

Get it!

Maven

Add to your pom.xml:

<dependency>
    <groupId>org.htmlunit</groupId>
    <artifactId>htmlunit</artifactId>
    <version>4.2.0</version>
</dependency>

Gradle

Add to your build.gradle:

implementation group: 'org.htmlunit', name: 'htmlunit', version: '4.2.0'

Vulnerabilities

List of Vulnerabilities

Security Policy

Overview

HtmlUnit is a "GUI-less browser for Java programs". It models HTML documents and provides an API that allows you to invoke pages, fill out forms, click links, etc... just like you do in your "normal" browser.

It has fairly good JavaScript support (which is constantly improving) and is able to work even with quite complex AJAX libraries, simulating Chrome, Firefox or Internet Explorer depending on the configuration used.

HtmlUnit is typically used for testing purposes or to retrieve information from web sites.

Features

  • Support for the HTTP and HTTPS protocols
  • Support for cookies
  • Ability to specify whether failing responses from the server should throw exceptions or should be returned as pages of the appropriate type (based on content type)
  • Support for submit methods POST and GET (as well as HEAD, DELETE, ...)
  • Ability to customize the request headers being sent to the server
  • Support for HTML responses
    • Wrapper for HTML pages that provides easy access to all information contained inside them
    • Support for submitting forms
    • Support for clicking links
    • Support for walking the DOM model of the HTML document
  • Proxy server support
  • Support for basic and NTLM authentication
  • Excellent JavaScript support

Getting Started

You can start here:

Contributing

Pull Requests and all other Community Contributions are essential for open source software. Every contribution - from bug reports to feature requests, typos to full new features - are greatly appreciated.

Last CI build

The latest builds are available from our Jenkins CI build server

Build Status

Read on if you want to try the latest bleeding-edge snapshot.

Maven

Add the snapshot repository and dependency to your pom.xml:

    <!-- ... -->
    <repository>
      <id>OSS Sonatype snapshots</id>
      <url>https://s01.oss.sonatype.org/content/repositories/snapshots/</url>
      <snapshots>
        <enabled>true</enabled>
        <updatePolicy>always</updatePolicy>
      </snapshots>
      <releases>
        <enabled>false</enabled>
      </releases>
    </repository>

    <!-- ... -->
    <dependencies>
      <dependency>
          <groupId>org.htmlunit</groupId>
          <artifactId>htmlunit</artifactId>
          <version>4.3.0-SNAPSHOT</version>
      </dependency>
      <!-- ... -->
    </dependencies>

    <!-- ... -->

Gradle

Add the snapshot repository and dependency to your build.gradle:

repositories {
  maven { url "https://s01.oss.sonatype.org/content/repositories/snapshots" }
  // ...
}
// ...
dependencies {
    implementation group: 'org.htmlunit', name: 'htmlunit', version: '4.2.0-SNAPSHOT'
  // ...
}

License

This project is licensed under the Apache 2.0 License

Development

useful mvn command lines

setup as or refresh the eclipse project

mvn eclipse:eclipse -DdownloadSources=true

run the whole core test suite (no huge tests, no libary tests)

mvn test -U -P without-library-and-huge-tests -Dgpg.skip -Djava.awt.headless=true

check dependencies for known security problems

mvn dependency-check:check

Contributing

I welcome contributions, especially in the form of pull requests. Please try to keep your pull requests small (don't bundle unrelated changes) and try to include test cases.

Some insights

HtmlUnit at openhub

Stargazers

Stargazers

htmlunit-cssparser's People

Contributors

asashour avatar axelnennker avatar daniel-beck avatar dependabot[bot] avatar oswetto avatar rbri avatar yashdreamsdevelopment avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

htmlunit-cssparser's Issues

calc function error

hi @rbri the calc function does not support css vh and vw units and i think there is a parsing error in the third example
(100vh - 43px); Error in expression. (Token "100vh" invalid)
calc (100vw - 43px); Error in expression. (Token "100vh" invalid)
calc (50vh-260px); Error in expression. (Token "50vh-260px" invalid)

CSS parsing fails for calc expressions that match the W3C specification

Reposting this from htmlunit, my bad I posted it in the wrong project. I realize that this is low priority, I'm not expecting it to be fixed anytime soon (and I don't have time to do it and issue a pull request, sorry). I just want to log the issue.

I Checked this in 2.41 and 2.42, I did not go back any farther. The parser does not accept correct calc expressions. Space after an operator is not accepted, although the spec says it has to be there. Parentheses are not expected but the spec defines them. I also tried a nested calc function in lieu of parentheses and that is rejected as well but defined in the spec. See section 11.1 for all of this.

I am not going to post the whole file. The CSS snippet has line numbers to match the warnings:

40: min-height: calc(100vh - 150px + 10px + 21px + 20pt);
366: left: calc((100vw - 600px) / 2);
367: top: calc((100vh - 100px) / 2);

2020-07-25 18:44:43.716 WARN 7545 --- [pool-3-thread-1] c.g.htmlunit.DefaultCssErrorHandler : CSS error: 'http://localhost:57928/tccc/style/application.css' [40:29] Error in expression. (Invalid token " ". Was expecting one of: , "inherit", , , , , , , <LENGTH_PX>, <LENGTH_CM>, <LENGTH_MM>, <LENGTH_IN>, <LENGTH_PT>, <LENGTH_PC>, <ANGLE_DEG>, <ANGLE_RAD>, <ANGLE_GRAD>, <TIME_MS>, <TIME_S>, <FREQ_HZ>, <FREQ_KHZ>, <RESOLUTION_DPI>, <RESOLUTION_DPCM>, , , <UNICODE_RANGE>, , , "progid:".)
2020-07-25 18:44:43.719 WARN 7545 --- [pool-3-thread-1] c.g.htmlunit.DefaultCssErrorHandler : CSS error: 'http://localhost:57928/tccc/style/application.css' [366:16] Error in expression. (Invalid token "(". Was expecting one of: , , "inherit", , , ")", "-", , , , , , <LENGTH_PX>, <LENGTH_CM>, <LENGTH_MM>, <LENGTH_IN>, <LENGTH_PT>, <LENGTH_PC>, <ANGLE_DEG>, <ANGLE_RAD>, <ANGLE_GRAD>, <TIME_MS>, <TIME_S>, <FREQ_HZ>, <FREQ_KHZ>, <RESOLUTION_DPI>, <RESOLUTION_DPCM>, , , <UNICODE_RANGE>, , , "progid:".)
2020-07-25 18:44:43.720 WARN 7545 --- [pool-3-thread-1] c.g.htmlunit.DefaultCssErrorHandler : CSS error: 'http://localhost:57928/tccc/style/application.css' [367:15] Error in expression. (Invalid token "(". Was expecting one of: , , "inherit", , , ")", "-", , , , , , <LENGTH_PX>, <LENGTH_CM>, <LENGTH_MM>, <LENGTH_IN>, <LENGTH_PT>, <LENGTH_PC>, <ANGLE_DEG>, <ANGLE_RAD>, <ANGLE_GRAD>, <TIME_MS>, <TIME_S>, <FREQ_HZ>, <FREQ_KHZ>, <RESOLUTION_DPI>, <RESOLUTION_DPCM>, , , <UNICODE_RANGE>, , , "progid:".)

Parse selectors error

Hi @rbri, Happy New Year :-)

I've error when parse selectors "div:not(div:nth-last-of-type(1))" or "p a:not(a:first-of-type)"

My Code

final CSSOMParser parser = new CSSOMParser(new CSS3Parser());
parser.setErrorHandler(ThrowCssExceptionErrorHandler.INSTANCE);
parser.parseSelectors(selectors);

Exception
"Error in pseudo class or element. (Invalid token ":". Was expecting one of: , ")".)"

Word inherit as css selector

Hi @rbri, if i use "inherit" as css selector i've error "Error in class selector. (Invalid token "inherit". Was expecting: .)"

.inherit { height:auto; background-color:orange; }

Color issue

Hi @rbri in the color the char "/" is not supported
color: hsl(120 75% 50% / 80%);
Error in expression. Invalid token "/"

Angle and Length: Missing values

Please consider adding support for the following angle and length unit types (for completion):

  • Angle: Turn - Represents an angle in a number of turns. MDN: angle
  • Length: Q - One quarter of a millimeter. MDN: length

Q (an absolute length units) is currently marked as experimental, but supported by all current browsers.

Lookahead(2) causes really poor parser performance

Even with the recently improved :not handling the performance of the CSS parser is still really poor. Over 50% of the CPU of our HtmlUnit tests is spent parsing CSS, and if I interpret the profiler data correctly the cause is the LOOKAHEAD(2) in CSS3Parser.jj:1111

JavaCC seems to implement LOOKAHEAD(2) by just running a side-effect free version of the parser, and as soon as 2 tokens have been correctly parsed, it throws a pre-constructed LookaheadSuccess throwable, restores the parser state and starts parsing for real. Throwing exceptions is expensive and the method that throws this exception is really high in the "self-time" of the profiler (actually the method itself is nowhere to be found, but various other methods that call this method are; I presume the compiler inlines the jj_scan_token(int) method that does it).

My guess is that the LOOKAHEAD(2) is there to differentiate between div span (descendant selector) and div {. Since the presence of whitespace after the selector (div) does not tell you whether you are done parsing selectors yet. My experience with parsers is that in general you want to skip all whitespace from the token stream. This way instead of having to differentiate between <IDENT> <S> <IDENT> vs <IDENT> <S> <LBRACE> you differentiate between <IDENT> <IDENT> vs <IDENT> <LBRACE>, making the parser LL(1), which should improve the performance a lot.

Is there any reason to keep the whitespace in the token stream? Is there an annoying CSS feature that requires this?

If I have time I might look into creating a pull request, but my experience with JavaCC is mostly theoretical.

Question: LexicalUnitType.SUB_EXPRESSION

This type LexicalUnitType.SUB_EXPRESSION is never created by the parser.
It is type about IE's expression() function (example: top:expression(body.scrollTop + 50 + "px"))?

Can't parsing @keyframes, @-webkit-keyframes

/* before parsed*/

@-webkit-keyframes load5 {
    0%,
    100% {
        box-shadow: 0em -2.6em 0em 0em #000000, 1.8em -1.8em 0 0em rgba(0, 0, 0, 0.2), 2.5em 0em 0 0em rgba(0, 0, 0, 0.2), 1.75em 1.75em 0 0em rgba(0, 0, 0, 0.2), 0em 2.5em 0 0em rgba(0, 0, 0, 0.2), -1.8em 1.8em 0 0em rgba(0, 0, 0, 0.2), -2.6em 0em 0 0em rgba(0, 0, 0, 0.5), -1.8em -1.8em 0 0em rgba(0, 0, 0, 0.7);
    }
    12.5% {
        box-shadow: 0em -2.6em 0em 0em rgba(0, 0, 0, 0.7), 1.8em -1.8em 0 0em #000000, 2.5em 0em 0 0em rgba(0, 0, 0, 0.2), 1.75em 1.75em 0 0em rgba(0, 0, 0, 0.2), 0em 2.5em 0 0em rgba(0, 0, 0, 0.2), -1.8em 1.8em 0 0em rgba(0, 0, 0, 0.2), -2.6em 0em 0 0em rgba(0, 0, 0, 0.2), -1.8em -1.8em 0 0em rgba(0, 0, 0, 0.5);
    }
    25% {
        box-shadow: 0em -2.6em 0em 0em rgba(0, 0, 0, 0.5), 1.8em -1.8em 0 0em rgba(0, 0, 0, 0.7), 2.5em 0em 0 0em #000000, 1.75em 1.75em 0 0em rgba(0, 0, 0, 0.2), 0em 2.5em 0 0em rgba(0, 0, 0, 0.2), -1.8em 1.8em 0 0em rgba(0, 0, 0, 0.2), -2.6em 0em 0 0em rgba(0, 0, 0, 0.2), -1.8em -1.8em 0 0em rgba(0, 0, 0, 0.2);
    }
    37.5% {
        box-shadow: 0em -2.6em 0em 0em rgba(0, 0, 0, 0.2), 1.8em -1.8em 0 0em rgba(0, 0, 0, 0.5), 2.5em 0em 0 0em rgba(0, 0, 0, 0.7), 1.75em 1.75em 0 0em #000000, 0em 2.5em 0 0em rgba(0, 0, 0, 0.2), -1.8em 1.8em 0 0em rgba(0, 0, 0, 0.2), -2.6em 0em 0 0em rgba(0, 0, 0, 0.2), -1.8em -1.8em 0 0em rgba(0, 0, 0, 0.2);
    }
    50% {
        box-shadow: 0em -2.6em 0em 0em rgba(0, 0, 0, 0.2), 1.8em -1.8em 0 0em rgba(0, 0, 0, 0.2), 2.5em 0em 0 0em rgba(0, 0, 0, 0.5), 1.75em 1.75em 0 0em rgba(0, 0, 0, 0.7), 0em 2.5em 0 0em #000000, -1.8em 1.8em 0 0em rgba(0, 0, 0, 0.2), -2.6em 0em 0 0em rgba(0, 0, 0, 0.2), -1.8em -1.8em 0 0em rgba(0, 0, 0, 0.2);
    }
    62.5% {
        box-shadow: 0em -2.6em 0em 0em rgba(0, 0, 0, 0.2), 1.8em -1.8em 0 0em rgba(0, 0, 0, 0.2), 2.5em 0em 0 0em rgba(0, 0, 0, 0.2), 1.75em 1.75em 0 0em rgba(0, 0, 0, 0.5), 0em 2.5em 0 0em rgba(0, 0, 0, 0.7), -1.8em 1.8em 0 0em #000000, -2.6em 0em 0 0em rgba(0, 0, 0, 0.2), -1.8em -1.8em 0 0em rgba(0, 0, 0, 0.2);
    }
    75% {
        box-shadow: 0em -2.6em 0em 0em rgba(0, 0, 0, 0.2), 1.8em -1.8em 0 0em rgba(0, 0, 0, 0.2), 2.5em 0em 0 0em rgba(0, 0, 0, 0.2), 1.75em 1.75em 0 0em rgba(0, 0, 0, 0.2), 0em 2.5em 0 0em rgba(0, 0, 0, 0.5), -1.8em 1.8em 0 0em rgba(0, 0, 0, 0.7), -2.6em 0em 0 0em #000000, -1.8em -1.8em 0 0em rgba(0, 0, 0, 0.2);
    }
    87.5% {
        box-shadow: 0em -2.6em 0em 0em rgba(0, 0, 0, 0.2), 1.8em -1.8em 0 0em rgba(0, 0, 0, 0.2), 2.5em 0em 0 0em rgba(0, 0, 0, 0.2), 1.75em 1.75em 0 0em rgba(0, 0, 0, 0.2), 0em 2.5em 0 0em rgba(0, 0, 0, 0.2), -1.8em 1.8em 0 0em rgba(0, 0, 0, 0.5), -2.6em 0em 0 0em rgba(0, 0, 0, 0.7), -1.8em -1.8em 0 0em #000000;
    }
}

@keyframes load5 {
    0%,
    100% {
        box-shadow: 0em -2.6em 0em 0em #000000, 1.8em -1.8em 0 0em rgba(0, 0, 0, 0.2), 2.5em 0em 0 0em rgba(0, 0, 0, 0.2), 1.75em 1.75em 0 0em rgba(0, 0, 0, 0.2), 0em 2.5em 0 0em rgba(0, 0, 0, 0.2), -1.8em 1.8em 0 0em rgba(0, 0, 0, 0.2), -2.6em 0em 0 0em rgba(0, 0, 0, 0.5), -1.8em -1.8em 0 0em rgba(0, 0, 0, 0.7);
    }
    12.5% {
        box-shadow: 0em -2.6em 0em 0em rgba(0, 0, 0, 0.7), 1.8em -1.8em 0 0em #000000, 2.5em 0em 0 0em rgba(0, 0, 0, 0.2), 1.75em 1.75em 0 0em rgba(0, 0, 0, 0.2), 0em 2.5em 0 0em rgba(0, 0, 0, 0.2), -1.8em 1.8em 0 0em rgba(0, 0, 0, 0.2), -2.6em 0em 0 0em rgba(0, 0, 0, 0.2), -1.8em -1.8em 0 0em rgba(0, 0, 0, 0.5);
    }
    25% {
        box-shadow: 0em -2.6em 0em 0em rgba(0, 0, 0, 0.5), 1.8em -1.8em 0 0em rgba(0, 0, 0, 0.7), 2.5em 0em 0 0em #000000, 1.75em 1.75em 0 0em rgba(0, 0, 0, 0.2), 0em 2.5em 0 0em rgba(0, 0, 0, 0.2), -1.8em 1.8em 0 0em rgba(0, 0, 0, 0.2), -2.6em 0em 0 0em rgba(0, 0, 0, 0.2), -1.8em -1.8em 0 0em rgba(0, 0, 0, 0.2);
    }
    37.5% {
        box-shadow: 0em -2.6em 0em 0em rgba(0, 0, 0, 0.2), 1.8em -1.8em 0 0em rgba(0, 0, 0, 0.5), 2.5em 0em 0 0em rgba(0, 0, 0, 0.7), 1.75em 1.75em 0 0em #000000, 0em 2.5em 0 0em rgba(0, 0, 0, 0.2), -1.8em 1.8em 0 0em rgba(0, 0, 0, 0.2), -2.6em 0em 0 0em rgba(0, 0, 0, 0.2), -1.8em -1.8em 0 0em rgba(0, 0, 0, 0.2);
    }
    50% {
        box-shadow: 0em -2.6em 0em 0em rgba(0, 0, 0, 0.2), 1.8em -1.8em 0 0em rgba(0, 0, 0, 0.2), 2.5em 0em 0 0em rgba(0, 0, 0, 0.5), 1.75em 1.75em 0 0em rgba(0, 0, 0, 0.7), 0em 2.5em 0 0em #000000, -1.8em 1.8em 0 0em rgba(0, 0, 0, 0.2), -2.6em 0em 0 0em rgba(0, 0, 0, 0.2), -1.8em -1.8em 0 0em rgba(0, 0, 0, 0.2);
    }
    62.5% {
        box-shadow: 0em -2.6em 0em 0em rgba(0, 0, 0, 0.2), 1.8em -1.8em 0 0em rgba(0, 0, 0, 0.2), 2.5em 0em 0 0em rgba(0, 0, 0, 0.2), 1.75em 1.75em 0 0em rgba(0, 0, 0, 0.5), 0em 2.5em 0 0em rgba(0, 0, 0, 0.7), -1.8em 1.8em 0 0em #000000, -2.6em 0em 0 0em rgba(0, 0, 0, 0.2), -1.8em -1.8em 0 0em rgba(0, 0, 0, 0.2);
    }
    75% {
        box-shadow: 0em -2.6em 0em 0em rgba(0, 0, 0, 0.2), 1.8em -1.8em 0 0em rgba(0, 0, 0, 0.2), 2.5em 0em 0 0em rgba(0, 0, 0, 0.2), 1.75em 1.75em 0 0em rgba(0, 0, 0, 0.2), 0em 2.5em 0 0em rgba(0, 0, 0, 0.5), -1.8em 1.8em 0 0em rgba(0, 0, 0, 0.7), -2.6em 0em 0 0em #000000, -1.8em -1.8em 0 0em rgba(0, 0, 0, 0.2);
    }
    87.5% {
        box-shadow: 0em -2.6em 0em 0em rgba(0, 0, 0, 0.2), 1.8em -1.8em 0 0em rgba(0, 0, 0, 0.2), 2.5em 0em 0 0em rgba(0, 0, 0, 0.2), 1.75em 1.75em 0 0em rgba(0, 0, 0, 0.2), 0em 2.5em 0 0em rgba(0, 0, 0, 0.2), -1.8em 1.8em 0 0em rgba(0, 0, 0, 0.5), -2.6em 0em 0 0em rgba(0, 0, 0, 0.7), -1.8em -1.8em 0 0em #000000;
    }
}

Those two css blocks are parsed as CSSUnknownRuleImpl.

/* after parsed */
@-webkit-keyframes load5 {
    0%,
    100% {
        box-shadow: 0ems -2.6ems 0ems 0ems #000000, 1.8ems -1.8ems 0 0ems rgba(0, 0, 0, 0.2), 2.5ems 0ems 0 0ems rgba(0, 0, 0, 0.2), 1.75ems 1.75ems 0 0ems rgba(0, 0, 0, 0.2), 0ems 2.5ems 0 0ems rgba(0, 0, 0, 0.2), -1.8ems 1.8ems 0 0ems rgba(0, 0, 0, 0.2), -2.6ems 0ems 0 0ems rgba(0, 0, 0, 0.5), -1.8ems -1.8ems 0 0ems rgba(0, 0, 0, 0.7);
    }
    12.5% {
        box-shadow: 0ems -2.6ems 0ems 0ems rgba(0, 0, 0, 0.7), 1.8ems -1.8ems 0 0ems #000000, 2.5ems 0ems 0 0ems rgba(0, 0, 0, 0.2), 1.75ems 1.75ems 0 0ems rgba(0, 0, 0, 0.2), 0ems 2.5ems 0 0ems rgba(0, 0, 0, 0.2), -1.8ems 1.8ems 0 0ems rgba(0, 0, 0, 0.2), -2.6ems 0ems 0 0ems rgba(0, 0, 0, 0.2), -1.8ems -1.8ems 0 0ems rgba(0, 0, 0, 0.5);
    }
    25% {
        box-shadow: 0ems -2.6ems 0ems 0ems rgba(0, 0, 0, 0.5), 1.8ems -1.8ems 0 0ems rgba(0, 0, 0, 0.7), 2.5ems 0ems 0 0ems #000000, 1.75ems 1.75ems 0 0ems rgba(0, 0, 0, 0.2), 0ems 2.5ems 0 0ems rgba(0, 0, 0, 0.2), -1.8ems 1.8ems 0 0ems rgba(0, 0, 0, 0.2), -2.6ems 0ems 0 0ems rgba(0, 0, 0, 0.2), -1.8ems -1.8ems 0 0ems rgba(0, 0, 0, 0.2);
    }
    37.5% {
        box-shadow: 0ems -2.6ems 0ems 0ems rgba(0, 0, 0, 0.2), 1.8ems -1.8ems 0 0ems rgba(0, 0, 0, 0.5), 2.5ems 0ems 0 0ems rgba(0, 0, 0, 0.7), 1.75ems 1.75ems 0 0ems #000000, 0ems 2.5ems 0 0ems rgba(0, 0, 0, 0.2), -1.8ems 1.8ems 0 0ems rgba(0, 0, 0, 0.2), -2.6ems 0ems 0 0ems rgba(0, 0, 0, 0.2), -1.8ems -1.8ems 0 0ems rgba(0, 0, 0, 0.2);
    }
    50% {
        box-shadow: 0ems -2.6ems 0ems 0ems rgba(0, 0, 0, 0.2), 1.8ems -1.8ems 0 0ems rgba(0, 0, 0, 0.2), 2.5ems 0ems 0 0ems rgba(0, 0, 0, 0.5), 1.75ems 1.75ems 0 0ems rgba(0, 0, 0, 0.7), 0ems 2.5ems 0 0ems #000000, -1.8ems 1.8ems 0 0ems rgba(0, 0, 0, 0.2), -2.6ems 0ems 0 0ems rgba(0, 0, 0, 0.2), -1.8ems -1.8ems 0 0ems rgba(0, 0, 0, 0.2);
    }
    62.5% {
        box-shadow: 0ems -2.6ems 0ems 0ems rgba(0, 0, 0, 0.2), 1.8ems -1.8ems 0 0ems rgba(0, 0, 0, 0.2), 2.5ems 0ems 0 0ems rgba(0, 0, 0, 0.2), 1.75ems 1.75ems 0 0ems rgba(0, 0, 0, 0.5), 0ems 2.5ems 0 0ems rgba(0, 0, 0, 0.7), -1.8ems 1.8ems 0 0ems #000000, -2.6ems 0ems 0 0ems rgba(0, 0, 0, 0.2), -1.8ems -1.8ems 0 0ems rgba(0, 0, 0, 0.2);
    }
    75% {
        box-shadow: 0ems -2.6ems 0ems 0ems rgba(0, 0, 0, 0.2), 1.8ems -1.8ems 0 0ems rgba(0, 0, 0, 0.2), 2.5ems 0ems 0 0ems rgba(0, 0, 0, 0.2), 1.75ems 1.75ems 0 0ems rgba(0, 0, 0, 0.2), 0ems 2.5ems 0 0ems rgba(0, 0, 0, 0.5), -1.8ems 1.8ems 0 0ems rgba(0, 0, 0, 0.7), -2.6ems 0ems 0 0ems #000000, -1.8ems -1.8ems 0 0ems rgba(0, 0, 0, 0.2);
    }
    87.5% {
        box-shadow: 0ems -2.6ems 0ems 0ems rgba(0, 0, 0, 0.2), 1.8ems -1.8ems 0 0ems rgba(0, 0, 0, 0.2), 2.5ems 0ems 0 0ems rgba(0, 0, 0, 0.2), 1.75ems 1.75ems 0 0ems rgba(0, 0, 0, 0.2), 0ems 2.5ems 0 0ems rgba(0, 0, 0, 0.2), -1.8ems 1.8ems 0 0ems rgba(0, 0, 0, 0.5), -2.6ems 0ems 0 0ems rgba(0, 0, 0, 0.7), -1.8ems -1.8ems 0 0ems #000000;
    }
}
@keyframes load5 {
    0%,
    100% {
        box-shadow: 0ems -2.6ems 0ems 0ems #000000, 1.8ems -1.8ems 0 0ems rgba(0, 0, 0, 0.2), 2.5ems 0ems 0 0ems rgba(0, 0, 0, 0.2), 1.75ems 1.75ems 0 0ems rgba(0, 0, 0, 0.2), 0ems 2.5ems 0 0ems rgba(0, 0, 0, 0.2), -1.8ems 1.8ems 0 0ems rgba(0, 0, 0, 0.2), -2.6ems 0ems 0 0ems rgba(0, 0, 0, 0.5), -1.8ems -1.8ems 0 0ems rgba(0, 0, 0, 0.7);
    }
    12.5% {
        box-shadow: 0ems -2.6ems 0ems 0ems rgba(0, 0, 0, 0.7), 1.8ems -1.8ems 0 0ems #000000, 2.5ems 0ems 0 0ems rgba(0, 0, 0, 0.2), 1.75ems 1.75ems 0 0ems rgba(0, 0, 0, 0.2), 0ems 2.5ems 0 0ems rgba(0, 0, 0, 0.2), -1.8ems 1.8ems 0 0ems rgba(0, 0, 0, 0.2), -2.6ems 0ems 0 0ems rgba(0, 0, 0, 0.2), -1.8ems -1.8ems 0 0ems rgba(0, 0, 0, 0.5);
    }
    25% {
        box-shadow: 0ems -2.6ems 0ems 0ems rgba(0, 0, 0, 0.5), 1.8ems -1.8ems 0 0ems rgba(0, 0, 0, 0.7), 2.5ems 0ems 0 0ems #000000, 1.75ems 1.75ems 0 0ems rgba(0, 0, 0, 0.2), 0ems 2.5ems 0 0ems rgba(0, 0, 0, 0.2), -1.8ems 1.8ems 0 0ems rgba(0, 0, 0, 0.2), -2.6ems 0ems 0 0ems rgba(0, 0, 0, 0.2), -1.8ems -1.8ems 0 0ems rgba(0, 0, 0, 0.2);
    }
    37.5% {
        box-shadow: 0ems -2.6ems 0ems 0ems rgba(0, 0, 0, 0.2), 1.8ems -1.8ems 0 0ems rgba(0, 0, 0, 0.5), 2.5ems 0ems 0 0ems rgba(0, 0, 0, 0.7), 1.75ems 1.75ems 0 0ems #000000, 0ems 2.5ems 0 0ems rgba(0, 0, 0, 0.2), -1.8ems 1.8ems 0 0ems rgba(0, 0, 0, 0.2), -2.6ems 0ems 0 0ems rgba(0, 0, 0, 0.2), -1.8ems -1.8ems 0 0ems rgba(0, 0, 0, 0.2);
    }
    50% {
        box-shadow: 0ems -2.6ems 0ems 0ems rgba(0, 0, 0, 0.2), 1.8ems -1.8ems 0 0ems rgba(0, 0, 0, 0.2), 2.5ems 0ems 0 0ems rgba(0, 0, 0, 0.5), 1.75ems 1.75ems 0 0ems rgba(0, 0, 0, 0.7), 0ems 2.5ems 0 0ems #000000, -1.8ems 1.8ems 0 0ems rgba(0, 0, 0, 0.2), -2.6ems 0ems 0 0ems rgba(0, 0, 0, 0.2), -1.8ems -1.8ems 0 0ems rgba(0, 0, 0, 0.2);
    }
    62.5% {
        box-shadow: 0ems -2.6ems 0ems 0ems rgba(0, 0, 0, 0.2), 1.8ems -1.8ems 0 0ems rgba(0, 0, 0, 0.2), 2.5ems 0ems 0 0ems rgba(0, 0, 0, 0.2), 1.75ems 1.75ems 0 0ems rgba(0, 0, 0, 0.5), 0ems 2.5ems 0 0ems rgba(0, 0, 0, 0.7), -1.8ems 1.8ems 0 0ems #000000, -2.6ems 0ems 0 0ems rgba(0, 0, 0, 0.2), -1.8ems -1.8ems 0 0ems rgba(0, 0, 0, 0.2);
    }
    75% {
        box-shadow: 0ems -2.6ems 0ems 0ems rgba(0, 0, 0, 0.2), 1.8ems -1.8ems 0 0ems rgba(0, 0, 0, 0.2), 2.5ems 0ems 0 0ems rgba(0, 0, 0, 0.2), 1.75ems 1.75ems 0 0ems rgba(0, 0, 0, 0.2), 0ems 2.5ems 0 0ems rgba(0, 0, 0, 0.5), -1.8ems 1.8ems 0 0ems rgba(0, 0, 0, 0.7), -2.6ems 0ems 0 0ems #000000, -1.8ems -1.8ems 0 0ems rgba(0, 0, 0, 0.2);
    }
    87.5% {
        box-shadow: 0ems -2.6ems 0ems 0ems rgba(0, 0, 0, 0.2), 1.8ems -1.8ems 0 0ems rgba(0, 0, 0, 0.2), 2.5ems 0ems 0 0ems rgba(0, 0, 0, 0.2), 1.75ems 1.75ems 0 0ems rgba(0, 0, 0, 0.2), 0ems 2.5ems 0 0ems rgba(0, 0, 0, 0.2), -1.8ems 1.8ems 0 0ems rgba(0, 0, 0, 0.5), -2.6ems 0ems 0 0ems rgba(0, 0, 0, 0.7), -1.8ems -1.8ems 0 0ems #000000;
    }
}

The real problem is that all 'em' are changed to 'ems'
So when I called toString() method, the css is different from the original css.

Help me How Can I Solved them.

parseStyleSheet error

Hi @rbri
This code not work, erorr invalid token "100vh"

String cssText = ".section-actions-hero{height:calc(100vh - 72px)}";
CSSOMParser parser =  new CSSOMParser(new CSS3Parser());
final Reader reader = new StringReader(cssText);
final InputSource is = new InputSource(reader);
parser.parseStyleSheet(is, null);

This code work

String cssText = ".section-actions-hero{height:calc(100vh - 72px)}";
CSSOMParser parser =  new CSSOMParser(new CSS3Parser());
parser.parseStyleDeclaration(cssText);

CSS calc() function is not supported

Hello @rbri htmlunit-cssparser not support css function calc()

Example 1

final String css = "#foo {width: calc(100px + 100px)}";
final InputSource source = new InputSource(new StringReader(css));
final CSSOMParser parser = new CSSOMParser();
final CSSStyleSheet sheet = parser.parseStyleSheet(source, null);
final CSSRuleList rules = sheet.getCssRules();
CSSRule rule = rules.item(0);
System.out.println(rule.getCssText()); 

 [1:26] Error in expression. (Invalid token " ". Was expecting one of: <NUMBER>, "inherit", <IDENT>, <STRING>, <HASH>, <EMS>, <EXS>, <LENGTH_PX>, <LENGTH_CM>, <LENGTH_MM>, <LENGTH_IN>, <LENGTH_PT>, <LENGTH_PC>, <ANGLE_DEG>, <ANGLE_RAD>, <ANGLE_GRAD>, <TIME_MS>, <TIME_S>, <FREQ_HZ>, <FREQ_KHZ>, <RESOLUTION_DPI>, <RESOLUTION_DPCM>, <PERCENTAGE>, <DIMENSION>, <UNICODE_RANGE>, <URI>, <FUNCTION>, "progid:".)
*#foo { }

Example 2

final String css = "#foo {width: calc(100px+100px)}";
final InputSource source = new InputSource(new StringReader(css));
final CSSOMParser parser = new CSSOMParser();
final CSSStyleSheet sheet = parser.parseStyleSheet(source, null);
final CSSRuleList rules = sheet.getCssRules();
CSSRule rule = rules.item(0);
System.out.println(rule.getCssText()); ---- > Return  *#foo { width: calc(100px 100px) }

Example 3

final String css = "#foo {width: calc(100px/100px)}";
final InputSource source = new InputSource(new StringReader(css));
final CSSOMParser parser = new CSSOMParser();
final CSSStyleSheet sheet = parser.parseStyleSheet(source, null);
final CSSRuleList rules = sheet.getCssRules();
CSSRule rule = rules.item(0);
System.out.println(rule.getCssText());  Return  *#foo { width: calc(100px 100px) }


null [1:24] Error in expression. (Invalid token "/". Was expecting one of: <S>, <NUMBER>, "inherit", <IDENT>, <STRING>, ")", "-", "=", <PLUS>, <COMMA>, <HASH>, <EMS>, <EXS>, <LENGTH_PX>, <LENGTH_CM>, <LENGTH_MM>, <LENGTH_IN>, <LENGTH_PT>, <LENGTH_PC>, <ANGLE_DEG>, <ANGLE_RAD>, <ANGLE_GRAD>, <TIME_MS>, <TIME_S>, <FREQ_HZ>, <FREQ_KHZ>, <RESOLUTION_DPI>, <RESOLUTION_DPCM>, <PERCENTAGE>, <DIMENSION>, <UNICODE_RANGE>, <URI>, <FUNCTION>, "progid:".)
*#foo { }

Example 4

final String css = "#foo {width: calc(100% - 100px)}";
final InputSource source = new InputSource(new StringReader(css));
final CSSOMParser parser = new CSSOMParser();
final CSSStyleSheet sheet = parser.parseStyleSheet(source, null);
final CSSRuleList rules = sheet.getCssRules();
CSSRule rule = rules.item(0);
System.out.println(rule.getCssText());


null [1:25] Error in expression. (Invalid token " ". Was expecting one of: <NUMBER>, "inherit", <IDENT>, <STRING>, <HASH>, <EMS>, <EXS>, <LENGTH_PX>, <LENGTH_CM>, <LENGTH_MM>, <LENGTH_IN>, <LENGTH_PT>, <LENGTH_PC>, <ANGLE_DEG>, <ANGLE_RAD>, <ANGLE_GRAD>, <TIME_MS>, <TIME_S>, <FREQ_HZ>, <FREQ_KHZ>, <RESOLUTION_DPI>, <RESOLUTION_DPCM>, <PERCENTAGE>, <DIMENSION>, <UNICODE_RANGE>, <URI>, <FUNCTION>, "progid:".)
*#foo { }

Method too large: com/gargoylesoftware/css/parser/javacc/CSS3ParserTokenManager

If you are using https://www.eclemma.org/jacoco/ for code analysis and the project under test uses htmlunit-cssparser then you get the following output during analysis.

[...]
Caused by: java.io.IOException: Error while instrumenting com/gargoylesoftware/css/parser/javacc/CSS3ParserTokenManager.
	at org.jacoco.agent.rt.internal_43f5073.core.instr.Instrumenter.instrumentError(Instrumenter.java:159)
	at org.jacoco.agent.rt.internal_43f5073.core.instr.Instrumenter.instrument(Instrumenter.java:109)
	at org.jacoco.agent.rt.internal_43f5073.CoverageTransformer.transform(CoverageTransformer.java:92)
	... 106 more
Caused by: org.jacoco.agent.rt.internal_43f5073.asm.MethodTooLargeException: Method too large: com/gargoylesoftware/css/parser/javacc/CSS3ParserTokenManager.jjMoveNfa_0 (II)I
	at org.jacoco.agent.rt.internal_43f5073.asm.MethodWriter.computeMethodInfoSize(MethodWriter.java:2087)
	at org.jacoco.agent.rt.internal_43f5073.asm.ClassWriter.toByteArray(ClassWriter.java:447)
	at org.jacoco.agent.rt.internal_43f5073.core.instr.Instrumenter.instrument(Instrumenter.java:90)
	at org.jacoco.agent.rt.internal_43f5073.core.instr.Instrumenter.instrument(Instrumenter.java:107)

If I get it right, CSS3ParserTokenManager is part of generated code (https://github.com/HtmlUnit/htmlunit-cssparser/blob/master/pom.xml#L65).

Would it be possible to restructure some part of the code generation to decrease the method size under 64K?

You can find a similar issue at https://stackoverflow.com/questions/37666076/jacoco-method-code-too-large-when-using-ver-0-7-6-and-0-7-5

`.only` cannot be used as a class name selector

Failing test:

$ git diff
diff --git a/src/test/java/org/htmlunit/cssparser/parser/CSS3ParserTest.java b/src/test/java/org/htmlunit/cssparser/parser/CSS3ParserTest.java
index e5386a7..f7240ae 100644
--- a/src/test/java/org/htmlunit/cssparser/parser/CSS3ParserTest.java
+++ b/src/test/java/org/htmlunit/cssparser/parser/CSS3ParserTest.java
@@ -85,6 +85,7 @@ public void selectorList() throws Exception {
      */
     @Test
     public void selector() throws Exception {
+        selectorType(".only", SelectorType.ELEMENT_NODE_SELECTOR);
         selectorType("a#id.class:link", SelectorType.ELEMENT_NODE_SELECTOR);
         selectorType("a#id.class", SelectorType.ELEMENT_NODE_SELECTOR);
         selectorType("a#id:link", SelectorType.ELEMENT_NODE_SELECTOR);
@@ -207,6 +208,7 @@ public void selectorLangInvalid() throws Exception {
      */
     @Test
     public void condition() throws Exception {
+        conditionType(".only", ConditionType.CLASS_CONDITION);
         conditionType("a#id.class:link", ConditionType.ID_CONDITION, ConditionType.CLASS_CONDITION,
                 ConditionType.PSEUDO_CLASS_CONDITION);
         conditionType("a#id.class", ConditionType.ID_CONDITION, ConditionType.CLASS_CONDITION);

Improve performance of NOT execution by reusing a cached parser

Rough idea of a parser cache that is local to the thread. Safes a lot of time because starting a parser is heavy (huge memory requirements) .

Sorry, this is on an older codebase and sat dormant on my machine for a while. Hope that still helps. Benchmarks with our load test tool have shown a dramatic difference in runtime behavior.

From 929f354f81514e15dcbaca69691fa6aae5970b85 Mon Sep 17 00:00:00 2001
From: Rene Schwietzke <[email protected]>
Date: Sat, 14 Jan 2023 13:11:59 +0100
Subject: [PATCH 1/1] Cache parser for not() operations

---
 .../htmlunit/javascript/host/css/CSSStyleSheet.java         | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java b/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java
index d2a7dcc6..4a3ecd36 100644
--- a/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java
+++ b/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java
@@ -142,7 +142,9 @@ import net.sourceforge.htmlunit.corejs.javascript.Context;
  */
 @JsxClass
 public class CSSStyleSheet extends StyleSheet {
-
+    // Xceptance: avoid a new copy of the parser when parsing a selector "not" string
+    private final static ThreadLocal<CSS3Parser> css3SelectorParser = ThreadLocal.withInitial(CSS3Parser::new);
+    
     private static final Log LOG = LogFactory.getLog(CSSStyleSheet.class);
     private static final Pattern NTH_NUMERIC = Pattern.compile("\\d+");
     private static final Pattern NTH_COMPLEX = Pattern.compile("[+-]?\\d*n\\w*([+-]\\w\\d*)?");
@@ -908,7 +910,7 @@ public class CSSStyleSheet extends StyleSheet {
                             errorOccured.set(true);
                         }
                     };
-                    final CSSOMParser parser = new CSSOMParser(new CSS3Parser());
+                    final CSSOMParser parser = new CSSOMParser(css3SelectorParser.get());
                     parser.setErrorHandler(errorHandler);
                     try {
                         final SelectorList selectorList = parser.parseSelectors(selectors);
-- 
2.25.1

Css Font error

Hello @rbri
when i parse this css "font:normal normal normal 14px/11 FontAwesome;" the parser return this error
null [1:1] Error in expression. (Invalid token "/". Was expecting one of: , "inherit", , , "-", , , , , <LENGTH_PX>, <LENGTH_CM>, <LENGTH_MM>, <LENGTH_IN>, <LENGTH_PT>, <LENGTH_PC>, <ANGLE_DEG>, <ANGLE_RAD>, <ANGLE_GRAD>, <TIME_MS>, <TIME_S>, <FREQ_HZ>, <FREQ_KHZ>, <RESOLUTION_DPI>, <RESOLUTION_DPCM>, , , <UNICODE_RANGE>, , , "progid:".)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.