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;
import java.util.HashMap;
import org.xml.sax.ErrorHandler;
import org.xml.sax.Locator;
import org.xml.sax.ext.Locator2;
@ -686,6 +688,15 @@ public class Tokenizer implements Locator, Locator2 {
return this.errorHandler;
}
/**
* Gets the errorProfile.
*
* @param errorProfile
*/
public HashMap getErrorProfile() {
return null;
}
/**
* Sets the commentPolicy.
*

View File

@ -1458,10 +1458,12 @@ public abstract class TreeBuilder<T> implements TokenHandler,
flushCharacters();
// [NOCPP[
boolean wasSelfClosing = selfClosing;
boolean voidElement = false;
if (errorHandler != null) {
// ID uniqueness
@IdType String id = attributes.getId();
if (id != null) {
if (id != null && !isTemplateContents()) {
LocatorImpl oldLoc = idLocations.get(id);
if (oldLoc != null) {
err("Duplicate ID \u201C" + id + "\u201D.");
@ -1580,6 +1582,9 @@ public abstract class TreeBuilder<T> implements TokenHandler,
elementName,
attributes);
selfClosing = false;
// [NOCPP[
voidElement = true;
// ]NOCPP]
attributes = null; // CPP
break starttagloop;
case TITLE:
@ -1592,6 +1597,9 @@ public abstract class TreeBuilder<T> implements TokenHandler,
elementName,
attributes);
selfClosing = false;
// [NOCPP[
voidElement = true;
// ]NOCPP]
attributes = null; // CPP
break starttagloop;
case SCRIPT:
@ -1778,6 +1786,9 @@ public abstract class TreeBuilder<T> implements TokenHandler,
attributes,
formPointer);
selfClosing = false;
// [NOCPP[
voidElement = true;
// ]NOCPP]
attributes = null; // CPP
break starttagloop;
case FORM:
@ -2124,6 +2135,9 @@ public abstract class TreeBuilder<T> implements TokenHandler,
elementName,
attributes);
selfClosing = false;
// [NOCPP[
voidElement = true;
// ]NOCPP]
attributes = null; // CPP
break starttagloop;
case HR:
@ -2132,6 +2146,9 @@ public abstract class TreeBuilder<T> implements TokenHandler,
elementName,
attributes);
selfClosing = false;
// [NOCPP[
voidElement = true;
// ]NOCPP]
attributes = null; // CPP
break starttagloop;
case IMAGE:
@ -2145,6 +2162,9 @@ public abstract class TreeBuilder<T> implements TokenHandler,
elementName, attributes,
formPointer);
selfClosing = false;
// [NOCPP[
voidElement = true;
// ]NOCPP]
attributes = null; // CPP
break starttagloop;
case TEXTAREA:
@ -2324,6 +2344,9 @@ public abstract class TreeBuilder<T> implements TokenHandler,
elementName,
attributes);
selfClosing = false;
// [NOCPP[
voidElement = true;
// ]NOCPP]
attributes = null; // CPP
break starttagloop;
case META:
@ -2391,6 +2414,9 @@ public abstract class TreeBuilder<T> implements TokenHandler,
elementName,
attributes);
selfClosing = false;
// [NOCPP[
voidElement = true;
// ]NOCPP]
attributes = null; // CPP
break starttagloop;
case META:
@ -2399,6 +2425,9 @@ public abstract class TreeBuilder<T> implements TokenHandler,
elementName,
attributes);
selfClosing = false;
// [NOCPP[
voidElement = true;
// ]NOCPP]
attributes = null; // CPP
break starttagloop;
case STYLE:
@ -2438,6 +2467,9 @@ public abstract class TreeBuilder<T> implements TokenHandler,
elementName,
attributes);
selfClosing = false;
// [NOCPP[
voidElement = true;
// ]NOCPP]
attributes = null; // CPP
break starttagloop;
case TEMPLATE:
@ -2572,6 +2604,9 @@ public abstract class TreeBuilder<T> implements TokenHandler,
elementName,
attributes);
selfClosing = false;
// [NOCPP[
voidElement = true;
// ]NOCPP]
attributes = null; // CPP
break starttagloop;
default:
@ -2745,6 +2780,9 @@ public abstract class TreeBuilder<T> implements TokenHandler,
elementName,
attributes);
selfClosing = false;
// [NOCPP[
voidElement = true;
// ]NOCPP]
pop(); // head
attributes = null; // CPP
break starttagloop;
@ -2756,6 +2794,9 @@ public abstract class TreeBuilder<T> implements TokenHandler,
elementName,
attributes);
selfClosing = false;
// [NOCPP[
voidElement = true;
// ]NOCPP]
pop(); // head
attributes = null; // CPP
break starttagloop;
@ -2844,6 +2885,13 @@ public abstract class TreeBuilder<T> implements TokenHandler,
}
if (selfClosing) {
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: 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_CHECKED;
static nsHtml5AttributeName* ATTR_FENCE;
static nsHtml5AttributeName* ATTR_NONCE;
static nsHtml5AttributeName* ATTR_ONSCROLL;
static nsHtml5AttributeName* ATTR_ONACTIVATE;
static nsHtml5AttributeName* ATTR_OPACITY;