From e63c99bb9eb81d7e4dd9667e2ebf57b01f51423a Mon Sep 17 00:00:00 2001 From: "Michael[tm] Smith" Date: Sun, 30 Oct 2022 18:27:21 +0900 Subject: [PATCH] Allow preprocessing of the input stream to be skipped MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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). --- org/w3c/css/css/StyleSheetParser.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/org/w3c/css/css/StyleSheetParser.java b/org/w3c/css/css/StyleSheetParser.java index c6c3a97c6..70dcff87c 100644 --- a/org/w3c/css/css/StyleSheetParser.java +++ b/org/w3c/css/css/StyleSheetParser.java @@ -50,6 +50,7 @@ public final class StyleSheetParser implements CssValidatorListener, CssParser { private static Constructor co = null; + private static boolean isPreprocessed; static { try { @@ -64,10 +65,15 @@ public final class StyleSheetParser CssFouffa cssFouffa; StyleSheet style = new StyleSheet(); - public StyleSheetParser(ApplContext ac) { + public StyleSheetParser(ApplContext ac, boolean isPreprocessed) { + this.isPreprocessed = isPreprocessed; ac.setStyleSheet(getStyleSheet()); } + public StyleSheetParser(ApplContext ac) { + new StyleSheetParser(ac, false); + } + public void reInit() { style = new StyleSheet(); } @@ -293,7 +299,8 @@ public void parseStyleElement(ApplContext ac, Reader reader, // if (cssFouffa == null) { String charset = ac.getCharsetForURL(url); - if (ac.getCssVersion().compareTo(CssVersion.CSS2) >=0 ) { + if (ac.getCssVersion().compareTo(CssVersion.CSS2) >=0 + && !isPreprocessed) { cssFouffa = new CssFouffa(ac, new UnescapeFilterReader(new BufferedReader(reader)), url, lineno); } else { cssFouffa = new CssFouffa(ac, reader, url, lineno);