-
Notifications
You must be signed in to change notification settings - Fork 405
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: parse boolean/enumerated HTML attributes as case-insensitive
- add an `HTMUtils` facility to get whether an HTML attribute has a case-insensitive value (boolean and enumerated attributes) - pre-process case-insensitive HTML attributes to lower-case their value - refactor the pre-processing attribute logic for more clarity - add a test Fix #941
- Loading branch information
Showing
6 changed files
with
154 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package com.adobe.epubcheck.xml; | ||
|
||
import com.google.common.base.Preconditions; | ||
|
||
/** | ||
* Utilities for HTML-specific logic. | ||
* | ||
*/ | ||
public class HTMLUtils | ||
{ | ||
/** | ||
* Returns whether an attribute is defined as having a case-insensitive value in | ||
* HTML. This is notably the case of boolean attributes and enumerated | ||
* attributes. | ||
* | ||
* @param name | ||
* the name of an attribute defined in the HTML specification | ||
* @return <code>true</code> iff the attribute value is case-insensitive | ||
*/ | ||
public static boolean isCaseInsensitiveAttribute(String name) | ||
{ | ||
switch (Preconditions.checkNotNull(name)) | ||
{ | ||
case "align": | ||
case "allowfullscreen": | ||
case "allowpaymentrequest": | ||
case "allowusermedia": | ||
case "async": | ||
case "autocapitalize": | ||
case "autocomplete": | ||
case "autofocus": | ||
case "autoplay": | ||
case "checked": | ||
case "contenteditable": | ||
case "controls": | ||
case "crossorigin": | ||
case "default": | ||
case "defer": | ||
case "dir": | ||
case "disabled": | ||
case "draggable": | ||
case "formnovalidate": | ||
case "hidden": | ||
case "http-equiv": | ||
case "ismap": | ||
case "itemscope": | ||
case "kind": | ||
case "loop": | ||
case "multiple": | ||
case "muted": | ||
case "nomodule": | ||
case "novalidate": | ||
case "open": | ||
case "playsinline": | ||
case "preload": | ||
case "readonly": | ||
case "required": | ||
case "reversed": | ||
case "scope": | ||
case "selected": | ||
case "shape": | ||
case "sizes": | ||
case "spellcheck": | ||
case "step": | ||
case "translate": | ||
case "type": | ||
case "typemustmatch": | ||
case "valign": | ||
case "value": | ||
case "wrap": | ||
return true; | ||
default: | ||
return false; | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/test/resources/30/single/xhtml/valid/attrs-case-insensitive.xhtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!DOCTYPE html> | ||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en"> | ||
<head> | ||
<title>Test</title> | ||
<meta charset="UTF-8"/> | ||
</head> | ||
<body> | ||
<h1>Test</h1> | ||
<div hidden="HIDDEN"></div> | ||
</body> | ||
</html> |
11 changes: 11 additions & 0 deletions
11
src/test/resources/30/single/xhtml/valid/attrs-custom-ns.xhtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!DOCTYPE html> | ||
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:foo="https://example.org" lang="en"> | ||
<head> | ||
<title>Test</title> | ||
<meta charset="UTF-8" /> | ||
</head> | ||
<body> | ||
<h1>Test</h1> | ||
<p foo:bar1="baz" foo:bar2="baz" foo:bar3="baz">custom attribute!</p> | ||
</body> | ||
</html> |
9 changes: 0 additions & 9 deletions
9
src/test/resources/30/single/xhtml/valid/custom-ns-attrs.xhtml
This file was deleted.
Oops, something went wrong.