This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 12420 - StyleSheetParser.parseStyleAttribute does not catch TokenMgrError
Summary: StyleSheetParser.parseStyleAttribute does not catch TokenMgrError
Status: NEW
Alias: None
Product: CSSValidator
Classification: Unclassified
Component: Parser (show other bugs)
Version: CSS Validator
Hardware: PC Linux
: P2 normal
Target Milestone: ---
Assignee: This bug has no owner yet - up for the taking
QA Contact: qa-dev tracking
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-04-05 10:11 UTC by fd
Modified: 2011-04-05 10:11 UTC (History)
0 users

See Also:


Attachments

Description fd 2011-04-05 10:11:29 UTC
Context
-------
The StyleSheetParser can parse the contents of a URL, a style element, or a style attribute, through the methods parseUrl, parseStyleElement and parseStyleAttribute.

TokenMgrError errors get raised when there is something really weird in the stream under test. From what I can tell, it's not the parser's fault when that happens, it's because there's something wrong in the stream under test. See below for an example.


Bug
---
TokenMgrError get correctly caught by parseStyleElement and converted into parse errors that are notified to the user.

They are not caught by parseStyleAttribute though (and do not seem to be caught by parseUrl either, actually). The online CSS validator thus reports an unknown error when that happens, which makes it look as if it crashed.

Other tools that use the CSS validator as a library will think the CSS crashed as well. At least, that's what the mobileOK Checker does :) (actually, the mobileOK Checker crashes as well because it expects Exception to be raised, not Error, but that's another story).


Location in the code
-----
http://dev.w3.org/cvsweb/2002/css-validator/org/w3c/css/css/StyleSheetParser.java?rev=1.17;content-type=text%2Fplain


Example
-----
Take an HTML page that contains a element with a style attribute whose value contains "<%".

Example of a Web page that triggers such an error right now:
 http://www.htc.com/us

... which contains the following HTML element:
 <ul id="ctl00_MenuTopDiscoverSub" class="discover-htc" style="&lt;%=ViewContext.RouteData.Values[&quot;Language&quot;] != null ? &quot;padding-left:45px;&quot; :&quot;&quot;%>">

On this page, the online CSS validator returns the following message:
[[ Unknown error org.w3c.css.parser.analyzer.TokenMgrError: Lexical error at line 1, column 2. Encountered: "%" (37), after : "<" ]]
... and internally, parseStyleAttribute raises a TokenMgrError.

Running the online CSS parser on the contents of the style attribute using direct input correctly returns a parse error:
[[ Parse Error Lexical error at line 1, column 2. Encountered: "%" (37), after : "<" ]]


Solution
-----
Handle exceptions consistently in StyleSheetParser.

Also, if TokenMgrError errors get raised because of the input stream, it might make sense to have them extend IOException rather than Error.