Skip to content

Commit e63c99b

Browse files
Allow preprocessing of the input stream to be skipped
This change adds an optional isPreprocessed boolean parameter to the StyleSheetParser() constructor; if the value of that parameter is true, the steps from https://drafts.csswg.org/css-syntax/#input-preprocessing for preprocessing the input stream are skipped — so UnescapeFilterReader() is not called. This is useful in a context where the input stream has already been preprocessed — for example, if the contents of the stylesheet being parsed are from an HTML document that has already been parsed by a conformant HTML parser (which is the case, for example, when the https://github.com/validator/validator HTML checker calls the code).
1 parent eca30bb commit e63c99b

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

org/w3c/css/css/StyleSheetParser.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public final class StyleSheetParser
5050
implements CssValidatorListener, CssParser {
5151

5252
private static Constructor co = null;
53+
private static boolean isPreprocessed;
5354

5455
static {
5556
try {
@@ -64,10 +65,15 @@ public final class StyleSheetParser
6465
CssFouffa cssFouffa;
6566
StyleSheet style = new StyleSheet();
6667

67-
public StyleSheetParser(ApplContext ac) {
68+
public StyleSheetParser(ApplContext ac, boolean isPreprocessed) {
69+
this.isPreprocessed = isPreprocessed;
6870
ac.setStyleSheet(getStyleSheet());
6971
}
7072

73+
public StyleSheetParser(ApplContext ac) {
74+
new StyleSheetParser(ac, false);
75+
}
76+
7177
public void reInit() {
7278
style = new StyleSheet();
7379
}
@@ -293,7 +299,8 @@ public void parseStyleElement(ApplContext ac, Reader reader,
293299

294300
// if (cssFouffa == null) {
295301
String charset = ac.getCharsetForURL(url);
296-
if (ac.getCssVersion().compareTo(CssVersion.CSS2) >=0 ) {
302+
if (ac.getCssVersion().compareTo(CssVersion.CSS2) >=0
303+
&& !isPreprocessed) {
297304
cssFouffa = new CssFouffa(ac, new UnescapeFilterReader(new BufferedReader(reader)), url, lineno);
298305
} else {
299306
cssFouffa = new CssFouffa(ac, reader, url, lineno);

0 commit comments

Comments
 (0)