radkovo / jStyleParser

jStyleParser is a CSS parser written in Java. It has its own application interface that is designed to allow an efficient CSS processing in Java and mapping the values to the Java data types. It parses CSS 2.1 style sheets into structures that can be efficiently assigned to DOM elements. It is intended be the primary CSS parser for the CSSBox library. While handling errors, it is user agent conforming according to the CSS specification.
http://cssbox.sourceforge.net/jstyleparser/
GNU Lesser General Public License v3.0
92 stars 49 forks source link

Fix for infinite loop when there are two adjacent @charset rules #59

Closed hrj closed 8 years ago

hrj commented 8 years ago

Consider an imported stylesheet that contains two adjacent @charset rules:

@charset "xyz";@charset "pqr";

The current code accepts the second @charset rule because the token-count is not incremented after the first @charset rule. Since the parsing is restarted when a @charset rule is processed and the new charset value differs from the previous value, the parser goes into an infinite loop.

This change fixes this by ensuring that the token-count is incremented and hence, the second @charset rule is ignored.

I have tested this change with gngr and the whole CSS2.1 test suite.

radkovo commented 8 years ago

Many thanks, merged. FYI, you may have noticed that some developers are (working)[https://github.com/radkovo/jStyleParser/network] on a migration of jStyleParser from ANTLRv3 to ANTLRv4. It seems to be almost done (all tests are passing) plan to merge their contributions during June. I believe this should improve the parser performance as well.

hrj commented 8 years ago

Oh nice! Wasn't aware of that work; thanks for the heads up.

Will it change the API? I am guessing (and hoping) it won't.

radkovo commented 8 years ago

The API should not change.

hrj commented 8 years ago

When it reaches PR stage, I could run it through the css 2.1 test suite and check for regressions.