Bug 1842199 - Add nonce attribute to HTML parser. r=hsivonen

Differential Revision: https://phabricator.services.mozilla.com/D182777
This commit is contained in:
Tom Schuster 2023-07-10 12:48:23 +00:00
parent 0573213f18
commit 36bbfb0e0c
5 changed files with 1331 additions and 1263 deletions

File diff suppressed because it is too large Load Diff

View File

@ -35,6 +35,8 @@
package nu.validator.htmlparser.impl; package nu.validator.htmlparser.impl;
import java.util.HashMap;
import org.xml.sax.ErrorHandler; import org.xml.sax.ErrorHandler;
import org.xml.sax.Locator; import org.xml.sax.Locator;
import org.xml.sax.ext.Locator2; import org.xml.sax.ext.Locator2;
@ -686,6 +688,15 @@ public class Tokenizer implements Locator, Locator2 {
return this.errorHandler; return this.errorHandler;
} }
/**
* Gets the errorProfile.
*
* @param errorProfile
*/
public HashMap getErrorProfile() {
return null;
}
/** /**
* Sets the commentPolicy. * Sets the commentPolicy.
* *

View File

@ -1458,10 +1458,12 @@ public abstract class TreeBuilder<T> implements TokenHandler,
flushCharacters(); flushCharacters();
// [NOCPP[ // [NOCPP[
boolean wasSelfClosing = selfClosing;
boolean voidElement = false;
if (errorHandler != null) { if (errorHandler != null) {
// ID uniqueness // ID uniqueness
@IdType String id = attributes.getId(); @IdType String id = attributes.getId();
if (id != null) { if (id != null && !isTemplateContents()) {
LocatorImpl oldLoc = idLocations.get(id); LocatorImpl oldLoc = idLocations.get(id);
if (oldLoc != null) { if (oldLoc != null) {
err("Duplicate ID \u201C" + id + "\u201D."); err("Duplicate ID \u201C" + id + "\u201D.");
@ -1580,6 +1582,9 @@ public abstract class TreeBuilder<T> implements TokenHandler,
elementName, elementName,
attributes); attributes);
selfClosing = false; selfClosing = false;
// [NOCPP[
voidElement = true;
// ]NOCPP]
attributes = null; // CPP attributes = null; // CPP
break starttagloop; break starttagloop;
case TITLE: case TITLE:
@ -1592,6 +1597,9 @@ public abstract class TreeBuilder<T> implements TokenHandler,
elementName, elementName,
attributes); attributes);
selfClosing = false; selfClosing = false;
// [NOCPP[
voidElement = true;
// ]NOCPP]
attributes = null; // CPP attributes = null; // CPP
break starttagloop; break starttagloop;
case SCRIPT: case SCRIPT:
@ -1778,6 +1786,9 @@ public abstract class TreeBuilder<T> implements TokenHandler,
attributes, attributes,
formPointer); formPointer);
selfClosing = false; selfClosing = false;
// [NOCPP[
voidElement = true;
// ]NOCPP]
attributes = null; // CPP attributes = null; // CPP
break starttagloop; break starttagloop;
case FORM: case FORM:
@ -2124,6 +2135,9 @@ public abstract class TreeBuilder<T> implements TokenHandler,
elementName, elementName,
attributes); attributes);
selfClosing = false; selfClosing = false;
// [NOCPP[
voidElement = true;
// ]NOCPP]
attributes = null; // CPP attributes = null; // CPP
break starttagloop; break starttagloop;
case HR: case HR:
@ -2132,6 +2146,9 @@ public abstract class TreeBuilder<T> implements TokenHandler,
elementName, elementName,
attributes); attributes);
selfClosing = false; selfClosing = false;
// [NOCPP[
voidElement = true;
// ]NOCPP]
attributes = null; // CPP attributes = null; // CPP
break starttagloop; break starttagloop;
case IMAGE: case IMAGE:
@ -2145,6 +2162,9 @@ public abstract class TreeBuilder<T> implements TokenHandler,
elementName, attributes, elementName, attributes,
formPointer); formPointer);
selfClosing = false; selfClosing = false;
// [NOCPP[
voidElement = true;
// ]NOCPP]
attributes = null; // CPP attributes = null; // CPP
break starttagloop; break starttagloop;
case TEXTAREA: case TEXTAREA:
@ -2324,6 +2344,9 @@ public abstract class TreeBuilder<T> implements TokenHandler,
elementName, elementName,
attributes); attributes);
selfClosing = false; selfClosing = false;
// [NOCPP[
voidElement = true;
// ]NOCPP]
attributes = null; // CPP attributes = null; // CPP
break starttagloop; break starttagloop;
case META: case META:
@ -2391,6 +2414,9 @@ public abstract class TreeBuilder<T> implements TokenHandler,
elementName, elementName,
attributes); attributes);
selfClosing = false; selfClosing = false;
// [NOCPP[
voidElement = true;
// ]NOCPP]
attributes = null; // CPP attributes = null; // CPP
break starttagloop; break starttagloop;
case META: case META:
@ -2399,6 +2425,9 @@ public abstract class TreeBuilder<T> implements TokenHandler,
elementName, elementName,
attributes); attributes);
selfClosing = false; selfClosing = false;
// [NOCPP[
voidElement = true;
// ]NOCPP]
attributes = null; // CPP attributes = null; // CPP
break starttagloop; break starttagloop;
case STYLE: case STYLE:
@ -2438,6 +2467,9 @@ public abstract class TreeBuilder<T> implements TokenHandler,
elementName, elementName,
attributes); attributes);
selfClosing = false; selfClosing = false;
// [NOCPP[
voidElement = true;
// ]NOCPP]
attributes = null; // CPP attributes = null; // CPP
break starttagloop; break starttagloop;
case TEMPLATE: case TEMPLATE:
@ -2572,6 +2604,9 @@ public abstract class TreeBuilder<T> implements TokenHandler,
elementName, elementName,
attributes); attributes);
selfClosing = false; selfClosing = false;
// [NOCPP[
voidElement = true;
// ]NOCPP]
attributes = null; // CPP attributes = null; // CPP
break starttagloop; break starttagloop;
default: default:
@ -2745,6 +2780,9 @@ public abstract class TreeBuilder<T> implements TokenHandler,
elementName, elementName,
attributes); attributes);
selfClosing = false; selfClosing = false;
// [NOCPP[
voidElement = true;
// ]NOCPP]
pop(); // head pop(); // head
attributes = null; // CPP attributes = null; // CPP
break starttagloop; break starttagloop;
@ -2756,6 +2794,9 @@ public abstract class TreeBuilder<T> implements TokenHandler,
elementName, elementName,
attributes); attributes);
selfClosing = false; selfClosing = false;
// [NOCPP[
voidElement = true;
// ]NOCPP]
pop(); // head pop(); // head
attributes = null; // CPP attributes = null; // CPP
break starttagloop; break starttagloop;
@ -2844,6 +2885,13 @@ public abstract class TreeBuilder<T> implements TokenHandler,
} }
if (selfClosing) { if (selfClosing) {
errSelfClosing(); errSelfClosing();
// [NOCPP[
} else if (wasSelfClosing && voidElement
&& tokenizer.getErrorProfile() != null
&& tokenizer.getErrorProfile().get("html-strict") != null) {
warn("Trailing slash on void elements has no effect and interacts"
+ " badly with unquoted attribute values.");
// ]NOCPP]
} }
// CPPONLY: if (mBuilder == null && attributes != HtmlAttributes.EMPTY_ATTRIBUTES) { // CPPONLY: if (mBuilder == null && attributes != HtmlAttributes.EMPTY_ATTRIBUTES) {
// CPPONLY: Portability.delete(attributes); // CPPONLY: Portability.delete(attributes);

File diff suppressed because it is too large Load Diff

View File

@ -267,6 +267,7 @@ class nsHtml5AttributeName {
static nsHtml5AttributeName* ATTR_CALCMODE; static nsHtml5AttributeName* ATTR_CALCMODE;
static nsHtml5AttributeName* ATTR_CHECKED; static nsHtml5AttributeName* ATTR_CHECKED;
static nsHtml5AttributeName* ATTR_FENCE; static nsHtml5AttributeName* ATTR_FENCE;
static nsHtml5AttributeName* ATTR_NONCE;
static nsHtml5AttributeName* ATTR_ONSCROLL; static nsHtml5AttributeName* ATTR_ONSCROLL;
static nsHtml5AttributeName* ATTR_ONACTIVATE; static nsHtml5AttributeName* ATTR_ONACTIVATE;
static nsHtml5AttributeName* ATTR_OPACITY; static nsHtml5AttributeName* ATTR_OPACITY;