[Git][java-team/libowasp-antisamy-java][upstream] 4 commits: New upstream version 1.7.5

Emmanuel Bourg (@ebourg) gitlab at salsa.debian.org
Tue Oct 27 08:14:32 GMT 2026



Emmanuel Bourg pushed to branch upstream at Debian Java Maintainers / libowasp-antisamy-java


Commits:
6a96d708 by Emmanuel Bourg at 2026-03-16T08:16:51+01:00
New upstream version 1.7.5
- - - - -
c4a7ca27 by Emmanuel Bourg at 2026-03-16T08:16:58+01:00
New upstream version 1.7.6
- - - - -
71f4da8f by Emmanuel Bourg at 2026-03-16T08:17:05+01:00
New upstream version 1.7.7
- - - - -
f5997fbf by Emmanuel Bourg at 2026-03-16T08:17:11+01:00
New upstream version 1.7.8
- - - - -


30 changed files:

- .github/workflows/codeql-analysis.yml
- .github/workflows/maven.yml
- .github/workflows/shiftleft-analysis.yml
- README.md
- SECURITY.md
- pom.xml
- src/main/java/org/owasp/validator/css/CssHandler.java
- src/main/java/org/owasp/validator/css/CssParser.java
- src/main/java/org/owasp/validator/css/CssValidator.java
- + src/main/java/org/owasp/validator/css/media/CssMediaFeature.java
- + src/main/java/org/owasp/validator/css/media/CssMediaQuery.java
- + src/main/java/org/owasp/validator/css/media/CssMediaQueryList.java
- + src/main/java/org/owasp/validator/css/media/CssMediaQueryLogicalOperator.java
- + src/main/java/org/owasp/validator/css/media/CssMediaType.java
- src/main/java/org/owasp/validator/html/CleanResults.java
- src/main/java/org/owasp/validator/html/Policy.java
- src/main/java/org/owasp/validator/html/model/Tag.java
- src/main/java/org/owasp/validator/html/scan/ASHTMLSerializer.java
- src/main/java/org/owasp/validator/html/scan/AntiSamyDOMScanner.java
- src/main/java/org/owasp/validator/html/scan/AntiSamySAXScanner.java
- src/main/java/org/owasp/validator/html/scan/MagicSAXFilter.java
- src/main/resources/antisamy-anythinggoes.xml
- src/main/resources/antisamy-ebay.xml
- src/main/resources/antisamy-myspace.xml
- src/main/resources/antisamy.xml
- src/site/site.xml
- + src/test/java/org/owasp/validator/css/CssValidatorTest.java
- src/test/java/org/owasp/validator/html/test/AntiSamyTest.java
- src/test/java/org/owasp/validator/html/test/LiteralTest.java
- src/test/java/org/owasp/validator/html/test/TestPolicy.java


Changes:

=====================================
.github/workflows/codeql-analysis.yml
=====================================
@@ -45,7 +45,7 @@ jobs:
 
     # Initializes the CodeQL tools for scanning.
     - name: Initialize CodeQL
-      uses: github/codeql-action/init at v2
+      uses: github/codeql-action/init at v3
       with:
         languages: ${{ matrix.language }}
         # If you wish to specify custom queries, you can do so here or in a config file.
@@ -56,7 +56,7 @@ jobs:
     # Autobuild attempts to build any compiled languages  (C/C++, C#, or Java).
     # If this step fails, then you should remove it and run the build manually (see below)
     - name: Autobuild
-      uses: github/codeql-action/autobuild at v2
+      uses: github/codeql-action/autobuild at v3
 
     # ℹ️ Command-line programs to run using the OS shell.
     # 📚 https://git.io/JvXDl
@@ -70,5 +70,5 @@ jobs:
     #   make release
 
     - name: Perform CodeQL Analysis
-      uses: github/codeql-action/analyze at v2
+      uses: github/codeql-action/analyze at v3
 


=====================================
.github/workflows/maven.yml
=====================================
@@ -13,10 +13,10 @@ jobs:
     - uses: actions/checkout at v4
       with:
         fetch-depth: 0
-    - name: Set up JDK 1.8
-      uses: actions/setup-java at v3
+    - name: Set up JDK 11
+      uses: actions/setup-java at v4
       with:
-        java-version: 8
+        java-version: 11
         distribution: zulu
     - name: Run unit tests
       run: mvn test


=====================================
.github/workflows/shiftleft-analysis.yml
=====================================
@@ -35,6 +35,6 @@ jobs:
         # type: python
 
     - name: Upload report
-      uses: github/codeql-action/upload-sarif at v2
+      uses: github/codeql-action/upload-sarif at v3
       with:
         sarif_file: reports


=====================================
README.md
=====================================
@@ -19,6 +19,11 @@ Throughout the development of the 1.6.x series, we have identified and deprecate
  * XML Schema validation is now required on AntiSamy policy files and cannot be disabled. You must make your policy file schema compliant in order to use it with AntiSamy.
  * The policy directive `noopenerAndNoreferrerAnchors` is now ON by default. If it is disabled, AntiSamy issues a nag, encouraging you to enable it.
 
+## Output format disclaimers
+Along AntiSamy's upgrade lifecycle the HTML parser dependency had changes, leading into some output differences that may come up depending on the use case. Consider this if you were using certain versions and get different outputs after upgrading.
+
+This can also apply for the output serializer that transforms the internal HTML representation to the final text output of the tool.
+
 ## Deprecating support for external stylesheets
 
 The AntiSamy team has decided that supporting the ability to allow embedded remote CSS is dangerous and so we are deprecating this feature and it will be removed in a future release. It is expected that there are very few, if any, users of this feature.


=====================================
SECURITY.md
=====================================
@@ -28,16 +28,16 @@ can understand what needs to be done to fix it.
 
 These are the known CVEs reported for AntiSamy:
 
-* AntiSamy CVE #1 - CVE-2016-10006: XSS Bypass in AntiSamy before v1.5.5 - https://www.cvedetails.com/cve/CVE-2016-10006
-* AntiSamy CVE #2 - CVE-2017-14735: XSS via HTML5 Entities in AntiSamy before v1.5.7 - https://www.cvedetails.com/cve/CVE-2017-14735
-* AntiSamy CVE #3 - CVE-2021-35043: XSS via HTML attributes using &#00058 as replacement for : character before v1.6.4 - https://www.cvedetails.com/cve/CVE-2021-35043
-* AntiSamy CVE #4 - CVE-2022-28367: AntiSamy before 1.6.6 allows XSS via HTML tag smuggling on STYLE content. https://www.cvedetails.com/cve/CVE-2022-28367. NOTE: This release only included a PARTIAL fix.
-* AntiSamy CVE #5 - CVE-2022-29577: AntiSamy before 1.6.7 allows XSS via HTML tag smuggling on STYLE content. - https://www.cvedetails.com/cve/CVE-2022-29577. This is the complete fix to the previous CVE.
-* AntiSamy CVE #6 - CVE-2023-43643: AntiSamy before 1.7.4 subject to mXSS when preserving comments. - https://www.cvedetails.com/cve/CVE-2023-43643
+* AntiSamy CVE #1 - CVE-2016-10006: AntiSamy before 1.5.5 allows XSS Bypass - https://nvd.nist.gov/vuln/detail/CVE-2016-10006
+* AntiSamy CVE #2 - CVE-2017-14735: AntiSamy before 1.5.7 allows XSS via HTML5 Entities - https://nvd.nist.gov/vuln/detail/CVE-2017-14735
+* AntiSamy CVE #3 - CVE-2021-35043: AntiSamy before 1.6.4 allows XSS via HTML attributes using &#00058 as replacement for : character - https://nvd.nist.gov/vuln/detail/CVE-2021-35043
+* AntiSamy CVE #4 - CVE-2022-28367: AntiSamy before 1.6.6 allows XSS via HTML tag smuggling on STYLE content - https://nvd.nist.gov/vuln/detail/CVE-2022-28367. NOTE: This release only included a PARTIAL fix.
+* AntiSamy CVE #5 - CVE-2022-29577: AntiSamy before 1.6.7 allows XSS via HTML tag smuggling on STYLE content - https://nvd.nist.gov/vuln/detail/CVE-2022-29577. This is the complete fix to the previous CVE.
+* AntiSamy CVE #6 - CVE-2023-43643: AntiSamy before 1.7.4 subject to mutation XSS (mXSS) when preserving comments - https://nvd.nist.gov/vuln/detail/CVE-2023-43643
+* AntiSamy CVE #7 - CVE-2024-23635: AntiSamy before 1.7.5 subject to mXSS when preserving comments - https://nvd.nist.gov/vuln/detail/CVE-2024-23635
 
 CVEs in AntiSamy dependencies:
-* AntiSamy prior to 1.6.6 used the old CyberNeko HTML library v1.9.22, which is subject to https://www.cvedetails.com/cve/CVE-2022-28366 and no longer maintained. AntiSamy 1.6.6 upgraded to an active fork of CyberNeko called HtmlUnit-Neko which fixed this CVE in v2.27 of that library. AntiSamy 1.6.6 upgraded to version 2.60.0 of HtmlUnit-Neko.
-* AntiSamy 1.6.8 upgraded to HtmlUnit-Neko v2.61.0 because v2.60.0 is subject to https://www.cvedetails.com/cve/CVE-2022-29546
-* AntiSamy 1.7.3 upgraded to HtmlUnit-Neko v3.1.0 because all versions prior to 3.0.0 are subject to https://www.cvedetails.com/cve/CVE-2023-26119
-* AntiSamy 1.7.4 upgraded to batik-css v1.17 because batik-css:1.16 is subject to https://www.cvedetails.com/cve/CVE-2022-44729
-
+* AntiSamy before 1.6.6 used the old CyberNeko HTML library net.sourceforge.nekohtml:nekohtml:1.9.22, which is subject to https://nvd.nist.gov/vuln/detail/CVE-2022-28366 and no longer maintained. AntiSamy 1.6.6 upgraded to an active fork of CyberNeko at net.sourceforge.htmlunit:neko-htmlunit which fixed this CVE in v2.27 of that library. AntiSamy 1.6.6 upgraded to net.sourceforge.htmlunit:neko-htmlunit:2.60.0
+* AntiSamy 1.6.8 upgraded to net.sourceforge.htmlunit:neko-htmlunit:2.61.0 because v2.60.0 is subject to https://nvd.nist.gov/vuln/detail/CVE-2022-29546
+* AntiSamy 1.7.3 upgraded to org.htmlunit:neko-htmlunit:3.1.0 because all versions of net.sourceforge.htmlunit:neko-htmlunit prior to 3.0.0 are subject to https://nvd.nist.gov/vuln/detail/CVE-2023-26119 (Note the group name change for neko-htmlunit starting with v3.0.0)
+* AntiSamy 1.7.4 upgraded to batik-css v1.17 because batik-css:1.16 is subject to https://nvd.nist.gov/vuln/detail/CVE-2022-44729


=====================================
pom.xml
=====================================
@@ -5,7 +5,7 @@
     <groupId>org.owasp.antisamy</groupId>
     <artifactId>antisamy</artifactId>
     <packaging>jar</packaging>
-    <version>1.7.4</version>
+    <version>1.7.8</version>
 
     <distributionManagement>
         <snapshotRepository>
@@ -27,6 +27,27 @@
             <id>nahsra</id>
             <name>Arshan Dabirsiaghi</name>
             <email>arshan.dabirsiaghi at gmail.com</email>
+            <roles>
+                <role>Project Creator</role>
+                <role>Original Project Leader</role>
+            </roles>
+        </developer>
+        <developer>
+            <id>davewichers</id>
+            <name>Dave Wichers</name>
+            <email>dave.wichers at owasp.org</email>
+            <roles>
+                <role>Primary Maintainer</role>
+            </roles>
+        </developer>
+        <developer>
+            <id>spassarop</id>
+            <name>Sebastian Passaro</name>
+            <email>sebastian.passaro at owasp.org</email>
+            <roles>
+                <role>XSS Technical Expert</role>
+                <role>Committer</role>
+            </roles>
         </developer>
     </developers>
 
@@ -49,15 +70,15 @@
     </scm>
 
     <properties>
-        <fluido.version>2.0.0-M7</fluido.version>
+        <fluido.version>2.1.0</fluido.version>
         <gpg.skip>true</gpg.skip><!-- by default skip gpg -->
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-        <project.build.outputTimestamp>2023-10-06T21:08:34Z</project.build.outputTimestamp>
+        <project.build.outputTimestamp>2025-05-07T19:56:02Z</project.build.outputTimestamp>
         <project.java.target>1.8</project.java.target>
-        <version.findsecbugs>1.12.0</version.findsecbugs>
-        <version.slf4j>2.0.9</version.slf4j>
-        <version.spotbugs.maven>4.7.3.6</version.spotbugs.maven>
-        <version.spotbugs>4.7.3</version.spotbugs>
+        <version.findsecbugs>1.14.0</version.findsecbugs>
+        <version.slf4j>2.0.17</version.slf4j>
+        <version.spotbugs.maven>4.9.3.0</version.spotbugs.maven>
+        <version.spotbugs>4.9.3</version.spotbugs>
     </properties>
 
     <profiles>
@@ -71,20 +92,21 @@
 
     <dependencies>
         <dependency>
-            <groupId>org.htmlunit</groupId>
-            <artifactId>neko-htmlunit</artifactId>
-            <version>3.6.0</version>
+            <groupId>commons-io</groupId>
+            <artifactId>commons-io</artifactId>
+            <version>2.19.0</version>
         </dependency>
         <dependency>
             <groupId>org.apache.httpcomponents.client5</groupId>
             <artifactId>httpclient5</artifactId>
-            <version>5.2.1</version>
+            <version>5.4.4</version>
             <exclusions>
-                <!-- exclude old versions of slf4j-api and httpcore5 as newer versions can be used -->
+                <!-- exclude this old version as we directly import a newer one -->
                 <exclusion>
                     <groupId>org.slf4j</groupId>
                     <artifactId>slf4j-api</artifactId>
                 </exclusion>
+                <!-- exclude this slightly older version as we directly import a newer one -->
                 <exclusion>
                     <groupId>org.apache.httpcomponents.core5</groupId>
                     <artifactId>httpcore5</artifactId>
@@ -94,48 +116,31 @@
         <dependency>
             <groupId>org.apache.httpcomponents.core5</groupId>
             <artifactId>httpcore5</artifactId>
-            <version>5.2.3</version>
+            <version>5.3.4</version>
         </dependency>
         <dependency>
             <groupId>org.apache.xmlgraphics</groupId>
             <artifactId>batik-css</artifactId>
-            <version>1.17</version>
+            <version>1.19</version>
             <exclusions>
-                <!-- exclude this old version of commons-io as newer can be used -->
+                <!-- exclude this old version as we directly import a newer one -->
                 <exclusion>
                     <groupId>commons-io</groupId>
                     <artifactId>commons-io</artifactId>
                 </exclusion>
-                <!-- exclude this as batik-css has a dependency that uses an older commons-logging and we want to eliminate the convergence mismatch -->
-                <exclusion>
-                    <groupId>commons-logging</groupId>
-                    <artifactId>commons-logging</artifactId>
-                </exclusion>
             </exclusions>
         </dependency>
         <dependency>
-            <groupId>commons-io</groupId>
-            <artifactId>commons-io</artifactId>
-            <version>2.14.0</version>
+            <groupId>org.htmlunit</groupId>
+            <artifactId>neko-htmlunit</artifactId>
+            <version>4.11.0</version>
         </dependency>
         <dependency>
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-api</artifactId>
             <version>${version.slf4j}</version>
         </dependency>
-        <dependency>
-            <groupId>org.slf4j</groupId>
-            <artifactId>jcl-over-slf4j</artifactId>
-            <version>${version.slf4j}</version>
-            <scope>test</scope>
-        </dependency>
-        <!-- without this import you get: SLF4J: Defaulting to no-operation (NOP) logger implementation -->
-        <dependency>
-            <groupId>org.slf4j</groupId>
-            <artifactId>slf4j-simple</artifactId>
-            <version>${version.slf4j}</version>
-            <scope>test</scope>
-        </dependency>
+
         <!-- While Java 7+ includes Xerces in the JRE, it apparently doesn't provide all the features we use that are in the 3rd party version. 
             So we import it directly. -->
         <dependency>
@@ -175,7 +180,7 @@
         <dependency>
             <groupId>commons-codec</groupId>
             <artifactId>commons-codec</artifactId>
-            <version>1.16.0</version>
+            <version>1.18.0</version>
             <scope>test</scope>
         </dependency>
         <dependency>
@@ -193,7 +198,20 @@
         <dependency>
             <groupId>org.hamcrest</groupId>
             <artifactId>hamcrest</artifactId>
-            <version>2.2</version>
+            <version>3.0</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>jcl-over-slf4j</artifactId>
+            <version>${version.slf4j}</version>
+            <scope>test</scope>
+        </dependency>
+        <!-- without this import you get: SLF4J: Defaulting to no-operation (NOP) logger implementation -->
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-simple</artifactId>
+            <version>${version.slf4j}</version>
             <scope>test</scope>
         </dependency>
 
@@ -206,12 +224,12 @@
                 <plugin>
                     <groupId>org.apache.maven.plugins</groupId>
                     <artifactId>maven-assembly-plugin</artifactId>
-                    <version>3.6.0</version>
+                    <version>3.7.1</version>
                 </plugin>
                 <plugin>
                     <groupId>org.apache.maven.plugins</groupId>
                     <artifactId>maven-dependency-plugin</artifactId>
-                    <version>3.6.0</version>
+                    <version>3.8.1</version>
                     <configuration>
                         <usedDependencies>
                             <dependency>commons-io:commons-io</dependency>
@@ -223,7 +241,7 @@
                 <plugin>
                     <groupId>org.apache.maven.plugins</groupId>
                     <artifactId>maven-javadoc-plugin</artifactId>
-                    <version>3.6.0</version>
+                    <version>3.11.2</version>
                     <configuration>
                         <!-- supports reproducibility of generated Javadocs -->
                         <notimestamp>true</notimestamp>
@@ -232,7 +250,7 @@
                 <plugin>
                     <groupId>org.apache.maven.plugins</groupId>
                     <artifactId>maven-release-plugin</artifactId>
-                    <version>3.0.1</version>
+                    <version>3.1.1</version>
                 </plugin>
             </plugins>
         </pluginManagement>
@@ -241,12 +259,12 @@
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-clean-plugin</artifactId>
-                <version>3.3.1</version>
+                <version>3.4.1</version>
             </plugin>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-compiler-plugin</artifactId>
-                <version>3.11.0</version>
+                <version>3.14.0</version>
                 <configuration>
                     <source>${project.java.target}</source>
                     <target>${project.java.target}</target>
@@ -261,22 +279,22 @@
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-deploy-plugin</artifactId>
-                <version>3.1.1</version>
+                <version>3.1.4</version>
             </plugin>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-enforcer-plugin</artifactId>
-                <version>3.4.1</version>
+                <version>3.5.0</version>
                 <dependencies>
                     <dependency>
                         <groupId>org.codehaus.mojo</groupId>
                         <artifactId>extra-enforcer-rules</artifactId>
-                        <version>1.7.0</version>
+                        <version>1.10.0</version>
                     </dependency>
                     <dependency>
                         <groupId>org.codehaus.mojo</groupId>
                         <artifactId>animal-sniffer-enforcer-rule</artifactId>
-                        <version>1.23</version>
+                        <version>1.24</version>
                     </dependency>
                 </dependencies>
                 <executions>
@@ -339,7 +357,7 @@
             <plugin> <!-- This plugin is disabled by default. Invoke the release profile (-Prelease) to enable it. -->
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-gpg-plugin</artifactId>
-                <version>3.1.0</version>
+                <version>3.2.7</version>
                 <executions>
                     <execution>
                         <id>sign-artifacts</id>
@@ -353,12 +371,12 @@
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-install-plugin</artifactId>
-                <version>3.1.1</version>
+                <version>3.1.4</version>
             </plugin>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-jar-plugin</artifactId>
-                <version>3.3.0</version>
+                <version>3.4.2</version>
                 <configuration>
                     <archive>
                         <manifest>
@@ -386,17 +404,17 @@
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-jxr-plugin</artifactId>
-                <version>3.3.0</version>
+                <version>3.6.0</version>
             </plugin>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-pmd-plugin</artifactId>
-                <version>3.21.0</version>
+                <version>3.26.0</version>
             </plugin>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-project-info-reports-plugin</artifactId>
-                <version>3.4.5</version>
+                <version>3.9.0</version>
             </plugin>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
@@ -406,7 +424,7 @@
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-site-plugin</artifactId>
-                <version>4.0.0-M9</version>
+                <version>3.21.0</version>
                 <dependencies>
                     <!-- Explicitly declare these dependencies so the versions plugin and library bots will flag available updates. The fluido-skin 
                         plugin is referenced in src/site/site.xml using the same fluido version property. -->
@@ -420,7 +438,7 @@
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-source-plugin</artifactId>
-                <version>3.3.0</version>
+                <version>3.3.1</version>
                 <executions>
                     <execution>
                         <id>attach-sources</id>
@@ -434,17 +452,17 @@
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-surefire-plugin</artifactId>
-                <version>3.1.2</version>
+                <version>3.5.3</version>
             </plugin>
             <plugin>
                 <groupId>org.codehaus.mojo</groupId>
                 <artifactId>versions-maven-plugin</artifactId>
-                <version>2.16.1</version>
+                <version>2.18.0</version>
             </plugin>
             <plugin>
                 <groupId>org.cyclonedx</groupId>
                 <artifactId>cyclonedx-maven-plugin</artifactId>
-                <version>2.7.9</version>
+                <version>2.9.1</version>
                 <executions>
                     <execution>
                         <phase>package</phase>
@@ -457,7 +475,7 @@
             <plugin>
                 <groupId>org.jacoco</groupId>
                 <artifactId>jacoco-maven-plugin</artifactId>
-                <version>0.8.10</version>
+                <version>0.8.13</version>
                 <executions>
                     <execution>
                         <id>prepare-agent</id>


=====================================
src/main/java/org/owasp/validator/css/CssHandler.java
=====================================
@@ -35,6 +35,10 @@ import java.util.Collection;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.ResourceBundle;
+import org.owasp.validator.css.media.CssMediaFeature;
+import org.owasp.validator.css.media.CssMediaQuery;
+import org.owasp.validator.css.media.CssMediaQueryList;
+import org.owasp.validator.css.media.CssMediaType;
 import org.owasp.validator.html.InternalPolicy;
 import org.owasp.validator.html.Policy;
 import org.owasp.validator.html.ScanException;
@@ -96,6 +100,10 @@ public class CssHandler implements DocumentHandler {
    */
   private boolean selectorOpen = false;
 
+  private MediaState mediaState = MediaState.OUTSIDE;
+
+  private enum MediaState {INSIDE, OUTSIDE, DENIED}
+
   /**
    * Constructs a handler for stylesheets using the given policy. The List of embedded stylesheets
    * produced by this constructor is now available via the getImportedStylesheetsURIList() method.
@@ -171,6 +179,7 @@ public class CssHandler implements DocumentHandler {
    *
    * @see org.w3c.css.sac.DocumentHandler#comment(java.lang.String)
    */
+  @Override
   public void comment(String text) throws CSSException {
     errorMessages.add(
         ErrorMessageUtil.getMessage(
@@ -184,6 +193,7 @@ public class CssHandler implements DocumentHandler {
    *
    * @see org.w3c.css.sac.DocumentHandler#ignorableAtRule(java.lang.String)
    */
+  @Override
   public void ignorableAtRule(String atRule) throws CSSException {
     // this method is called when the parser hits an unrecognized @-rule. Like the page/media/font
     // declarations, this is CSS2+ stuff
@@ -211,6 +221,7 @@ public class CssHandler implements DocumentHandler {
    * @see org.w3c.css.sac.DocumentHandler#importStyle(java.lang.String,
    *      org.w3c.css.sac.SACMediaList, java.lang.String)
    */
+  @Override
   public void importStyle(String uri, SACMediaList media, String defaultNamespaceURI)
       throws CSSException {
 
@@ -292,6 +303,7 @@ public class CssHandler implements DocumentHandler {
    * @see org.w3c.css.sac.DocumentHandler#namespaceDeclaration(java.lang.String,
    *      java.lang.String)
    */
+  @Override
   public void namespaceDeclaration(String prefix, String uri) throws CSSException {
     // CSS3 - Namespace declaration - ignore for now
   }
@@ -301,6 +313,7 @@ public class CssHandler implements DocumentHandler {
    *
    * @see org.w3c.css.sac.DocumentHandler#startDocument(org.w3c.css.sac.InputSource)
    */
+  @Override
   public void startDocument(InputSource arg0) throws CSSException {
     // no-op
   }
@@ -310,6 +323,7 @@ public class CssHandler implements DocumentHandler {
    *
    * @see org.w3c.css.sac.DocumentHandler#endDocument(org.w3c.css.sac.InputSource)
    */
+  @Override
   public void endDocument(InputSource source) throws CSSException {
     // no-op
   }
@@ -319,6 +333,7 @@ public class CssHandler implements DocumentHandler {
    *
    * @see org.w3c.css.sac.DocumentHandler#startFontFace()
    */
+  @Override
   public void startFontFace() throws CSSException {
     // CSS2 Font Face declaration - ignore this for now
   }
@@ -328,34 +343,18 @@ public class CssHandler implements DocumentHandler {
    *
    * @see org.w3c.css.sac.DocumentHandler#endFontFace()
    */
+  @Override
   public void endFontFace() throws CSSException {
     // CSS2 Font Face declaration - ignore this for now
   }
 
-  /*
-   * (non-Javadoc)
-   *
-   * @see org.w3c.css.sac.DocumentHandler#startMedia(org.w3c.css.sac.SACMediaList)
-   */
-  public void startMedia(SACMediaList media) throws CSSException {
-    // CSS2 Media declaration - ignore this for now
-  }
-
-  /*
-   * (non-Javadoc)
-   *
-   * @see org.w3c.css.sac.DocumentHandler#endMedia(org.w3c.css.sac.SACMediaList)
-   */
-  public void endMedia(SACMediaList media) throws CSSException {
-    // CSS2 Media declaration - ignore this for now
-  }
-
   /*
    * (non-Javadoc)
    *
    * @see org.w3c.css.sac.DocumentHandler#startPage(java.lang.String,
    *      java.lang.String)
    */
+  @Override
   public void startPage(String name, String pseudoPage) throws CSSException {
     // CSS2 Page declaration - ignore this for now
   }
@@ -366,6 +365,7 @@ public class CssHandler implements DocumentHandler {
    * @see org.w3c.css.sac.DocumentHandler#endPage(java.lang.String,
    *      java.lang.String)
    */
+  @Override
   public void endPage(String name, String pseudoPage) throws CSSException {
     // CSS2 Page declaration - ignore this for now
   }
@@ -375,6 +375,7 @@ public class CssHandler implements DocumentHandler {
    *
    * @see org.w3c.css.sac.DocumentHandler#startSelector(org.w3c.css.sac.SelectorList)
    */
+  @Override
   public void startSelector(SelectorList selectors) throws CSSException {
 
     // keep track of number of valid selectors from this rule
@@ -455,6 +456,7 @@ public class CssHandler implements DocumentHandler {
    *
    * @see org.w3c.css.sac.DocumentHandler#endSelector(org.w3c.css.sac.SelectorList)
    */
+  @Override
   public void endSelector(SelectorList selectors) throws CSSException {
     // if we are in a state within a selector, close brace
     if (selectorOpen) {
@@ -472,6 +474,7 @@ public class CssHandler implements DocumentHandler {
    * @see org.w3c.css.sac.DocumentHandler#property(java.lang.String,
    *      org.w3c.css.sac.LexicalUnit, boolean)
    */
+  @Override
   public void property(String name, LexicalUnit value, boolean important) throws CSSException {
     // only bother validating and building if we are either inline or within a selector tag
 
@@ -523,4 +526,56 @@ public class CssHandler implements DocumentHandler {
               }));
     }
   }
+
+  @Override
+  public void startMedia(SACMediaList media) throws CSSException {
+    CssMediaQueryList mediaQueryList = (CssMediaQueryList) media;
+
+    boolean first = true;
+    for (CssMediaQuery query : mediaQueryList.getMediaQueries()) {
+      if (!validator.isValidMediaQuery(query)) {
+        continue;
+      }
+      if (first) {
+        styleSheet.append("@media ");
+        first = false;
+      } else {
+        styleSheet.append(", ");
+      }
+      if (query.getLogicalOperator() != null) {
+        styleSheet.append(query.getLogicalOperator()).append(' ');
+      }
+      styleSheet.append(query.getMediaType());
+      for (CssMediaFeature feature : query.getMediaFeatures()) {
+        if (feature == query.getMediaFeatures().get(0) && query.getMediaType() == CssMediaType.IMPLIED_ALL) {
+          styleSheet.append("(");
+        } else {
+          styleSheet.append(" and (");
+        }
+        styleSheet.append(feature.getName());
+        if (feature.getExpression() != null) {
+          styleSheet.append(": ");
+          styleSheet.append(validator.lexicalValueToString(feature.getExpression()));
+        }
+        styleSheet.append(')');
+      }
+    }
+
+    if (!first) {
+      styleSheet.append(" {");
+      styleSheet.append('\n');
+      mediaState = MediaState.INSIDE;
+    } else {
+      mediaState = MediaState.DENIED;
+    }
+  }
+
+  @Override
+  public void endMedia(SACMediaList media) throws CSSException {
+    if (mediaState == MediaState.INSIDE) {
+      styleSheet.append('}');
+      styleSheet.append('\n');
+    }
+    mediaState = MediaState.OUTSIDE;
+  }
 }


=====================================
src/main/java/org/owasp/validator/css/CssParser.java
=====================================
@@ -28,70 +28,226 @@
  */
 package org.owasp.validator.css;
 
+import static org.owasp.validator.css.media.CssMediaQueryLogicalOperator.AND;
+import static org.owasp.validator.css.media.CssMediaQueryLogicalOperator.OR;
+
+import org.apache.batik.css.parser.CSSSACMediaList;
 import org.apache.batik.css.parser.LexicalUnits;
+import org.owasp.validator.css.media.CssMediaFeature;
+import org.owasp.validator.css.media.CssMediaQuery;
+import org.owasp.validator.css.media.CssMediaQueryList;
+import org.owasp.validator.css.media.CssMediaQueryLogicalOperator;
+import org.owasp.validator.css.media.CssMediaType;
 import org.w3c.css.sac.CSSException;
 import org.w3c.css.sac.CSSParseException;
 import org.w3c.css.sac.LexicalUnit;
 
 public class CssParser extends org.apache.batik.css.parser.Parser {
 
-    /**
-     * This implementation is a workaround to solve leading dash errors on property names.
-     * @see <code>https://issues.apache.org/jira/browse/BATIK-1112</code>
-     * @param inSheet Specifies if the style to parse is inside a sheet or the sheet itself.
-     * @throws CSSException Thrown if there are parsing errors in CSS
-     */
-    protected void parseStyleDeclaration(final boolean inSheet) throws CSSException {
-        boolean leadingDash = false;
-        for (;;) {
-            switch (current) {
-                case LexicalUnits.EOF:
-                    if (inSheet) {
-                        throw createCSSParseException("eof");
-                    }
-                    return;
-                case LexicalUnits.RIGHT_CURLY_BRACE:
-                    if (!inSheet) {
-                        throw createCSSParseException("eof.expected");
-                    }
-                    nextIgnoreSpaces();
-                    return;
-                case LexicalUnits.SEMI_COLON:
-                    nextIgnoreSpaces();
-                    continue;
-                case LexicalUnits.MINUS:
-                    leadingDash = true;
-                    next();
-                    break;
-                default:
-                    throw createCSSParseException("identifier");
-                case LexicalUnits.IDENTIFIER:
-            }
-
-            final String name = (leadingDash ? "-" : "") + scanner.getStringValue();
-            leadingDash = false;
-
-            if (nextIgnoreSpaces() != LexicalUnits.COLON) {
-                throw createCSSParseException("colon");
-            }
-            nextIgnoreSpaces();
-
-            LexicalUnit exp = null;
-
-            try {
-                exp = parseExpression(false);
-            } catch (final CSSParseException e) {
-                reportError(e);
-            }
-
-            if (exp != null) {
-                boolean important = false;
-                if (current == LexicalUnits.IMPORTANT_SYMBOL) {
-                    important = true;
-                    nextIgnoreSpaces();
-                }
-                documentHandler.property(name, exp, important);
-            }
+  /**
+   * This implementation is a workaround to solve leading dash errors on property names.
+   *
+   * @see <code>https://issues.apache.org/jira/browse/BATIK-1112</code>
+   * @param inSheet Specifies if the style to parse is inside a sheet or the sheet itself.
+   * @throws CSSException Thrown if there are parsing errors in CSS
+   */
+  @Override
+  protected void parseStyleDeclaration(final boolean inSheet) throws CSSException {
+    boolean leadingDash = false;
+    for (; ; ) {
+      switch (current) {
+        case LexicalUnits.EOF:
+          if (inSheet) {
+            throw createCSSParseException("eof");
+          }
+          return;
+        case LexicalUnits.RIGHT_CURLY_BRACE:
+          if (!inSheet) {
+            throw createCSSParseException("eof.expected");
+          }
+          nextIgnoreSpaces();
+          return;
+        case LexicalUnits.SEMI_COLON:
+          nextIgnoreSpaces();
+          continue;
+        case LexicalUnits.MINUS:
+          leadingDash = true;
+          next();
+          break;
+        default:
+          throw createCSSParseException("identifier");
+        case LexicalUnits.IDENTIFIER:
+      }
+
+      final String name = (leadingDash ? "-" : "") + scanner.getStringValue();
+      leadingDash = false;
+
+      if (nextIgnoreSpaces() != LexicalUnits.COLON) {
+        throw createCSSParseException("colon");
+      }
+      nextIgnoreSpaces();
+
+      LexicalUnit exp = null;
+
+      try {
+        exp = parseExpression(false);
+      } catch (final CSSParseException e) {
+        reportError(e);
+      }
+
+      if (exp != null) {
+        boolean important = false;
+        if (current == LexicalUnits.IMPORTANT_SYMBOL) {
+          important = true;
+          nextIgnoreSpaces();
         }
+        documentHandler.property(name, exp, important);
+      }
+    }
+  }
+
+  @Override
+  protected CSSSACMediaList parseMediaList() {
+    CssMediaQueryList mediaList = new CssMediaQueryList();
+
+    mediaList.append(parseMediaQuery());
+    while (hasAnotherMediaQuery()) {
+      nextIgnoreSpaces();
+      mediaList.append(parseMediaQuery());
+    }
+
+    return mediaList;
+  }
+
+  private boolean hasAnotherMediaQuery() {
+    return current == LexicalUnits.COMMA || (current == LexicalUnits.IDENTIFIER && scanner.getStringValue().equals(OR.toString()));
+  }
+
+  protected CssMediaQuery parseMediaQuery() {
+    CssMediaQuery query = new CssMediaQuery();
+    CssMediaType mediaType = null;
+    CssMediaQueryLogicalOperator logicalOperator = null;
+    switch (current) {
+      case LexicalUnits.LEFT_BRACE:
+        mediaType = CssMediaType.IMPLIED_ALL;
+        break;
+      case LexicalUnits.IDENTIFIER:
+        logicalOperator = CssMediaQueryLogicalOperator.parse(scanner.getStringValue());
+        if (logicalOperator != null) {
+          switch (logicalOperator) {
+            case ONLY:
+              parseLogicalOperatorOnly();
+              mediaType = parseMediaType();
+              break;
+            case NOT:
+              mediaType = parseLogicalOperatorNot();
+              break;
+            case AND:
+            case OR:
+            case COMMA:
+              throw createCSSParseException("identifier");
+          }
+        } else {
+          mediaType = parseMediaType();
+        }
+        break;
+      default:
+        throw createCSSParseException("identifier");
+    }
+    query.setMediaType(mediaType);
+    query.setLogicalOperator(logicalOperator);
+
+    if (mediaType == CssMediaType.IMPLIED_ALL) {
+      query.addMediaFeature(parseMediaFeature());
+    }
+
+    while (current == LexicalUnits.IDENTIFIER && CssMediaQueryLogicalOperator.parse(scanner.getStringValue()) == AND) {
+      nextIgnoreSpaces();
+      query.addMediaFeature(parseMediaFeature());
+    }
+    return query;
+  }
+
+  private CssMediaType parseMediaType() {
+    CssMediaType mediaType;
+    mediaType = CssMediaType.parse(scanner.getStringValue());
+    if (mediaType == null) {
+      throw createCSSParseException("identifier");
+    }
+    nextIgnoreSpaces();
+    return mediaType;
+  }
+
+  private CssMediaType parseLogicalOperatorNot() {
+    CssMediaType mediaType;
+    if (nextIgnoreSpaces() == LexicalUnits.IDENTIFIER) {
+      mediaType = parseMediaType();
+    } else {
+      mediaType = CssMediaType.IMPLIED_ALL;
+    }
+    return mediaType;
+  }
+
+  private void parseLogicalOperatorOnly() {
+    if (nextIgnoreSpaces() != LexicalUnits.IDENTIFIER) {
+      throw createCSSParseException("identifier");
+    }
+  }
+
+  protected CssMediaFeature parseMediaFeature() {
+    if (current != LexicalUnits.LEFT_BRACE) {
+      throw createCSSParseException("'(' expected.");
+    }
+    nextIgnoreSpaces();
+    String namePrefix = "";
+    if (current == LexicalUnits.MINUS) {
+      nextIgnoreSpaces();
+      namePrefix = "-";
+    }
+    if (current != LexicalUnits.IDENTIFIER) {
+      throw createCSSParseException("identifier");
+    }
+    String name = namePrefix + scanner.getStringValue();
+    nextIgnoreSpaces();
+    LexicalUnit exp = null;
+    if (current == LexicalUnits.COLON) {
+      nextIgnoreSpaces();
+      exp = parseTerm(null);
+    }
+    if (current != LexicalUnits.RIGHT_BRACE) {
+      throw createCSSParseException("')' expected.");
+    }
+    nextIgnoreSpaces();
+
+    return new CssMediaFeature(name, exp);
+  }
+
+  @Override
+  protected void parseMediaRule() {
+    CSSSACMediaList ml = parseMediaList();
+    try {
+      documentHandler.startMedia(ml);
+
+      if (current != LexicalUnits.LEFT_CURLY_BRACE) {
+        reportError("left.curly.brace");
+      } else {
+        nextIgnoreSpaces();
+
+        loop:
+        for (; ; ) {
+          switch (current) {
+            case LexicalUnits.EOF:
+            case LexicalUnits.RIGHT_CURLY_BRACE:
+              break loop;
+            default:
+              parseRuleSet();
+          }
+        }
+
+        nextIgnoreSpaces();
+      }
+    } finally {
+      documentHandler.endMedia(ml);
     }
+  }
 }


=====================================
src/main/java/org/owasp/validator/css/CssValidator.java
=====================================
@@ -28,8 +28,12 @@
  */
 package org.owasp.validator.css;
 
+import java.text.DecimalFormat;
 import java.util.Iterator;
 import java.util.regex.Pattern;
+import org.apache.batik.css.parser.CSSLexicalUnit;
+import org.owasp.validator.css.media.CssMediaFeature;
+import org.owasp.validator.css.media.CssMediaQuery;
 import org.owasp.validator.html.Policy;
 import org.owasp.validator.html.ScanException;
 import org.owasp.validator.html.model.AntiSamyPattern;
@@ -55,6 +59,8 @@ import org.w3c.css.sac.SimpleSelector;
  */
 public class CssValidator {
 
+  private static final LexicalUnit EMPTYSTRINGLEXICALUNIT = CSSLexicalUnit.createString(LexicalUnit.SAC_STRING_VALUE, "", null);
+
   private final Policy policy;
 
   /**
@@ -199,13 +205,13 @@ public class CssValidator {
             policy.getCommonRegularExpressions("cssIDSelector"),
             policy.getCommonRegularExpressions("cssIDExclusion"));
       case Condition.SAC_PSEUDO_CLASS_CONDITION:
-        // this is a basic psuedo element condition; compare condition
+        // this is a basic pseudo-element condition; compare condition
         // against valid pattern and is not blacklisted by exclusion pattern
 
         return validateCondition(
             (AttributeCondition) condition,
             policy.getCommonRegularExpressions("cssPseudoElementSelector"),
-            policy.getCommonRegularExpressions("cssPsuedoElementExclusion"));
+            policy.getCommonRegularExpressions("cssPseudoElementExclusion"));
       case Condition.SAC_BEGIN_HYPHEN_ATTRIBUTE_CONDITION:
       case Condition.SAC_ONE_OF_ATTRIBUTE_CONDITION:
       case Condition.SAC_ATTRIBUTE_CONDITION:
@@ -344,15 +350,15 @@ public class CssValidator {
         // this is a rgb encoded color
         StringBuffer sb = new StringBuffer("rgb(");
         LexicalUnit param = lu.getParameters();
-        sb.append(param.getIntegerValue()); // R value
+        sb.append(getColorValue(param)); // R value
         sb.append(',');
         param = param.getNextLexicalUnit(); // comma
         param = param.getNextLexicalUnit(); // G value
-        sb.append(param.getIntegerValue());
+        sb.append(getColorValue(param));
         sb.append(',');
         param = param.getNextLexicalUnit(); // comma
         param = param.getNextLexicalUnit(); // B value
-        sb.append(param.getIntegerValue());
+        sb.append(getColorValue(param));
         sb.append(')');
 
         return sb.toString();
@@ -361,10 +367,42 @@ public class CssValidator {
         return "inherit";
       case LexicalUnit.SAC_OPERATOR_COMMA:
         return ",";
+      case LexicalUnit.SAC_OPERATOR_SLASH:
+        return "/";
+      case LexicalUnit.SAC_FUNCTION:
+        StringBuilder builder = new StringBuilder();
+
+        // Append the function name, e.g., "var"
+        builder.append(lu.getFunctionName()).append("(");
+
+        LexicalUnit params = lu.getParameters();
+        while (params != null) {
+          String paramsValue = lexicalValueToString(params);
+          if (paramsValue == null) {
+            return null;
+          }
+          builder.append(paramsValue);
+          params = params.getNextLexicalUnit();
+          if (params != null) {
+            builder.append(", ");
+          }
+        }
+
+        // Check for fallback (some functions like "var" have fallback values)
+        LexicalUnit fallback = lu.getPreviousLexicalUnit();
+        if (fallback != null) {
+          String fallbackValue = lexicalValueToString(fallback);
+          if (fallbackValue == null) {
+            return null;
+          }
+          builder.append(", ").append(fallbackValue);
+        }
+
+        builder.append(")");
+        return builder.toString();
       case LexicalUnit.SAC_ATTR:
       case LexicalUnit.SAC_COUNTER_FUNCTION:
       case LexicalUnit.SAC_COUNTERS_FUNCTION:
-      case LexicalUnit.SAC_FUNCTION:
       case LexicalUnit.SAC_RECT_FUNCTION:
       case LexicalUnit.SAC_SUB_EXPRESSION:
       case LexicalUnit.SAC_UNICODERANGE:
@@ -374,4 +412,59 @@ public class CssValidator {
         return null;
     }
   }
+
+  /**
+   * Returns whether the given {@link CssMediaQuery} is valid
+   *
+   * @param mediaQuery mediaQuery
+   * @return valid mediaQuery?
+   */
+  public boolean isValidMediaQuery(CssMediaQuery mediaQuery) {
+    // check mediaType against allowed media-HTML-Attribute
+    Property mediatype = policy.getPropertyByName("_mediatype");
+    if (mediatype == null) {
+      return false;
+    }
+
+    String mediaTypeString = mediaQuery.getMediaType().toString().toLowerCase();
+    boolean isRegExpAllowed = false;
+    for (Pattern pattern : mediatype.getAllowedRegExp()) {
+      isRegExpAllowed |= pattern.matcher(mediaTypeString).matches();
+    }
+    boolean isValidMediaType = mediatype.getAllowedValues().contains(mediaTypeString) || isRegExpAllowed;
+    if (!isValidMediaType) {
+      return false;
+    }
+
+    for (CssMediaFeature feature : mediaQuery.getMediaFeatures()) {
+      LexicalUnit expression = feature.getExpression();
+      if (expression == null) {
+        expression = EMPTYSTRINGLEXICALUNIT;
+      }
+      if (!isValidMediaFeature(feature.getName(), expression)) {
+        return false;
+      }
+    }
+    return true;
+  }
+
+  private boolean isValidMediaFeature(String name, LexicalUnit lu) {
+    return isValidProperty("_mediafeature_" + name, lu);
+  }
+
+  /**
+   * Returns color value as int.
+   * Maps percentages to values between 0 and 255.
+   * Negative percentages are mapped to 0, values bigger than 100% to 255.
+   *
+   * @param param LexicalUnit
+   * @return color value as int
+   */
+  private static String getColorValue(LexicalUnit param) {
+    if (param.getLexicalUnitType() == LexicalUnit.SAC_PERCENTAGE) {
+      return new DecimalFormat("0.#").format(param.getFloatValue()) + "%";
+    } else {
+      return "" + param.getIntegerValue();
+    }
+  }
 }


=====================================
src/main/java/org/owasp/validator/css/media/CssMediaFeature.java
=====================================
@@ -0,0 +1,28 @@
+package org.owasp.validator.css.media;
+
+import org.w3c.css.sac.LexicalUnit;
+
+public class CssMediaFeature {
+
+    private final String name;
+    private final LexicalUnit expression;
+
+    /**
+     * Constructor.
+     *
+     * @param name Feature-name
+     * @param expression expression, may be null
+     */
+    public CssMediaFeature(String name, LexicalUnit expression) {
+        this.name = name;
+        this.expression = expression;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public LexicalUnit getExpression() {
+        return expression;
+    }
+}


=====================================
src/main/java/org/owasp/validator/css/media/CssMediaQuery.java
=====================================
@@ -0,0 +1,36 @@
+package org.owasp.validator.css.media;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+public class CssMediaQuery {
+
+    private CssMediaQueryLogicalOperator logicalOperator;
+    private CssMediaType mediaType;
+    private final List<CssMediaFeature> mediaFeatures = new ArrayList<>();
+
+    public CssMediaQueryLogicalOperator getLogicalOperator() {
+        return logicalOperator;
+    }
+
+    public void setLogicalOperator(CssMediaQueryLogicalOperator logicalOperator) {
+        this.logicalOperator = logicalOperator;
+    }
+
+    public CssMediaType getMediaType() {
+        return mediaType;
+    }
+
+    public void setMediaType(CssMediaType mediaType) {
+        this.mediaType = mediaType;
+    }
+
+    public void addMediaFeature(CssMediaFeature mediaFeature) {
+        mediaFeatures.add(mediaFeature);
+    }
+
+    public List<CssMediaFeature> getMediaFeatures() {
+        return Collections.unmodifiableList(mediaFeatures);
+    }
+}


=====================================
src/main/java/org/owasp/validator/css/media/CssMediaQueryList.java
=====================================
@@ -0,0 +1,44 @@
+package org.owasp.validator.css.media;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.batik.css.parser.CSSSACMediaList;
+
+public class CssMediaQueryList extends CSSSACMediaList {
+
+    private final List<CssMediaQuery> mediaQueries = new ArrayList<>();
+
+    @Override
+    public int getLength() {
+        return mediaQueries.size();
+    }
+
+    /**
+     * Use {@link CssMediaQueryList#getMediaQueryAt(int)} instead.
+     * {@inheritDoc}
+     */
+    @Override
+    public String item(int index) {
+        CssMediaQuery query = getMediaQueryAt(index);
+        if (query.getMediaFeatures().isEmpty() && query.getLogicalOperator() == null) {
+            return query.getMediaType().toString();
+        } else {
+            throw new UnsupportedOperationException("CSS3 MediaQuery unsupported");
+        }
+    }
+
+    public CssMediaQuery getMediaQueryAt(int index) {
+        return mediaQueries.get(index);
+    }
+
+    public List<CssMediaQuery> getMediaQueries() {
+        return Collections.unmodifiableList(mediaQueries);
+    }
+
+
+    public void append(CssMediaQuery mediaQuery) {
+        mediaQueries.add(mediaQuery);
+    }
+}


=====================================
src/main/java/org/owasp/validator/css/media/CssMediaQueryLogicalOperator.java
=====================================
@@ -0,0 +1,25 @@
+package org.owasp.validator.css.media;
+
+public enum CssMediaQueryLogicalOperator {
+    AND("and"), NOT("not"), ONLY("only"), OR("or"), COMMA(",");
+
+    public final String label;
+
+    CssMediaQueryLogicalOperator(String label) {
+        this.label = label;
+    }
+
+    @Override
+    public String toString() {
+        return label;
+    }
+
+    public static CssMediaQueryLogicalOperator parse(String operator) {
+        for (CssMediaQueryLogicalOperator element : values()) {
+            if (element.label.equalsIgnoreCase(operator)) {
+                return element;
+            }
+        }
+        return null;
+    }
+}


=====================================
src/main/java/org/owasp/validator/css/media/CssMediaType.java
=====================================
@@ -0,0 +1,25 @@
+package org.owasp.validator.css.media;
+
+public enum CssMediaType {
+    ALL("all"), PRINT("print"), SCREEN("screen"), IMPLIED_ALL("");
+
+    public final String label;
+
+    CssMediaType(String label) {
+        this.label = label;
+    }
+
+    @Override
+    public String toString() {
+        return label;
+    }
+
+    public static CssMediaType parse(String mediaType) {
+        for (CssMediaType element : values()) {
+            if (element.toString().equalsIgnoreCase(mediaType)) {
+                return element;
+            }
+        }
+        return null;
+    }
+}


=====================================
src/main/java/org/owasp/validator/html/CleanResults.java
=====================================
@@ -98,6 +98,7 @@ public class CleanResults {
     this(
         startOfScan,
         new Callable<String>() {
+          @Override
           public String call() throws Exception {
             return cleanHTML;
           }


=====================================
src/main/java/org/owasp/validator/html/Policy.java
=====================================
@@ -1070,19 +1070,23 @@ public class Policy {
 
     final NodeList nodes = parent.getElementsByTagName(tagName);
     return new Iterable<Element>() {
+      @Override
       public Iterator<Element> iterator() {
         return new Iterator<Element>() {
           int pos = 0;
           int len = nodes.getLength();
 
+          @Override
           public boolean hasNext() {
             return pos < len;
           }
 
+          @Override
           public Element next() {
             return (Element) nodes.item(pos++);
           }
 
+          @Override
           public void remove() {
             throw new UnsupportedOperationException("Cant remove");
           }


=====================================
src/main/java/org/owasp/validator/html/model/Tag.java
=====================================
@@ -97,6 +97,7 @@ public class Tag {
     Collections.sort(
         values,
         new Comparator<Attribute>() {
+          @Override
           public int compare(Attribute o1, Attribute o2) {
             return o1.getName().compareTo(o2.getName());
           }


=====================================
src/main/java/org/owasp/validator/html/scan/ASHTMLSerializer.java
=====================================
@@ -2,30 +2,164 @@ package org.owasp.validator.html.scan;
 
 import java.io.IOException;
 import java.io.Writer;
+import java.util.Locale;
 import org.apache.xml.serialize.ElementState;
 import org.apache.xml.serialize.HTMLdtd;
 import org.apache.xml.serialize.OutputFormat;
 import org.owasp.validator.html.InternalPolicy;
+import org.owasp.validator.html.TagMatcher;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
 
 @SuppressWarnings("deprecation")
 public class ASHTMLSerializer extends org.apache.xml.serialize.HTMLSerializer {
 
   private static final Logger logger = LoggerFactory.getLogger(ASHTMLSerializer.class);
   private boolean encodeAllPossibleEntities;
+  private final TagMatcher allowedEmptyTags;
+  private final TagMatcher requireClosingTags;
 
   public ASHTMLSerializer(Writer w, OutputFormat format, InternalPolicy policy) {
     super(w, format);
+    this.allowedEmptyTags = policy.getAllowedEmptyTags();
+    this.requireClosingTags = policy.getRequiresClosingTags();
     this.encodeAllPossibleEntities = policy.isEntityEncodeIntlCharacters();
   }
 
+  @Override
   protected String getEntityRef(int charToPrint) {
     if (encodeAllPossibleEntities || Constants.big5CharsToEncode.indexOf(charToPrint) != -1)
       return super.getEntityRef(charToPrint);
     return null;
   }
 
+  /**
+   * Called to serialize a DOM element. Equivalent to calling {@link #startElement}, {@link
+   * #endElement} and serializing everything inbetween, but better optimized.
+   */
+  @Override
+  protected void serializeElement(Element elem) throws IOException {
+    Attr attr;
+    NamedNodeMap attrMap;
+    int i;
+    Node child;
+    ElementState state;
+    boolean preserveSpace;
+    String name;
+    String value;
+    String tagName;
+
+    tagName = elem.getTagName();
+    state = getElementState();
+    if (isDocumentState()) {
+      // If this is the root element handle it differently.
+      // If the first root element in the document, serialize
+      // the document's DOCTYPE. Space preserving defaults
+      // to that of the output format.
+      if (!_started) startDocument(tagName);
+    } else {
+      // For any other element, if first in parent, then
+      // close parent's opening tag and use the parnet's
+      // space preserving.
+      if (state.empty) _printer.printText('>');
+      // Indent this element on a new line if the first
+      // content of the parent element or immediately
+      // following an element.
+      if (_indenting && !state.preserveSpace && (state.empty || state.afterElement))
+        _printer.breakLine();
+    }
+    preserveSpace = state.preserveSpace;
+
+    // Do not change the current element state yet.
+    // This only happens in endElement().
+
+    // XHTML: element names are lower case, DOM will be different
+    _printer.printText('<');
+    _printer.printText(tagName);
+    _printer.indent();
+
+    // Lookup the element's attribute, but only print specified
+    // attributes. (Unspecified attributes are derived from the DTD.
+    // For each attribute print it's name and value as one part,
+    // separated with a space so the element can be broken on
+    // multiple lines.
+    attrMap = elem.getAttributes();
+    if (attrMap != null) {
+      for (i = 0; i < attrMap.getLength(); ++i) {
+        attr = (Attr) attrMap.item(i);
+        name = attr.getName().toLowerCase(Locale.ENGLISH);
+        value = attr.getValue();
+        if (attr.getSpecified()) {
+          _printer.printSpace();
+          // HTML: Empty values print as attribute name, no value.
+          // HTML: URI attributes will print unescaped
+          if (value == null) {
+            value = "";
+          }
+          if (!_format.getPreserveEmptyAttributes() && value.length() == 0)
+            _printer.printText(name);
+          else if (HTMLdtd.isURI(tagName, name)) {
+            _printer.printText(name);
+            _printer.printText("=\"");
+            _printer.printText(escapeURI(value));
+            _printer.printText('"');
+          } else if (HTMLdtd.isBoolean(tagName, name)) _printer.printText(name);
+          else {
+            _printer.printText(name);
+            _printer.printText("=\"");
+            printEscaped(value);
+            _printer.printText('"');
+          }
+        }
+      }
+    }
+    if (HTMLdtd.isPreserveSpace(tagName)) preserveSpace = true;
+
+    // If element has children, or if element is not an empty tag,
+    // serialize an opening tag.
+    if (elem.hasChildNodes() || !HTMLdtd.isEmptyTag(tagName)) {
+      // Enter an element state, and serialize the children
+      // one by one. Finally, end the element.
+      state = enterElementState(null, null, tagName, preserveSpace);
+
+      // Prevents line breaks inside A/TD
+      if (tagName.equalsIgnoreCase("A") || tagName.equalsIgnoreCase("TD")) {
+        state.empty = false;
+        _printer.printText('>');
+      }
+
+      // Handle SCRIPT and STYLE specifically by changing the
+      // state of the current element to CDATA (XHTML) or
+      // unescaped (HTML).
+      if (tagName.equalsIgnoreCase("SCRIPT") || tagName.equalsIgnoreCase("STYLE")) {
+        // HTML: Print contents unescaped
+        state.unescaped = true;
+      }
+      child = elem.getFirstChild();
+      while (child != null) {
+        serializeNode(child);
+        child = child.getNextSibling();
+      }
+      endElementIO(null, null, tagName);
+    } else {
+      _printer.unindent();
+      // XHTML: Close empty tag with ' />' so it's XML and HTML compatible.
+      // HTML: Empty tags are defined as such in DTD no in document.
+      if (!elem.hasChildNodes() && isAllowedEmptyTag(tagName) && !requiresClosingTag(tagName))
+        _printer.printText("/>");
+      else _printer.printText('>');
+      // After element but parent element is no longer empty.
+      state.afterElement = true;
+      state.empty = false;
+      if (isDocumentState()) _printer.flush();
+    }
+  }
+
+  @Override
   public void endElementIO(String namespaceURI, String localName, String rawName)
       throws IOException {
 
@@ -36,17 +170,23 @@ public class ASHTMLSerializer extends org.apache.xml.serialize.HTMLSerializer {
     _printer.unindent();
     state = getElementState();
 
-    if (state.empty) _printer.printText('>');
-    // This element is not empty and that last content was another element, so print a line break
-    // before that last element and this element's closing tag. [keith] Provided this is not an
-    // anchor. HTML: some elements do not print closing tag (e.g. LI)
-    if (rawName == null || !HTMLdtd.isOnlyOpening(rawName) || HTMLdtd.isOptionalClosing(rawName)) {
-      if (_indenting && !state.preserveSpace && state.afterElement) _printer.breakLine();
-      // Must leave CData section first (Illegal in HTML, but still)
-      if (state.inCData) _printer.printText("]]>");
-      _printer.printText("</");
-      _printer.printText(state.rawName);
-      _printer.printText('>');
+    if (state.empty && isAllowedEmptyTag(rawName) && !requiresClosingTag(rawName)) { //
+      _printer.printText("/>");
+    } else {
+      if (state.empty) _printer.printText('>');
+      // This element is not empty and that last content was another element, so print a line break
+      // before that last element and this element's closing tag. [keith] Provided this is not an
+      // anchor. HTML: some elements do not print closing tag (e.g. LI)
+      if (rawName == null
+          || !HTMLdtd.isOnlyOpening(rawName)
+          || HTMLdtd.isOptionalClosing(rawName)) {
+        if (_indenting && !state.preserveSpace && state.afterElement) _printer.breakLine();
+        // Must leave CData section first (Illegal in HTML, but still)
+        if (state.inCData) _printer.printText("]]>");
+        _printer.printText("</");
+        _printer.printText(state.rawName);
+        _printer.printText('>');
+      }
     }
 
     // Leave the element state and update that of the parent (if we're not root) to not empty and
@@ -74,4 +214,12 @@ public class ASHTMLSerializer extends org.apache.xml.serialize.HTMLSerializer {
     }
     return "";
   }
+
+  private boolean requiresClosingTag(String tagName) {
+    return requireClosingTags.matches(tagName);
+  }
+
+  private boolean isAllowedEmptyTag(String tagName) {
+    return "head".equals(tagName) || allowedEmptyTags.matches(tagName);
+  }
 }


=====================================
src/main/java/org/owasp/validator/html/scan/AntiSamyDOMScanner.java
=====================================
@@ -200,6 +200,7 @@ public class AntiSamyDOMScanner extends AbstractAntiSamyScanner {
 
       Callable<String> cleanHtml =
           new Callable<String>() {
+            @Override
             public String call() throws Exception {
               return trimmed;
             }


=====================================
src/main/java/org/owasp/validator/html/scan/AntiSamySAXScanner.java
=====================================
@@ -182,6 +182,7 @@ public class AntiSamySAXScanner extends AbstractAntiSamyScanner {
     final String tainted = html;
     Callable<String> cleanCallable =
         new Callable<String>() {
+          @Override
           public String call() throws Exception {
             return trim(tainted, out.toString());
           }


=====================================
src/main/java/org/owasp/validator/html/scan/MagicSAXFilter.java
=====================================
@@ -98,6 +98,7 @@ public class MagicSAXFilter extends DefaultFilter implements XMLDocumentFilter {
     inCdata = false;
   }
 
+  @Override
   public void characters(XMLString text, Augmentations augs) throws XNIException {
 
     Ops topOp = peekTop();
@@ -121,6 +122,7 @@ public class MagicSAXFilter extends DefaultFilter implements XMLDocumentFilter {
   private static final Pattern conditionalDirectives =
       Pattern.compile("<?!?\\[\\s*(?:end)?if[^]]*\\]>?");
 
+  @Override
   public void comment(XMLString text, Augmentations augs) throws XNIException {
 
     if (preserveComments) {
@@ -134,11 +136,13 @@ public class MagicSAXFilter extends DefaultFilter implements XMLDocumentFilter {
     }
   }
 
+  @Override
   public void doctypeDecl(String root, String publicId, String systemId, Augmentations augs)
       throws XNIException {
     // user supplied doctypes are ignored
   }
 
+  @Override
   public void emptyElement(QName element, XMLAttributes attributes, Augmentations augs)
       throws XNIException {
     this.startElement(element, attributes, augs);
@@ -154,6 +158,7 @@ public class MagicSAXFilter extends DefaultFilter implements XMLDocumentFilter {
     return new XMLString(endTag.toCharArray(), 0, endTag.length());
   }
 
+  @Override
   public void endElement(QName element, Augmentations augs) throws XNIException {
     Ops topOp = peekTop();
     if (Ops.REMOVE == topOp) {
@@ -166,7 +171,7 @@ public class MagicSAXFilter extends DefaultFilter implements XMLDocumentFilter {
       // if encoding this element, insert closing tag: super.characters will encode the string
       // buffer
       operations.pop();
-      super.characters(makeEndTag(element.rawname), augs);
+      super.characters(makeEndTag(element.getRawname()), augs);
     } else if (Ops.CSS == topOp) {
       operations.pop();
       // now scan the CSS.
@@ -224,25 +229,29 @@ public class MagicSAXFilter extends DefaultFilter implements XMLDocumentFilter {
     return cssScanner;
   }
 
+  @Override
   public void processingInstruction(String target, XMLString data, Augmentations augs)
       throws XNIException {
     // processing instructions are being removed
   }
 
+  @Override
   public void startCDATA(Augmentations augs) throws XNIException {
     inCdata = true;
     super.startCDATA(augs);
   }
 
+  @Override
   public void endCDATA(Augmentations augs) throws XNIException {
     inCdata = false;
     super.endCDATA(augs);
   }
 
+  @Override
   public void startElement(QName element, XMLAttributes attributes, Augmentations augs)
       throws XNIException {
     // see if we have a policy for this tag.
-    String tagNameLowerCase = element.localpart.toLowerCase();
+    String tagNameLowerCase = element.getLocalpart().toLowerCase();
     Tag tag = policy.getTagByLowercaseName(tagNameLowerCase);
 
     /*
@@ -275,22 +284,22 @@ public class MagicSAXFilter extends DefaultFilter implements XMLDocumentFilter {
       this.operations.push(Ops.REMOVE);
     } else if ((tag == null && policy.isEncodeUnknownTag())
         || (tag != null && tag.isAction(Policy.ACTION_ENCODE))) {
-      String name = "<" + element.localpart + ">";
+      String name = "<" + element.getLocalpart() + ">";
       super.characters(new XMLString(name.toCharArray(), 0, name.length()), augs);
       this.operations.push(Ops.ENCODE);
     } else if (tag == null) {
       addError(
           ErrorMessageUtil.ERROR_TAG_NOT_IN_POLICY,
-          new Object[] {HTMLEntityEncoder.htmlEntityEncode(element.localpart)});
+          new Object[] {HTMLEntityEncoder.htmlEntityEncode(element.getLocalpart())});
       this.operations.push(Ops.FILTER);
     } else if (tag.isAction(Policy.ACTION_FILTER)) {
       addError(
           ErrorMessageUtil.ERROR_TAG_FILTERED,
-          new Object[] {HTMLEntityEncoder.htmlEntityEncode(element.localpart)});
+          new Object[] {HTMLEntityEncoder.htmlEntityEncode(element.getLocalpart())});
       this.operations.push(Ops.FILTER);
     } else if (tag.isAction("validate")) {
 
-      boolean isStyle = "style".endsWith(element.localpart);
+      boolean isStyle = "style".endsWith(element.getLocalpart());
 
       // validate all attributes, we need to do this now to find out
       // how to deal with the element
@@ -313,14 +322,15 @@ public class MagicSAXFilter extends DefaultFilter implements XMLDocumentFilter {
         if ("style".equalsIgnoreCase(name)) {
           CssScanner styleScanner = makeCssScanner();
           try {
-            CleanResults cr = styleScanner.scanInlineStyle(value, element.localpart, maxInputSize);
+            CleanResults cr =
+                styleScanner.scanInlineStyle(value, element.getLocalpart(), maxInputSize);
             attributes.setValue(i, cr.getCleanHTML());
             validattributes.addAttribute(makeSimpleQname(name), "CDATA", cr.getCleanHTML());
             errorMessages.addAll(cr.getErrorMessages());
           } catch (ScanException e) {
             addError(
                 ErrorMessageUtil.ERROR_CSS_ATTRIBUTE_MALFORMED,
-                new Object[] {element.localpart, HTMLEntityEncoder.htmlEntityEncode(value)});
+                new Object[] {element.getLocalpart(), HTMLEntityEncoder.htmlEntityEncode(value)});
           }
         } else if (attribute != null) {
           // validate the values against the policy
@@ -378,7 +388,7 @@ public class MagicSAXFilter extends DefaultFilter implements XMLDocumentFilter {
           addError(
               ErrorMessageUtil.ERROR_ATTRIBUTE_NOT_IN_POLICY,
               new Object[] {
-                element.localpart,
+                element.getLocalpart(),
                 HTMLEntityEncoder.htmlEntityEncode(name),
                 HTMLEntityEncoder.htmlEntityEncode(value)
               });
@@ -399,7 +409,7 @@ public class MagicSAXFilter extends DefaultFilter implements XMLDocumentFilter {
         this.operations.push(Ops.FILTER);
       } else {
 
-        if ("a".equals(element.localpart)) {
+        if ("a".equals(element.getLocalpart())) {
           boolean addNofollow = isNofollowAnchors;
           boolean addNoopenerAndNoreferrer = false;
 
@@ -447,7 +457,7 @@ public class MagicSAXFilter extends DefaultFilter implements XMLDocumentFilter {
       // no options left, so the tag will be removed
       addError(
           ErrorMessageUtil.ERROR_TAG_DISALLOWED,
-          new Object[] {HTMLEntityEncoder.htmlEntityEncode(element.localpart)});
+          new Object[] {HTMLEntityEncoder.htmlEntityEncode(element.getLocalpart())});
       this.operations.push(Ops.REMOVE);
     }
     // now we know exactly what to do, let's do it


=====================================
src/main/resources/antisamy-anythinggoes.xml
=====================================
@@ -33,7 +33,7 @@
 
         <regexp name="anything" value=".*" />
         <regexp name="numberOrPercent" value="(\d)+(%{0,1})" />
-        <regexp name="paragraph" value="([\p{L}\p{N},'\.\s\-_\(\)]|&[0-9]{2};)*" />
+        <regexp name="paragraph" value="[\p{L}\p{N},'.\s\-_\(\)&;]*" />
         <regexp name="htmlId" value="[a-zA-Z0-9\:\-_\.]+" />
         <regexp name="htmlTitle" value="[\p{L}\p{N}\s\-_',:\[\]!\./\\\(\)&]*" /> <!-- force non-empty with a '+' at the end instead of '*' -->
         <regexp name="htmlClass" value="[a-zA-Z0-9\s,\-_]+" />
@@ -67,8 +67,8 @@
         <!-- This is for pseudo-element selector (ex. foo:pseudo-element { ... } -->
         <regexp name="cssPseudoElementSelector" value=":[a-zA-Z0-9\-_]+" />
 
-        <!-- This is to list out any psuedo-element names that are *not* valid -->
-        <regexp name="cssPsuedoElementExclusion" value="" />
+        <!-- This is to list out any pseudo-element names that are *not* valid -->
+        <regexp name="cssPseudoElementExclusion" value="" />
 
         <!-- This is for attribute selectors (ex. foo[attr=value] { ... } -->
         <regexp name="cssAttributeSelector" value="\[[a-zA-Z0-9\-_]+((=|~=|\|=){1}[a-zA-Z0-9\-_]+){1}\]" />
@@ -97,6 +97,8 @@
         <regexp name="positiveLength" value="((\+)?0|(\+)?([0-9]+(\.[0-9]+)?([eE][+-]?[0-9]+)?)(rem|vw|vh|em|ex|px|in|cm|mm|pt|pc))" />
         <regexp name="percentage" value="(-|\+)?([0-9]+(\.[0-9]+)?)%" />
         <regexp name="positivePercentage" value="(\+)?([0-9]+(\.[0-9]+)?)%" />
+        <regexp name="ratio" value="[0-9]+/[0-9]+"/>
+        <regexp name="resolution" value="((\+)?0|(\+)?([0-9]+(\.[0-9]+)?)(dpi|dpcm|dppx|x))"/>
 
         <regexp name="absolute-size" value="(xx-small|x-small|small|medium|large|x-large|xx-large)" />
         <regexp name="relative-size" value="(larger|smaller)" />
@@ -2612,6 +2614,479 @@
                 <literal value="inherit" />
             </literal-list>
         </property>
+
+        <property name="_mediafeature_any-hover" description="Does any available input mechanism allow the user to hover over elements?">
+            <category-list>
+                <category value="mediafeature"/>
+            </category-list>
+            <literal-list>
+                <literal value="none"/>
+                <literal value="hover"/>
+            </literal-list>
+        </property>
+
+        <property name="_mediatype" description="Describes the general category of a device">
+            <literal-list>
+                <literal value="all"/>
+                <literal value="print"/>
+                <literal value="screen"/>
+                <literal value=""/>
+            </literal-list>
+        </property>
+
+        <property name="_mediafeature_any-pointer" description="Is any available input mechanism a pointing device, and if so, how accurate is it?">
+            <category-list>
+                <category value="mediafeature"/>
+            </category-list>
+            <literal-list>
+                <literal value="none"/>
+                <literal value="coarse"/>
+                <literal value="fine"/>
+            </literal-list>
+        </property>
+
+        <property name="_mediafeature_aspect-ratio" description="Width-to-height aspect ratio of the viewport.">
+            <category-list>
+                <category value="mediafeature"/>
+            </category-list>
+            <regexp-list>
+                <regexp name="ratio"/>
+                <regexp name="number"/>
+            </regexp-list>
+        </property>
+
+        <property name="_mediafeature_color" description="Number of bits per color component of the output device, or zero if the device isn't color.">
+            <category-list>
+                <category value="mediafeature"/>
+            </category-list>
+            <literal-list>
+                <literal value=""/>
+            </literal-list>
+            <regexp-list>
+                <regexp name="integer"/>
+            </regexp-list>
+        </property>
+        <property name="_mediafeature_min-color" description="">
+            <category-list>
+                <category value="mediafeature"/>
+            </category-list>
+            <regexp-list>
+                <regexp name="integer"/>
+            </regexp-list>
+        </property>
+        <property name="_mediafeature_max-color" description="">
+            <category-list>
+                <category value="mediafeature"/>
+            </category-list>
+            <regexp-list>
+                <regexp name="integer"/>
+            </regexp-list>
+        </property>
+
+        <property name="_mediafeature_color-gamut" description="Approximate range of colors that are supported by the user agent and output device.">
+            <category-list>
+                <category value="mediafeature"/>
+            </category-list>
+            <literal-list>
+                <literal value="srgb"/>
+                <literal value="p3"/>
+                <literal value="rec2020"/>
+            </literal-list>
+        </property>
+
+        <property name="_mediafeature_color-index" description="Number of entries in the output device's color lookup table, or zero if the device does not use such a table.">
+            <category-list>
+                <category value="mediafeature"/>
+            </category-list>
+            <literal-list>
+                <literal value=""/>
+            </literal-list>
+            <regexp-list>
+                <regexp name="integer"/>
+            </regexp-list>
+        </property>
+        <property name="_mediafeature_min-color-index" description="">
+            <category-list>
+                <category value="mediafeature"/>
+            </category-list>
+            <regexp-list>
+                <regexp name="integer"/>
+            </regexp-list>
+        </property>
+        <property name="_mediafeature_max-color-index" description="">
+            <category-list>
+                <category value="mediafeature"/>
+            </category-list>
+            <regexp-list>
+                <regexp name="integer"/>
+            </regexp-list>
+        </property>
+
+        <property name="_mediafeature_device-aspect-ratio" description="Width-to-height aspect ratio of the output device. Deprecated in Media Queries Level 4.">
+            <category-list>
+                <category value="mediafeature"/>
+            </category-list>
+            <regexp-list>
+                <regexp name="ratio"/>
+                <regexp name="number"/>
+            </regexp-list>
+        </property>
+
+        <property name="_mediafeature_device-height" description="Height of the rendering surface of the output device. Deprecated in Media Queries Level 4.">
+            <category-list>
+                <category value="mediafeature"/>
+            </category-list>
+            <regexp-list>
+                <regexp name="positiveLength"/>
+            </regexp-list>
+        </property>
+        <property name="_mediafeature_min-device-height" description="">
+            <category-list>
+                <category value="mediafeature"/>
+            </category-list>
+            <regexp-list>
+                <regexp name="positiveLength"/>
+            </regexp-list>
+        </property>
+        <property name="_mediafeature_max-device-height" description="">
+            <category-list>
+                <category value="mediafeature"/>
+            </category-list>
+            <regexp-list>
+                <regexp name="positiveLength"/>
+            </regexp-list>
+        </property>
+
+        <property name="_mediafeature_device-width" description="Width of the rendering surface of the output device. Deprecated in Media Queries Level 4.">
+            <category-list>
+                <category value="mediafeature"/>
+            </category-list>
+            <regexp-list>
+                <regexp name="positiveLength"/>
+            </regexp-list>
+        </property>
+        <property name="_mediafeature_min-device-width" description="">
+            <category-list>
+                <category value="mediafeature"/>
+            </category-list>
+            <regexp-list>
+                <regexp name="positiveLength"/>
+            </regexp-list>
+        </property>
+        <property name="_mediafeature_max-device-width" description="">
+            <category-list>
+                <category value="mediafeature"/>
+            </category-list>
+            <regexp-list>
+                <regexp name="positiveLength"/>
+            </regexp-list>
+        </property>
+
+        <property name="_mediafeature_display-mode" description="The mode in which an application is being displayed: for example, fullscreen or picture-in-picture mode. Added in Media Queries Level 5.">
+            <category-list>
+                <category value="mediafeature"/>
+            </category-list>
+            <literal-list>
+                <literal value="browser"/>
+                <literal value="fullscreen"/>
+                <literal value="minimal-ui"/>
+                <literal value="picture-in-picture"/>
+                <literal value="standalone"/>
+                <literal value="window-controls-overlay"/>
+            </literal-list>
+        </property>
+
+        <property name="_mediafeature_dynamic-range" description="Combination of brightness, contrast ratio, and color depth that are supported by the user agent and the output device. Added in Media Queries Level 5.">
+            <category-list>
+                <category value="mediafeature"/>
+            </category-list>
+            <literal-list>
+                <literal value="standard"/>
+                <literal value="high"/>
+            </literal-list>
+        </property>
+
+        <property name="_mediafeature_forced-colors" description="Detect whether user agent restricts color palette. Added in Media Queries Level 5.">
+            <category-list>
+                <category value="mediafeature"/>
+            </category-list>
+            <literal-list>
+                <literal value="none"/>
+                <literal value="active"/>
+            </literal-list>
+        </property>
+
+        <property name="_mediafeature_grid" description="Does the device use a grid or bitmap screen?">
+            <category-list>
+                <category value="mediafeature"/>
+            </category-list>
+            <literal-list>
+                <literal value=""/>
+                <literal value="-0"/>
+                <literal value="0"/>
+                <literal value="1"/>
+            </literal-list>
+        </property>
+
+        <property name="_mediafeature_height" description="Height of the viewport.">
+            <category-list>
+                <category value="mediafeature"/>
+            </category-list>
+            <regexp-list>
+                <regexp name="positiveLength"/>
+            </regexp-list>
+        </property>
+        <property name="_mediafeature_min-height" description="">
+            <category-list>
+                <category value="mediafeature"/>
+            </category-list>
+            <regexp-list>
+                <regexp name="positiveLength"/>
+            </regexp-list>
+        </property>
+        <property name="_mediafeature_max-height" description="">
+            <category-list>
+                <category value="mediafeature"/>
+            </category-list>
+            <regexp-list>
+                <regexp name="positiveLength"/>
+            </regexp-list>
+        </property>
+
+        <property name="_mediafeature_hover" description="Does the primary input mechanism allow the user to hover over elements?">
+            <category-list>
+                <category value="mediafeature"/>
+            </category-list>
+            <literal-list>
+                <literal value="none"/>
+                <literal value="hover"/>
+            </literal-list>
+        </property>
+
+        <property name="_mediafeature_inverted-colors" description="Is the user agent or underlying OS inverting colors? Added in Media Queries Level 5.">
+            <category-list>
+                <category value="mediafeature"/>
+            </category-list>
+            <literal-list>
+                <literal value="none"/>
+                <literal value="inverted"/>
+            </literal-list>
+        </property>
+
+        <property name="_mediafeature_monochrome" description="Bits per pixel in the output device's monochrome frame buffer, or zero if the device isn't monochrome.">
+            <category-list>
+                <category value="mediafeature"/>
+            </category-list>
+            <literal-list>
+                <literal value=""/>
+            </literal-list>
+            <regexp-list>
+                <regexp name="integer"/>
+            </regexp-list>
+        </property>
+        <property name="_mediafeature_min-monochrome" description="">
+            <category-list>
+                <category value="mediafeature"/>
+            </category-list>
+            <regexp-list>
+                <regexp name="integer"/>
+            </regexp-list>
+        </property>
+        <property name="_mediafeature_max-monochrome" description="">
+            <category-list>
+                <category value="mediafeature"/>
+            </category-list>
+            <regexp-list>
+                <regexp name="integer"/>
+            </regexp-list>
+        </property>
+
+        <property name="_mediafeature_orientation" description="Orientation of the viewport.">
+            <category-list>
+                <category value="mediafeature"/>
+            </category-list>
+            <literal-list>
+                <literal value="portrait"/>
+                <literal value="landscape"/>
+            </literal-list>
+        </property>
+
+        <property name="_mediafeature_overflow-block" description="How does the output device handle content that overflows the viewport along the block axis?">
+            <category-list>
+                <category value="mediafeature"/>
+            </category-list>
+            <literal-list>
+                <literal value="none"/>
+                <literal value="scroll"/>
+                <literal value="optional-paged"/>
+                <literal value="paged"/>
+            </literal-list>
+        </property>
+
+        <property name="_mediafeature_overflow-inline" description="Can content that overflows the viewport along the inline axis be scrolled?">
+            <category-list>
+                <category value="mediafeature"/>
+            </category-list>
+            <literal-list>
+                <literal value="none"/>
+                <literal value="scroll"/>
+            </literal-list>
+        </property>
+
+        <property name="_mediafeature_pointer" description="Is the primary input mechanism a pointing device, and if so, how accurate is it?">
+            <category-list>
+                <category value="mediafeature"/>
+            </category-list>
+            <literal-list>
+                <literal value="none"/>
+                <literal value="coarse"/>
+                <literal value="fine"/>
+            </literal-list>
+        </property>
+
+        <property name="_mediafeature_prefers-color-scheme" description="Detect if the user prefers a light or dark color scheme. Added in Media Queries Level 5.">
+            <category-list>
+                <category value="mediafeature"/>
+            </category-list>
+            <literal-list>
+                <literal value="light"/>
+                <literal value="dark"/>
+            </literal-list>
+        </property>
+
+        <property name="_mediafeature_prefers-contrast" description="Detects if the user has requested the system increase or decrease the amount of contrast between adjacent colors. Added in Media Queries Level 5.">
+            <category-list>
+                <category value="mediafeature"/>
+            </category-list>
+            <literal-list>
+                <literal value="no-preference"/>
+                <literal value="more"/>
+                <literal value="less"/>
+                <literal value="custom"/>
+            </literal-list>
+        </property>
+
+        <property name="_mediafeature_prefers-reduced-motion" description="Detects if the user has requested the web content that consumes less internet traffic.">
+            <category-list>
+                <category value="mediafeature"/>
+            </category-list>
+            <literal-list>
+                <literal value="no-preference"/>
+                <literal value="reduce"/>
+            </literal-list>
+        </property>
+
+        <property name="_mediafeature_prefers-reduced-transparency" description="The user prefers less motion on the page. Added in Media Queries Level 5.">
+            <category-list>
+                <category value="mediafeature"/>
+            </category-list>
+            <literal-list>
+                <literal value="no-preference"/>
+                <literal value="reduce"/>
+            </literal-list>
+        </property>
+
+        <property name="_mediafeature_resolution" description="Detects if a user has enabled a setting on their device to reduce the transparent or translucent layer effects used on the device.">
+            <category-list>
+                <category value="mediafeature"/>
+            </category-list>
+            <regexp-list>
+                <regexp name="resolution"/>
+            </regexp-list>
+        </property>
+        <property name="_mediafeature_min-resolution" description="">
+            <category-list>
+                <category value="mediafeature"/>
+            </category-list>
+            <regexp-list>
+                <regexp name="resolution"/>
+            </regexp-list>
+        </property>
+        <property name="_mediafeature_max-resolution" description="">
+            <category-list>
+                <category value="mediafeature"/>
+            </category-list>
+            <regexp-list>
+                <regexp name="resolution"/>
+            </regexp-list>
+        </property>
+
+        <property name="_mediafeature_scan" description="Whether display output is progressive or interlaced.">
+            <category-list>
+                <category value="mediafeature"/>
+            </category-list>
+            <literal-list>
+                <literal value="interlace"/>
+                <literal value="progressive"/>
+            </literal-list>
+        </property>
+
+        <property name="_mediafeature_scripting" description="Detects whether scripting (i.e. JavaScript) is available. Added in Media Queries Level 5.">
+            <category-list>
+                <category value="mediafeature"/>
+            </category-list>
+            <literal-list>
+                <literal value="none"/>
+                <literal value="initial-only"/>
+                <literal value="enabled"/>
+            </literal-list>
+        </property>
+
+        <property name="_mediafeature_shape" description="Detects the shape of the device to distinguish rectangular and round displays.">
+            <category-list>
+                <category value="mediafeature"/>
+            </category-list>
+            <literal-list>
+                <literal value="rect"/>
+                <literal value="round"/>
+            </literal-list>
+        </property>
+
+        <property name="_mediafeature_update" description="How frequently the output device can modify the appearance of content.">
+            <category-list>
+                <category value="mediafeature"/>
+            </category-list>
+            <literal-list>
+                <literal value="none"/>
+                <literal value="slow"/>
+                <literal value="fast"/>
+            </literal-list>
+        </property>
+
+        <property name="_mediafeature_video-dynamic-range" description="Combination of brightness, contrast ratio, and color depth that are supported by the video plane of user agent and the output device. Added in Media Queries Level 5.">
+            <category-list>
+                <category value="mediafeature"/>
+            </category-list>
+            <literal-list>
+                <literal value="standard"/>
+                <literal value="high"/>
+            </literal-list>
+        </property>
+
+        <property name="_mediafeature_width" description="Width of the viewport including width of scrollbar.">
+            <category-list>
+                <category value="mediafeature"/>
+            </category-list>
+            <regexp-list>
+                <regexp name="positiveLength"/>
+            </regexp-list>
+        </property>
+        <property name="_mediafeature_min-width" description="">
+            <category-list>
+                <category value="mediafeature"/>
+            </category-list>
+            <regexp-list>
+                <regexp name="positiveLength"/>
+            </regexp-list>
+        </property>
+        <property name="_mediafeature_max-width" description="">
+            <category-list>
+                <category value="mediafeature"/>
+            </category-list>
+            <regexp-list>
+                <regexp name="positiveLength"/>
+            </regexp-list>
+        </property>
         <!-- end manual properties -->
     </css-rules>
     <allowed-empty-tags>


=====================================
src/main/resources/antisamy-ebay.xml
=====================================
@@ -31,7 +31,7 @@
 
         <regexp name="anything" value=".*" />
         <regexp name="numberOrPercent" value="(\d)+(%{0,1})" />
-        <regexp name="paragraph" value="([\p{L}\p{N},'\.\s\-_\(\)]|&[0-9]{2};)*" />
+        <regexp name="paragraph" value="[\p{L}\p{N},'.\s\-_\(\)&;]*" />
         <regexp name="htmlId" value="[a-zA-Z0-9\:\-_\.]+" />
         <regexp name="htmlTitle" value="[\p{L}\p{N}\s\-_',:\[\]!\./\\\(\)&]*" /> <!-- force non-empty with a '+' at the end instead of '*' -->
         <regexp name="htmlClass" value="[a-zA-Z0-9\s,\-_]+" />
@@ -65,8 +65,8 @@
         <!-- This is for pseudo-element selector (ex. foo:pseudo-element { ... } -->
         <regexp name="cssPseudoElementSelector" value=":[a-zA-Z0-9\-_]+" />
 
-        <!-- This is to list out any psuedo-element names that are *not* valid -->
-        <regexp name="cssPsuedoElementExclusion" value="" />
+        <!-- This is to list out any pseudo-element names that are *not* valid -->
+        <regexp name="cssPseudoElementExclusion" value="" />
 
         <!-- This is for attribute selectors (ex. foo[attr=value] { ... } -->
         <regexp name="cssAttributeSelector" value="\[[a-zA-Z0-9\-_]+((=|~=|\|=){1}[a-zA-Z0-9\-_]+){1}\]" />


=====================================
src/main/resources/antisamy-myspace.xml
=====================================
@@ -33,7 +33,7 @@
 
         <regexp name="anything" value=".*" />
         <regexp name="numberOrPercent" value="(\d)+(%{0,1})" />
-        <regexp name="paragraph" value="([\p{L}\p{N},'\.\s\-_\(\)]|&[0-9]{2};)*" />
+        <regexp name="paragraph" value="[\p{L}\p{N},'.\s\-_\(\)&;]*" />
         <regexp name="htmlId" value="[a-zA-Z0-9\:\-_\.]+" />
         <regexp name="htmlTitle" value="[\p{L}\p{N}\s\-_',:\[\]!\./\\\(\)&]*" /> <!-- force non-empty with a '+' at the end instead of '*' -->
         <regexp name="htmlClass" value="[a-zA-Z0-9\s,\-_]+" />
@@ -67,8 +67,8 @@
         <!-- This is for pseudo-element selector (ex. foo:pseudo-element { ... } -->
         <regexp name="cssPseudoElementSelector" value=":[a-zA-Z0-9\-_]+" />
 
-        <!-- This is to list out any psuedo-element names that are *not* valid -->
-        <regexp name="cssPsuedoElementExclusion" value="" />
+        <!-- This is to list out any pseudo-element names that are *not* valid -->
+        <regexp name="cssPseudoElementExclusion" value="" />
 
         <!-- This is for attribute selectors (ex. foo[attr=value] { ... } -->
         <regexp name="cssAttributeSelector" value="\[[a-zA-Z0-9\-_]+((=|~=|\|=){1}[a-zA-Z0-9\-_]+){1}\]" />


=====================================
src/main/resources/antisamy.xml
=====================================
@@ -36,7 +36,7 @@
 
         <regexp name="anything" value=".*" />
         <regexp name="numberOrPercent" value="(\d)+(%{0,1})" />
-        <regexp name="paragraph" value="([\p{L}\p{N},'\.\s\-_\(\)]|&[0-9]{2};)*" />
+        <regexp name="paragraph" value="[\p{L}\p{N},'.\s\-_\(\)&;]*" />
         <regexp name="htmlId" value="[a-zA-Z0-9\:\-_\.]+" />
         <regexp name="htmlTitle" value="[\p{L}\p{N}\s\-_',:\[\]!\./\\\(\)&]*" /> <!-- force non-empty with a '+' at the end instead of '*' -->
         <regexp name="htmlClass" value="[a-zA-Z0-9\s,\-_]+" />
@@ -71,8 +71,8 @@
         <!-- This is for pseudo-element selector (ex. foo:pseudo-element { ... } -->
         <regexp name="cssPseudoElementSelector" value=":[a-zA-Z0-9\-_]+" />
 
-        <!-- This is to list out any psuedo-element names that are *not* valid -->
-        <regexp name="cssPsuedoElementExclusion" value="" />
+        <!-- This is to list out any pseudo-element names that are *not* valid -->
+        <regexp name="cssPseudoElementExclusion" value="" />
 
         <!-- This is for attribute selectors (ex. foo[attr=value] { ... } -->
         <regexp name="cssAttributeSelector" value="\[[a-zA-Z0-9\-_]+((=|~=|\|=){1}[a-zA-Z0-9\-_]+){1}\]" />
@@ -109,6 +109,10 @@
         <regexp name="rgbCode"
             value="rgb\(([1]?[0-9]{1,2}|2[0-4][0-9]|25[0-5]),([1]?[0-9]{1,2}|2[0-4][0-9]|25[0-5]),([1]?[0-9]{1,2}|2[0-4][0-9]|25[0-5])\)" />
 
+        <!-- Relative color values between 0%-100% are also allowed -->
+        <regexp name="rgbPercentage"
+                value="rgb\(([0-9][0-9]?|100)\.?\d*%,([0-9][0-9]?|100)\.?\d*%,([0-9][0-9]?|100)\.?\d*%\)" />
+
         <!-- CSS2 Allowed System Color Values -->
         <regexp name="systemColor"
             value="(activeborder|activecaption|appworkspace|background|buttonface|buttonhighlight|buttonshadow|buttontext|captiontext|graytext|highlight|highlighttext|inactiveborder|inactivecaption|inactivecaptiontext|infobackground|infotext|menu|menutext|scrollbar|threeddarkshadow|threedface|threedhighlight|threedlightshadow|threedshadow|window|windowframe|windowtext)" />
@@ -1141,6 +1145,7 @@
                 <regexp name="colorName" />
                 <regexp name="colorCode" />
                 <regexp name="rgbCode" />
+                <regexp name="rgbPercentage" />
                 <regexp name="systemColor" />
             </regexp-list>
         </property>
@@ -1207,6 +1212,7 @@
                 <regexp name="colorName" />
                 <regexp name="colorCode" />
                 <regexp name="rgbCode" />
+                <regexp name="rgbPercentage" />
                 <regexp name="systemColor" />
             </regexp-list>
         </property>
@@ -1221,6 +1227,7 @@
                 <regexp name="colorName" />
                 <regexp name="colorCode" />
                 <regexp name="rgbCode" />
+                <regexp name="rgbPercentage" />
                 <regexp name="systemColor" />
             </regexp-list>
         </property>
@@ -1235,6 +1242,7 @@
                 <regexp name="colorName" />
                 <regexp name="colorCode" />
                 <regexp name="rgbCode" />
+                <regexp name="rgbPercentage" />
                 <regexp name="systemColor" />
             </regexp-list>
         </property>
@@ -1249,6 +1257,7 @@
                 <regexp name="colorName" />
                 <regexp name="colorCode" />
                 <regexp name="rgbCode" />
+                <regexp name="rgbPercentage" />
                 <regexp name="systemColor" />
             </regexp-list>
         </property>
@@ -1263,6 +1272,7 @@
                 <regexp name="colorName" />
                 <regexp name="colorCode" />
                 <regexp name="rgbCode" />
+                <regexp name="rgbPercentage" />
                 <regexp name="systemColor" />
             </regexp-list>
         </property>
@@ -1314,6 +1324,7 @@
                 <regexp name="colorName" />
                 <regexp name="colorCode" />
                 <regexp name="rgbCode" />
+                <regexp name="rgbPercentage" />
                 <regexp name="systemColor" />
             </regexp-list>
         </property>
@@ -1693,6 +1704,7 @@
                 <regexp name="colorName" />
                 <regexp name="colorCode" />
                 <regexp name="rgbCode" />
+                <regexp name="rgbPercentage" />
                 <regexp name="systemColor" />
             </regexp-list>
         </property>
@@ -2348,6 +2360,7 @@
                 <regexp name="colorName" />
                 <regexp name="colorCode" />
                 <regexp name="rgbCode" />
+                <regexp name="rgbPercentage" />
                 <regexp name="systemColor" />
             </regexp-list>
             <shorthand-list>
@@ -2366,6 +2379,7 @@
                 <regexp name="colorName" />
                 <regexp name="colorCode" />
                 <regexp name="rgbCode" />
+                <regexp name="rgbPercentage" />
                 <regexp name="systemColor" />
             </regexp-list>
             <shorthand-list>
@@ -2384,6 +2398,7 @@
                 <regexp name="colorName" />
                 <regexp name="colorCode" />
                 <regexp name="rgbCode" />
+                <regexp name="rgbPercentage" />
                 <regexp name="systemColor" />
             </regexp-list>
             <shorthand-list>
@@ -2402,6 +2417,7 @@
                 <regexp name="colorName" />
                 <regexp name="colorCode" />
                 <regexp name="rgbCode" />
+                <regexp name="rgbPercentage" />
                 <regexp name="systemColor" />
             </regexp-list>
             <shorthand-list>
@@ -2420,6 +2436,7 @@
                 <regexp name="colorName" />
                 <regexp name="colorCode" />
                 <regexp name="rgbCode" />
+                <regexp name="rgbPercentage" />
                 <regexp name="systemColor" />
             </regexp-list>
             <shorthand-list>
@@ -2587,6 +2604,7 @@
                 <regexp name="colorName" />
                 <regexp name="colorCode" />
                 <regexp name="rgbCode" />
+                <regexp name="rgbPercentage" />
                 <regexp name="systemColor" />
                 <regexp name="length" />
             </regexp-list>


=====================================
src/site/site.xml
=====================================
@@ -1,10 +1,7 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project name="${project.name}" xmlns="https://maven.apache.org/DECORATION/1.8.0"
-    xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
-    xsi:schemaLocation="https://maven.apache.org/DECORATION/1.8.0 https://maven.apache.org/xsd/decoration-1.8.0.xsd">
-    <bannerLeft>
-        <src>/images/owasp.png</src>
-        <href>https://owasp.org/www-project-antisamy/</href>
+<site xmlns="http://maven.apache.org/SITE/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://maven.apache.org/SITE/2.0.0 https://maven.apache.org/xsd/site-2.0.0.xsd">
+    <bannerLeft href="https://owasp.org/www-project-antisamy">
+        <image src="images/owasp.png" />
     </bannerLeft>
     <skin>
         <groupId>org.apache.maven.skins</groupId>
@@ -23,5 +20,5 @@
         </links>
         <menu ref="reports" />
     </body>
-</project>
+</site>
 


=====================================
src/test/java/org/owasp/validator/css/CssValidatorTest.java
=====================================
@@ -0,0 +1,102 @@
+package org.owasp.validator.css;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import org.apache.batik.css.parser.CSSLexicalUnit;
+import org.junit.Test;
+import org.w3c.css.sac.LexicalUnit;
+
+public class CssValidatorTest {
+  @Test
+  public void testLexicalValueToStringSacFunction() {
+    CssValidator cssValidator = new CssValidator(null);
+
+    final CSSLexicalUnit param =
+        CSSLexicalUnit.createString(LexicalUnit.SAC_STRING_VALUE, "--ds-text-purple", null);
+    final CSSLexicalUnit varFunc = CSSLexicalUnit.createFunction("var", param, null);
+
+    assertEquals("var(--ds-text-purple)", cssValidator.lexicalValueToString(varFunc));
+
+    final CSSLexicalUnit hslaParam = CSSLexicalUnit.createInteger(100, null);
+    final CSSLexicalUnit hslaParam1 = CSSLexicalUnit.createDimension(98, "%", hslaParam);
+    final CSSLexicalUnit hslaParam2 = CSSLexicalUnit.createDimension(50, "%", hslaParam1);
+    CSSLexicalUnit.createFloat(LexicalUnit.SAC_REAL, 0.3f, hslaParam2);
+
+    final CSSLexicalUnit hslaFunc = CSSLexicalUnit.createFunction("hsla", hslaParam, null);
+    assertEquals("hsla(100, 98.0%, 50.0%, 0.3)", cssValidator.lexicalValueToString(hslaFunc));
+  }
+
+  @Test
+  public void testLexicalValueToStringSacFunctionTwoParams() {
+    CssValidator cssValidator = new CssValidator(null);
+
+    final CSSLexicalUnit param =
+        CSSLexicalUnit.createString(LexicalUnit.SAC_STRING_VALUE, "--ds-text-purple", null);
+    CSSLexicalUnit.createString(LexicalUnit.SAC_STRING_VALUE, "#FFFFFF", param);
+    final CSSLexicalUnit func = CSSLexicalUnit.createFunction("var", param, null);
+
+    assertEquals("var(--ds-text-purple, #FFFFFF)", cssValidator.lexicalValueToString(func));
+  }
+
+  @Test
+  public void testLexicalValueToStringUnsupported() {
+    CssValidator cssValidator = new CssValidator(null);
+    final CSSLexicalUnit param =
+        CSSLexicalUnit.createString(LexicalUnit.SAC_STRING_VALUE, "section", null);
+    final CSSLexicalUnit func =
+        CSSLexicalUnit.createPredefinedFunction(LexicalUnit.SAC_COUNTER_FUNCTION, param, null);
+    assertNull(cssValidator.lexicalValueToString(func));
+  }
+
+  @Test
+  public void testLexicalValueToStringNestedVarsWithFallback() {
+    CssValidator cssValidator = new CssValidator(null);
+
+    // Create fallback first: --ds-text-purple, #FFFFFF
+    final CSSLexicalUnit param =
+        CSSLexicalUnit.createString(LexicalUnit.SAC_STRING_VALUE, "--ds-text-purple", null);
+    final CSSLexicalUnit fallback =
+        CSSLexicalUnit.createString(LexicalUnit.SAC_STRING_VALUE, "#FFFFFF", null);
+
+    // Create first var() function with fallback
+    final CSSLexicalUnit function = CSSLexicalUnit.createFunction("var", param, fallback);
+
+    // Check if the output is as expected for first var()
+    assertEquals("var(--ds-text-purple, #FFFFFF)", cssValidator.lexicalValueToString(function));
+
+    // Create outer variable: --custom-prop
+    final CSSLexicalUnit outerParam =
+        CSSLexicalUnit.createString(LexicalUnit.SAC_STRING_VALUE, "--custom-prop", null);
+
+    // Create outer var() with the first function as fallback
+    final CSSLexicalUnit outerFunction = CSSLexicalUnit.createFunction("var", outerParam, function);
+
+    // Ensure the output is as expected for the nested var() function
+    assertEquals(
+        "var(--custom-prop, var(--ds-text-purple, #FFFFFF))",
+        cssValidator.lexicalValueToString(outerFunction));
+  }
+
+  @Test
+  public void testDefaultPolicyUrlFunction() {
+    CssValidator cssValidator = new CssValidator(null);
+
+    // Test a simple url function
+    final CSSLexicalUnit urlParam =
+        CSSLexicalUnit.createString(LexicalUnit.SAC_STRING_VALUE, "http://example.com", null);
+    final CSSLexicalUnit urlFunc = CSSLexicalUnit.createFunction("url", urlParam, null);
+
+    assertEquals("url(http://example.com)", cssValidator.lexicalValueToString(urlFunc));
+  }
+
+  @Test
+  public void testSacUriWithValidUrl() {
+    CssValidator cssValidator = new CssValidator(null);
+
+    // Test with a valid URL, which should be allowed
+    final CSSLexicalUnit validUrl =
+        CSSLexicalUnit.createString(LexicalUnit.SAC_URI, "https://example.com", null);
+    assertEquals("url(https://example.com)", cssValidator.lexicalValueToString(validUrl));
+  }
+}


=====================================
src/test/java/org/owasp/validator/html/test/AntiSamyTest.java
=====================================
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007-2023, Arshan Dabirsiaghi, Jason Li
+ * Copyright (c) 2007-2024, Arshan Dabirsiaghi, Jason Li
  *
  * All rights reserved.
  *
@@ -34,6 +34,7 @@ import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
@@ -48,7 +49,10 @@ import java.net.URL;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.Locale;
 import java.util.Map;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import org.apache.commons.codec.binary.Base64;
@@ -63,6 +67,8 @@ import org.owasp.validator.html.ScanException;
 import org.owasp.validator.html.model.Attribute;
 import org.owasp.validator.html.model.Property;
 import org.owasp.validator.html.model.Tag;
+import org.owasp.validator.html.scan.Constants;
+import org.w3c.css.sac.CSSParseException;
 
 /**
  * This class tests AntiSamy functionality and the basic policy file which should be immune to XSS
@@ -100,6 +106,7 @@ public class AntiSamyTest {
 
   private AntiSamy as = new AntiSamy();
   private TestPolicy policy = null;
+  private ResourceBundle messages = null;
 
   @Before
   public void setUp() throws Exception {
@@ -111,6 +118,13 @@ public class AntiSamyTest {
     // get Policy instance from a URL.
     URL url = getClass().getResource("/antisamy.xml");
     policy = TestPolicy.getInstance(url);
+    try {
+      messages = ResourceBundle.getBundle("AntiSamy", Locale.getDefault());
+    } catch (MissingResourceException mre) {
+      messages =
+              ResourceBundle.getBundle(
+                      "AntiSamy", new Locale(Constants.DEFAULT_LOCALE_LANG, Constants.DEFAULT_LOCALE_LOC));
+    }
   }
 
   @Test
@@ -868,8 +882,8 @@ public class AntiSamyTest {
     assertFalse(p.matcher(s1).matches());
     assertFalse(p.matcher(s2).matches());
 
-    assertThat(s1, containsString("<hr>"));
-    assertThat(s2, containsString("<hr>"));
+    assertThat(s1, containsString("<hr/>"));
+    assertThat(s2, containsString("<hr/>"));
   }
 
   @Test
@@ -1307,8 +1321,8 @@ public class AntiSamyTest {
     assertTrue(crd.getErrorMessages().size() > 0);
     assertTrue(crs.getErrorMessages().size() > 0);
 
-    assertTrue(crSax.contains("<script") && !crDom.contains("<script"));
-    assertTrue(crDom.contains("<script") && !crDom.contains("<script"));
+    assertThat(crDom, both(not(containsString("script"))).and(not(containsString("alert"))));
+    assertThat(crSax, both(not(containsString("script"))).and(not(containsString("alert"))));
   }
 
   @Test
@@ -1431,7 +1445,7 @@ public class AntiSamyTest {
 
     StringBuilder sb = new StringBuilder();
     sb.append("<html><head><title>foobar</title></head><body>");
-    sb.append("<img src=\"http://foobar.com/pic.gif\"></body></html>");
+    sb.append("<img src=\"http://foobar.com/pic.gif\"/></body></html>");
 
     html = sb.toString();
 
@@ -1572,12 +1586,12 @@ public class AntiSamyTest {
     String input =
         "<object width=\"560\" height=\"340\"><param name=\"movie\" value=\"http://www.youtube.com/v/IyAyd4WnvhU&hl=en&fs=1&\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"allowscriptaccess\" value=\"always\"></param><embed src=\"http://www.youtube.com/v/IyAyd4WnvhU&hl=en&fs=1&\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"560\" height=\"340\"></embed></object>";
     String expectedOutput =
-        "<object height=\"340\" width=\"560\"><param name=\"movie\" value=\"http://www.youtube.com/v/IyAyd4WnvhU&hl=en&fs=1&\"><param name=\"allowFullScreen\" value=\"true\"><param name=\"allowscriptaccess\" value=\"always\"><embed allowfullscreen=\"true\" allowscriptaccess=\"always\" height=\"340\" src=\"http://www.youtube.com/v/IyAyd4WnvhU&hl=en&fs=1&\" type=\"application/x-shockwave-flash\" width=\"560\"></embed></object>";
+        "<object height=\"340\" width=\"560\"><param name=\"movie\" value=\"http://www.youtube.com/v/IyAyd4WnvhU&hl=en&fs=1&\"/><param name=\"allowFullScreen\" value=\"true\"/><param name=\"allowscriptaccess\" value=\"always\"/><embed allowfullscreen=\"true\" allowscriptaccess=\"always\" height=\"340\" src=\"http://www.youtube.com/v/IyAyd4WnvhU&hl=en&fs=1&\" type=\"application/x-shockwave-flash\" width=\"560\"/></object>";
     CleanResults cr = as.scan(input, revised, AntiSamy.DOM);
     assertThat(cr.getCleanHTML(), containsString(expectedOutput));
 
     String saxExpectedOutput =
-        "<object width=\"560\" height=\"340\"><param name=\"movie\" value=\"http://www.youtube.com/v/IyAyd4WnvhU&hl=en&fs=1&\"><param name=\"allowFullScreen\" value=\"true\"><param name=\"allowscriptaccess\" value=\"always\"><embed src=\"http://www.youtube.com/v/IyAyd4WnvhU&hl=en&fs=1&\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"560\" height=\"340\"></embed></object>";
+        "<object width=\"560\" height=\"340\"><param name=\"movie\" value=\"http://www.youtube.com/v/IyAyd4WnvhU&hl=en&fs=1&\"/><param name=\"allowFullScreen\" value=\"true\"/><param name=\"allowscriptaccess\" value=\"always\"/><embed src=\"http://www.youtube.com/v/IyAyd4WnvhU&hl=en&fs=1&\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"560\" height=\"340\"/></object>";
     cr = as.scan(input, revised, AntiSamy.SAX);
     assertThat(cr.getCleanHTML(), equalTo(saxExpectedOutput));
 
@@ -1586,9 +1600,9 @@ public class AntiSamyTest {
     input =
         "<object width=\"560\" height=\"340\"><param name=\"movie\" value=\"http://supermaliciouscode.com/badstuff.swf\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"allowscriptaccess\" value=\"always\"></param><embed src=\"http://www.youtube.com/v/IyAyd4WnvhU&hl=en&fs=1&\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"560\" height=\"340\"></embed></object>";
     expectedOutput =
-        "<object height=\"340\" width=\"560\"><param name=\"allowFullScreen\" value=\"true\"><param name=\"allowscriptaccess\" value=\"always\"><embed allowfullscreen=\"true\" allowscriptaccess=\"always\" height=\"340\" src=\"http://www.youtube.com/v/IyAyd4WnvhU&hl=en&fs=1&\" type=\"application/x-shockwave-flash\" width=\"560\"></embed></object>";
+        "<object height=\"340\" width=\"560\"><param name=\"allowFullScreen\" value=\"true\"/><param name=\"allowscriptaccess\" value=\"always\"/><embed allowfullscreen=\"true\" allowscriptaccess=\"always\" height=\"340\" src=\"http://www.youtube.com/v/IyAyd4WnvhU&hl=en&fs=1&\" type=\"application/x-shockwave-flash\" width=\"560\"/></object>";
     saxExpectedOutput =
-        "<object width=\"560\" height=\"340\"><param name=\"allowFullScreen\" value=\"true\"><param name=\"allowscriptaccess\" value=\"always\"><embed src=\"http://www.youtube.com/v/IyAyd4WnvhU&hl=en&fs=1&\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"560\" height=\"340\"></embed></object>";
+        "<object width=\"560\" height=\"340\"><param name=\"allowFullScreen\" value=\"true\"/><param name=\"allowscriptaccess\" value=\"always\"/><embed src=\"http://www.youtube.com/v/IyAyd4WnvhU&hl=en&fs=1&\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"560\" height=\"340\"/></object>";
     cr = as.scan(input, revised, AntiSamy.DOM);
     assertThat(cr.getCleanHTML(), containsString(expectedOutput));
 
@@ -1600,9 +1614,9 @@ public class AntiSamyTest {
     input =
         "<object width=\"560\" height=\"340\"><param name=\"movie\" value=\"http://www.youtube.com/v/IyAyd4WnvhU&hl=en&fs=1&\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"allowscriptaccess\" value=\"always\"></param><embed src=\"http://hereswhereikeepbadcode.com/ohnoscary.swf\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"560\" height=\"340\"></embed></object>";
     expectedOutput =
-        "<object height=\"340\" width=\"560\"><param name=\"movie\" value=\"http://www.youtube.com/v/IyAyd4WnvhU&hl=en&fs=1&\"><param name=\"allowFullScreen\" value=\"true\"><param name=\"allowscriptaccess\" value=\"always\"></object>";
+        "<object height=\"340\" width=\"560\"><param name=\"movie\" value=\"http://www.youtube.com/v/IyAyd4WnvhU&hl=en&fs=1&\"/><param name=\"allowFullScreen\" value=\"true\"/><param name=\"allowscriptaccess\" value=\"always\"/></object>";
     saxExpectedOutput =
-        "<object width=\"560\" height=\"340\"><param name=\"movie\" value=\"http://www.youtube.com/v/IyAyd4WnvhU&hl=en&fs=1&\"><param name=\"allowFullScreen\" value=\"true\"><param name=\"allowscriptaccess\" value=\"always\"></object>";
+        "<object width=\"560\" height=\"340\"><param name=\"movie\" value=\"http://www.youtube.com/v/IyAyd4WnvhU&hl=en&fs=1&\"/><param name=\"allowFullScreen\" value=\"true\"/><param name=\"allowscriptaccess\" value=\"always\"/></object>";
 
     cr = as.scan(input, revised, AntiSamy.DOM);
     assertThat(cr.getCleanHTML(), containsString(expectedOutput));
@@ -1799,10 +1813,10 @@ public class AntiSamyTest {
     CleanResults results_sax = as.scan(test, policy, AntiSamy.SAX);
     CleanResults results_dom = as.scan(test, policy, AntiSamy.DOM);
 
-    assertEquals(results_sax.getCleanHTML(), results_dom.getCleanHTML());
     assertEquals(
-        "whatever<img src=\"https://ssl.gstatic.com/codesite/ph/images/defaultlogo.png\">",
-        results_dom.getCleanHTML());
+            "whatever<img src=\"https://ssl.gstatic.com/codesite/ph/images/defaultlogo.png\"/>",
+            results_sax.getCleanHTML());
+    assertEquals(results_sax.getCleanHTML(), results_dom.getCleanHTML());
   }
 
   @Test
@@ -1845,7 +1859,7 @@ public class AntiSamyTest {
     Writer writer = new StringWriter();
     as.scan(reader, writer, policy);
     String cleanHtml = writer.toString().trim();
-    assertEquals("whatever" + testImgSrcURL + ">", cleanHtml);
+    assertEquals("whatever" + testImgSrcURL + "/>", cleanHtml);
   }
 
   @Test
@@ -2621,4 +2635,275 @@ public class AntiSamyTest {
           as.scan(payload, revised, AntiSamy.SAX).getCleanHTML(), not(containsString("mxss")));
     }
   }
+
+  @Test
+  public void testRegexStackOverflow() throws ScanException, PolicyException {
+    try {
+      String input =
+          "<img border=\"0\" width=\"320\" height=\"200\" style=\"width:3.368in;height:2.0486in\" id=\"id_123\" src=\"/url/uri\" alt=\"";
+      for (int i = 0; i < 2500; i++) {
+        input += "SampleText ";
+      }
+      input += "!\\\">";
+      as.scan(input, policy, AntiSamy.DOM).getCleanHTML();
+      as.scan(input, policy, AntiSamy.SAX).getCleanHTML();
+    } catch (StackOverflowError e) {
+      fail("Parser should not throw a stack overflow error");
+    }
+  }
+
+  @Test
+  public void testBangCommentsWhenPreservingComments() throws ScanException, PolicyException {
+    // Concern is that when preserving comments, certain endings of comments would be
+    // misinterpreted.
+    TestPolicy revised = policy.cloneWithDirective(Policy.PRESERVE_COMMENTS, "true");
+    assertThat(
+        as.scan("<!--<div/>--!><img src=x onerror=mxss(1)> <li>--></p>", revised, AntiSamy.DOM)
+            .getCleanHTML(),
+        not(containsString("mxss")));
+    assertThat(
+        as.scan("<!--<div/>--!><img src=x onerror=mxss(1)> <li>--></p>", revised, AntiSamy.SAX)
+            .getCleanHTML(),
+        not(containsString("mxss")));
+    assertThat(
+        as.scan(
+                "<!--<div/>--><img src=x onerror=mxss(1)> <li>--></p><input/>",
+                revised,
+                AntiSamy.DOM)
+            .getCleanHTML(),
+        not(containsString("mxss")));
+    assertThat(
+        as.scan(
+                "<!--<div/>--><img src=x onerror=mxss(1)> <li>--></p><input/>",
+                revised,
+                AntiSamy.SAX)
+            .getCleanHTML(),
+        not(containsString("mxss")));
+  }
+
+  @Test
+  public void testGithubIssue453() throws ScanException, PolicyException {
+    String test453 =
+        "<html lang=\"en\">\n"
+            + "<head>\n"
+            + "</head>\n"
+            + "<table>\n"
+            + "<SELECT NAME=\"Lang\">\n"
+            + "<OPTION VALUE=\"da\">Dansk</OPTION>\n"
+            + "<OPTION VALUE=\"en\" selected=selected>English</OPTION>\n"
+            + "</SELECT>\n"
+            + "</table>\n"
+            + "</html>";
+    String cleaned = as.scan(test453, policy, AntiSamy.SAX).getCleanHTML();
+    cleaned = cleaned.replaceAll("\r?\n", "");
+    cleaned = cleaned.replaceAll("\\s\\s+", " ");
+
+    assertThat(
+        cleaned,
+        containsString(
+            "<body> <table> "
+                + "<select name=\"Lang\"> "
+                + "<option value=\"da\">Dansk</option> "));
+
+    cleaned = as.scan(test453, policy, AntiSamy.DOM).getCleanHTML();
+    cleaned = cleaned.replaceAll("\r?\n", "");
+    cleaned = cleaned.replaceAll("\\s\\s+", " ");
+
+    assertThat(
+        cleaned,
+        containsString(
+            "<body> <table> "
+                + "<select name=\"Lang\"> "
+                + "<option value=\"da\">Dansk</option> "));
+  }
+
+  @Test
+  public void testGithubIssue484() throws ScanException, PolicyException {
+    String s = "<p>this is para data</p><br/><p>this is para data 2</p>";
+    CleanResults crDom = as.scan(s, policy, AntiSamy.DOM);
+    CleanResults crSax = as.scan(s, policy, AntiSamy.SAX);
+    String domValue = crDom.getCleanHTML();
+    String saxValue = crSax.getCleanHTML();
+    assertEquals("<p>this is para data</p>\n" + "<br/>\n" + "<p>this is para data 2</p>", domValue);
+    assertEquals("<p>this is para data</p>\n" + "<br/>\n" + "<p>this is para data 2</p>", saxValue);
+  }
+
+  @Test
+  public void testGithubIssue546() throws ScanException, PolicyException {
+    //Given
+    String taintedHtml = "<style>.cl { color: rgb(50%, 20.5%, 100%); }</style>";
+
+    //When
+    CleanResults crDom = as.scan(taintedHtml, policy, AntiSamy.DOM);
+    CleanResults crSax = as.scan(taintedHtml, policy, AntiSamy.SAX);
+
+    //Then
+    String expectedCleanHtml = "<style>*.cl {\n\tcolor: rgb(50%,20.5%,100%);\n}\n</style>";
+    assertEquals(expectedCleanHtml, crDom.getCleanHTML());
+    assertEquals(expectedCleanHtml, crSax.getCleanHTML());
+  }
+
+  @Test
+  public void testGithubIssue546FaultyPercentagesGetFilteredByRegex() throws ScanException, PolicyException {
+    //Given
+    String taintedHtml = "<style>.cl { color: rgb(50%, -20%, 150%); }</style>";
+
+    //When
+    CleanResults crDom = as.scan(taintedHtml, policy, AntiSamy.DOM);
+    CleanResults crSax = as.scan(taintedHtml, policy, AntiSamy.SAX);
+
+    //Then
+    String expectedCleanHtml = "<style>*.cl {\n}\n</style>";
+    assertEquals(expectedCleanHtml, crDom.getCleanHTML());
+    assertEquals(expectedCleanHtml, crSax.getCleanHTML());
+  }
+
+  @Test
+  public void testGithubIssue552() throws ScanException, PolicyException {
+    Pattern positiveLength = Pattern.compile("((\\+)?0|(\\+)?([0-9]+(\\.[0-9]+)?([eE][+-]?[0-9]+)?)(rem|vw|vh|em|ex|px|in|cm|mm|pt|pc))");
+    Pattern integer = Pattern.compile("([-+])?[0-9]+");
+    Property mediaType = new Property("_mediatype",
+                                      Collections.emptyList(),
+                                      Arrays.asList("", "all", "print", "screen"),
+                                      Collections.emptyList(),
+                                      "",
+                                      "remove");
+    Property minWidth = new Property("_mediafeature_min-width",
+                                     Collections.singletonList(positiveLength),
+                                     Collections.emptyList(),
+                                     Collections.emptyList(),
+                                     "",
+                                     "remove");
+    Property maxWidth = new Property("_mediafeature_max-width",
+                                     Collections.singletonList(positiveLength),
+                                     Collections.emptyList(),
+                                     Collections.emptyList(),
+                                     "",
+                                     "remove");
+    Property color = new Property("_mediafeature_color",
+                                  Collections.singletonList(integer),
+                                  Collections.singletonList(""),
+                                  Collections.emptyList(),
+                                  "",
+                                  "remove");
+    Property orientation = new Property("_mediafeature_orientation",
+                                        Collections.emptyList(),
+                                        Arrays.asList("portrait", "landscape"),
+                                        Collections.emptyList(),
+                                        "",
+                                        "remove");
+    Property grid = new Property("_mediafeature_grid",
+                                 Collections.emptyList(),
+                                 Arrays.asList("", "-1", "-0", "0", "1"),
+                                 Collections.emptyList(),
+                                 "",
+                                 "remove");
+    Property monochrome = new Property("_mediafeature_monochrome",
+                                       Collections.singletonList(integer),
+                                       Collections.singletonList(""),
+                                       Collections.emptyList(),
+                                       "",
+                                       "remove");
+
+    checkStyleTag("@media screen {}",
+                  "@media screen {\n}\n",
+                  policy.addCssProperty(mediaType));
+
+    checkStyleTag("@media screen,print {}",
+                  "@media screen, print {\n}\n",
+                  policy.addCssProperty(mediaType));
+
+    checkStyleTag("@media only screen and (max-width: 639px) and (min-width: 300px) {}",
+                  "@media only screen and (max-width: 639.0px) and (min-width: 300.0px) {\n}\n",
+                  policy.addCssProperty(mediaType).addCssProperty(minWidth).addCssProperty(maxWidth));
+
+    checkStyleTag("@media not screen, screen and (color), print and (orientation: portrait) {}",
+                  "@media not screen, screen and (color), print and (orientation: portrait) {\n}\n",
+                  policy.addCssProperty(mediaType).addCssProperty(color).addCssProperty(orientation));
+
+    checkStyleTag("@media not screen, print and (orientation: doesNotExist), all {}",
+                  "@media not screen, all {\n}\n",
+                  policy.addCssProperty(mediaType).addCssProperty(orientation));
+
+    checkStyleTag("@media (min-width: 500.0px) {}",
+                  "@media (min-width: 500.0px) {\n}\n",
+                  policy.addCssProperty(mediaType).addCssProperty(minWidth));
+
+    checkStyleTag("@media (grid) {}",
+                  "@media (grid) {\n}\n",
+                  policy.addCssProperty(mediaType).addCssProperty(grid));
+
+    checkStyleTag("@media (monochrome) {}",
+                  "@media (monochrome) {\n}\n",
+                  policy.addCssProperty(mediaType).addCssProperty(monochrome));
+
+    checkStyleTag("@media (monochrome: 2) {}",
+                  "@media (monochrome: 2) {\n}\n",
+                  policy.addCssProperty(mediaType).addCssProperty(monochrome));
+
+    checkStyleTag("@media screen and (max-width: 639px) or only print {}",
+                  "@media screen and (max-width: 639.0px), only print {\n}\n",
+                  policy.addCssProperty(mediaType).addCssProperty(maxWidth));
+
+    checkStyleTag("@media print or (max-width: 639px) or only print {}",
+                  "@media print, (max-width: 639.0px), only print {\n}\n",
+                  policy.addCssProperty(mediaType).addCssProperty(maxWidth));
+
+    checkStyleTag("@media print or not (max-width: 639px), not print {}",
+                  "@media print, not (max-width: 639.0px), not print {\n}\n",
+                  policy.addCssProperty(mediaType).addCssProperty(maxWidth));
+
+    checkStyleTag("@media only print or not (max-width: 639px) and (min-width: 500px), not print {}",
+                  "@media only print, not (max-width: 639.0px) and (min-width: 500.0px), not print {\n}\n",
+                  policy.addCssProperty(mediaType).addCssProperty(maxWidth).addCssProperty(minWidth));
+
+    checkStyleTag("@media only print or not (max-width: 639px) and (min-width: 500px), not screen {}",
+                  "@media only print, not screen {\n}\n",
+                  policy.addCssProperty(mediaType).addCssProperty(maxWidth));
+
+    checkStyleTag("@media screen {*{color: red;notAllowed: nope}}",
+                  "@media screen {\n* {\n\tcolor: red;\n}\n}\n",
+                  policy.addCssProperty(mediaType));
+
+    assertThrows(CSSParseException.class, () -> checkStyleTag("@media notValid screen {}", "", policy));
+    assertThrows(CSSParseException.class, () -> checkStyleTag("@media doesNotExist {}", "", policy));
+  }
+
+  private void checkStyleTag(String input, String expected, Policy policy) throws ScanException, PolicyException {
+    //Given
+    String taintedHtml = "<style>" + input + "</style>";
+    String expectedCleanHtml = "<style>" + expected + "</style>";
+
+    //When
+    CleanResults crDom = as.scan(taintedHtml, policy, AntiSamy.DOM);
+    CleanResults crSax = as.scan(taintedHtml, policy, AntiSamy.SAX);
+
+    //Then
+    assertEquals(expectedCleanHtml, crDom.getCleanHTML());
+    assertEquals(expectedCleanHtml, crSax.getCleanHTML());
+  }
+
+  @Test
+  public void testGithubIssue554() throws ScanException, PolicyException {
+    checkInlineStyle("font: bold italic large Palatino, serif", "font: bold italic large Palatino , serif;");
+    checkInlineStyle("font: 12pt/14pt sans-serif", "font: 12.0pt / 14.0pt sans-serif;");
+    checkInlineStyle("font: 12.0pt / 14.0pt sans-serif;", "font: 12.0pt / 14.0pt sans-serif;");
+    checkInlineStyle("font: 12.25pt sans-serif;", "font: 12.25pt sans-serif;");
+    checkInlineStyle("font: 14px/20px Tahoma, Geneva, Arial, Verdana, sans-serif",
+                     "font: 14.0px / 20.0px Tahoma , Geneva , Arial , Verdana , sans-serif;");
+  }
+
+  private void checkInlineStyle(String inline, String expected) throws ScanException, PolicyException {
+    //Given
+    String taintedHtml = "<html><head/><body><p style=\"" + inline + "\">test</p></body></html>";
+    String expectedCleanHtml = "<html>\n  <head/>\n  <body>\n    <p style=\"" + expected + "\">test</p>\n  </body>\n</html>";
+
+    //When
+    CleanResults crDom = as.scan(taintedHtml, policy, AntiSamy.DOM);
+    CleanResults crSax = as.scan(taintedHtml, policy, AntiSamy.SAX);
+
+    //Then
+    assertEquals(expectedCleanHtml, crDom.getCleanHTML());
+    assertEquals(expectedCleanHtml, crSax.getCleanHTML());
+  }
 }


=====================================
src/test/java/org/owasp/validator/html/test/LiteralTest.java
=====================================
@@ -43,6 +43,7 @@ public class LiteralTest extends TestCase {
 
   private Policy policy = null;
 
+  @Override
   protected void setUp() throws Exception {
 
     /*


=====================================
src/test/java/org/owasp/validator/html/test/TestPolicy.java
=====================================
@@ -74,6 +74,7 @@ public class TestPolicy extends InternalPolicy {
     return new TestPolicy(getParseContext(getTopLevelElement(url), url));
   }
 
+  @Override
   public TestPolicy cloneWithDirective(String name, String value) {
     Map<String, String> directives = new HashMap<String, String>(this.directives);
     directives.put(name, value);



View it on GitLab: https://salsa.debian.org/java-team/libowasp-antisamy-java/-/compare/b87547970ab8eaf236c9a44a85a9aacc4f1f77c0...f5997fbfb9c95b75a784d82d7495c14d5357f4ee

-- 
View it on GitLab: https://salsa.debian.org/java-team/libowasp-antisamy-java/-/compare/b87547970ab8eaf236c9a44a85a9aacc4f1f77c0...f5997fbfb9c95b75a784d82d7495c14d5357f4ee
You're receiving this email because of your account on salsa.debian.org. Manage all notifications: https://salsa.debian.org/-/profile/notifications | Help: https://salsa.debian.org/help


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-java-commits/attachments/20261027/bcb39eee/attachment.htm>


More information about the pkg-java-commits mailing list