This is an automated email from the ASF dual-hosted git repository.
tballison pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tika.git
The following commit(s) were added to refs/heads/main by this push:
new a8719b45b5 Clarify html handler and tika's xhtml dialect (#3164)
a8719b45b5 is described below
commit a8719b45b54b8ccbbe6499f8809b020360dcb5e3
Author: Tim Allison <[email protected]>
AuthorDate: Mon Sep 14 13:32:40 2026 -0400
Clarify html handler and tika's xhtml dialect (#3164)
---
.../org/apache/tika/parser/html/HtmlHandler.java | 10 +++++-----
.../org/apache/tika/parser/html/HtmlMapper.java | 21 +++++++++++----------
2 files changed, 16 insertions(+), 15 deletions(-)
diff --git
a/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-html-module/src/main/java/org/apache/tika/parser/html/HtmlHandler.java
b/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-html-module/src/main/java/org/apache/tika/parser/html/HtmlHandler.java
index 759ea69984..61c895733c 100644
---
a/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-html-module/src/main/java/org/apache/tika/parser/html/HtmlHandler.java
+++
b/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-html-module/src/main/java/org/apache/tika/parser/html/HtmlHandler.java
@@ -150,11 +150,11 @@ class HtmlHandler extends TextContentHandler {
metadata.add(HTML.PREFIX_HTML_META +
atts.getValue("property"), atts.getValue("content"));
}
} else if ("BASE".equals(name) && atts.getValue("href") != null) {
- startElementWithSafeAttributes("base", atts);
+ startElementWithMappedAttributes("base", atts);
xhtml.endElement("base");
metadata.set(HttpHeaders.CONTENT_LOCATION,
resolve(atts.getValue("href")));
} else if ("LINK".equals(name)) {
- startElementWithSafeAttributes("link", atts);
+ startElementWithMappedAttributes("link", atts);
xhtml.endElement("link");
} else if ("SCRIPT".equals(name)) {
scriptAtts = atts;
@@ -164,7 +164,7 @@ class HtmlHandler extends TextContentHandler {
if (bodyLevel > 0 && discardLevel == 0) {
String safe = mapper.mapSafeElement(name);
if (safe != null) {
- startElementWithSafeAttributes(safe, atts);
+ startElementWithMappedAttributes(safe, atts);
}
}
@@ -237,7 +237,7 @@ class HtmlHandler extends TextContentHandler {
}
}
- private void startElementWithSafeAttributes(String name, Attributes atts)
throws SAXException {
+ private void startElementWithMappedAttributes(String name, Attributes
atts) throws SAXException {
if (atts.getLength() == 0) {
xhtml.startElement(name);
return;
@@ -300,7 +300,7 @@ class HtmlHandler extends TextContentHandler {
scriptLevel--;
if (scriptLevel == 0) {
if (scriptAtts.getLength() > 0) {
- startElementWithSafeAttributes("script", scriptAtts);
+ startElementWithMappedAttributes("script", scriptAtts);
xhtml.endElement("script");
}
scriptAtts = EMPTY_ATTS;
diff --git
a/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-html-module/src/main/java/org/apache/tika/parser/html/HtmlMapper.java
b/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-html-module/src/main/java/org/apache/tika/parser/html/HtmlMapper.java
index 1ca74345e9..15a965bc4a 100644
---
a/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-html-module/src/main/java/org/apache/tika/parser/html/HtmlMapper.java
+++
b/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-html-module/src/main/java/org/apache/tika/parser/html/HtmlMapper.java
@@ -28,16 +28,17 @@ package org.apache.tika.parser.html;
public interface HtmlMapper {
/**
- * Maps "safe" HTML element names to semantic XHTML equivalents. If the
- * given element is unknown or deemed unsafe for inclusion in the parse
- * output, then this method returns <code>null</code> and the element
- * will be ignored but the content inside it is still processed. See
+ * Maps HTML element names to Tika's XHTML dialect. If the given element
+ * is not part of that dialect, this method returns <code>null</code> and
+ * the element is dropped but the content inside it is still processed.
+ * "Safe" here means valid in the output dialect; this is not a browser
+ * sanitizer, and attribute values are passed through unchanged. See
* the {@link #isDiscardElement(String)} method for a way to discard
* the entire contents of an element.
*
* @param name HTML element name (upper case)
* @return XHTML element name (lower case), or
- * <code>null</code> if the element is unsafe
+ * <code>null</code> if the element is not in the output dialect
*/
String mapSafeElement(String name);
@@ -53,16 +54,16 @@ public interface HtmlMapper {
/**
- * Maps "safe" HTML attribute names to semantic XHTML equivalents. If the
- * given attribute is unknown or deemed unsafe for inclusion in the parse
- * output, then this method returns <code>null</code> and the attribute
- * will be ignored. This method assumes that the element name
+ * Maps HTML attribute names to Tika's XHTML dialect. If the given
+ * attribute is not part of that dialect for this element, this method
+ * returns <code>null</code>, and the attribute is dropped. Attribute
+ * values are not inspected. This method assumes that the element name
* is valid and normalised.
*
* @param elementName HTML element name (lower case)
* @param attributeName HTML attribute name (lower case)
* @return XHTML attribute name (lower case), or
- * <code>null</code> if the element is unsafe
+ * <code>null</code> if the attribute is not in the output dialect
*/
String mapSafeAttribute(String elementName, String attributeName);