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 6286 - XML comments are incorrectly counted in HTTPXHTMLResource.java
Summary: XML comments are incorrectly counted in HTTPXHTMLResource.java
Status: RESOLVED FIXED
Alias: None
Product: mobileOK Basic checker
Classification: Unclassified
Component: Java Library (show other bugs)
Version: unspecified
Hardware: PC Linux
: P2 normal
Target Milestone: ---
Assignee: Abel Rionda
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-12-06 22:32 UTC by fd
Modified: 2008-12-06 22:34 UTC (History)
0 users

See Also:


Attachments

Description fd 2008-12-06 22:32:08 UTC
The regular expression used to match comments in HTTPXHTMLResource.java is defined as:
 Pattern.compile("(<!-- .* -->)", Pattern.MULTILINE);

This is incorrect because:
 1. "." does not match new lines unless the Pattern.DOTALL is also set
 2. regular expression are greedy in Java, meaning that if there is one comment at the beginning of the document and one comment at the end, the regular expression will just match the entire document between the beginning of the first comment and the end of the second one
 3. There may be no space between the beginning and the end of the comment, i.e. "<!--comment-->" is a valid comment.

The correct regular expression should rather be:
 Pattern.compile("(<!--.*?-->)", Pattern.MULTILINE | Pattern.DOTALL);
Comment 1 fd 2008-12-06 22:34:13 UTC
Fixed regular expression in HTTPXHTMLResource.java