From 78fdfd9e3a2fa08a106823d1a3e5684b36e49abd Mon Sep 17 00:00:00 2001
From: Noam Rosenthal To parse HTML from a string, given a To parse HTML from a string, given a Set document's type to " If configuration is not null, then set parser's parser
+ sanitizer configuration to configuration and set parser's
+ remove javascript navigation URLs to safe. Place html into the input stream for parser. The
encoding confidence is
irrelevant. Parses html using the HTML parser with options options, and replaces
the children of element with the result. element provides context for the
- HTML parser. The parsed fragment is sanitized based on the
- options's " Parses html using the HTML parser with options options, and replaces
the children of shadowRoot with the result. shadowRoot's host provides context for the HTML parser. The
- parsed fragment is sanitized based on the options's
- " Parses html using the HTML parser with options options, and replaces
the children of element with the result. element provides context for the
HTML parser. If the options dictionary contains a " Parses html using the HTML parser with options options, and replaces
the children of shadowRoot with the result. shadowRoot's host provides context for the HTML parser. If the
options dictionary contains a " Parses html using the HTML parser with options options, and returns
- a new Let sanitizer be the result of calling get a sanitizer instance from
options with options and true. Call sanitize on document with sanitizer and
- true. Let configuration be sanitizer's
+ configuration. Remove unsafe from configuration. Parse HTML from a string given document, html,
+ configuration, and true. Return document. Parse HTML from a string given document and
- compliantHTML. Let sanitizer be the result of calling get a sanitizer instance from
options with options and false. Call sanitize on document with sanitizer and
- false. Let configuration be sanitizer's
+ configuration. Parse HTML from a string given document, compliantHTML,
+ configuration, and false. Return document. Let sanitizer be the result of calling getting a sanitizer from options given safe. Let configuration be sanitizer's
+ configuration. If safe is true, then remove unsafe from
+ configuration. Let scriptingMode be Inert. Let fragment be the result of invoking the HTML fragment parsing
- algorithm given target, html, true, and
- scriptingMode. Let fragment be the result of parsing a fragment given target, html, true,
+ scriptingMode, configuration, and safe. Scripts in fragment will only execute once inserted into
target. Sanitize fragment given sanitizer and
- safe. Replace all with fragment within
target. To sanitize a Let configuration be sanitizer's
- configuration. To determine whether an attribute attribute contains a Assert: configuration is valid. Let url be the result of running the basic URL parser on
+ attribute's value. If safe is true, then remove unsafe from
- configuration. If url is failure, then return false. Run the inner sanitize steps given node, configuration,
- and safe. Return true if url's scheme is " To perform the inner sanitize steps given a To check if a sanitizer config allows comments given a SanitizerConfig
+ configuration: Return true if configuration[" To check if a sanitizer config allows processing instruction target given a
+ string piTarget and a SanitizerConfig
+ configuration: For each child of node's children: If configuration[" Assert: child is a If configuration[" If child is a Otherwise, if configuration[" If child is a Return true. If configuration[" To sanitize an Let elementName be a SanitizerElementNamespace with
+ element's local name and namespace. Continue. If configuration[" If configuration[" If child is a If configuration[" Let piTarget be child's target. Otherwise, if configuration[" If configuration[" For each attribute of element's
+ attribute list: If configuration[" Let attrName be a SanitizerAttributeNamespace with
+ attribute's local name and namespace. Otherwise: Let elementWithLocalAttributes be «[ ]». If configuration[" If configuration[" If elementWithLocalAttributes[" Otherwise: Otherwise, if configuration[" Let elementName be a SanitizerElementNamespace with
- child's local name and namespace. If configuration[" Assert: node is not a Run the inner sanitize steps given child,
- configuration, and handleJavascriptNavigationUrls. Let fragment be a new For each innerChild of
- child's children, append innerChild to
- fragment. Replace child with
- fragment within node. Assert that this did not
- throw. Continue. If configuration[" If configuration[" Otherwise: If configuration[" If elementName[" If child is a shadow host, then run the inner sanitize
- steps given child's shadow root, configuration, and
- handleJavascriptNavigationUrls. Let elementWithLocalAttributes be «[ ]». If configuration[" For each attribute in child's
- attribute list: Let attrName be a SanitizerAttributeNamespace with
- attribute's local name and
- namespace. If elementWithLocalAttributes[" Otherwise, if configuration[" If configuration[" Otherwise: Otherwise: If elementWithLocalAttributes[" Otherwise, if configuration[" If elementWithLocalAttributes[" Otherwise, if configuration[" If removeJavascriptNavigationUrls is false, then
+ continue. If handleJavascriptNavigationUrls is true: If the pair (elementName, attrName) matches an entry in the
+ built-in navigating URL attributes list, and if attribute
+ contains a If the pair (elementName, attrName) matches an entry in the
- built-in navigating URL attributes list, and if attribute
- contains a If child's namespace is
- the MathML Namespace, attribute's local name is " If the built-in animating URL attributes list contains the pair (elementName, attrName), and
- attribute's value is " If element's namespace is the
+ MathML Namespace, attribute's local name is " Run the inner sanitize steps given child,
- configuration, and handleJavascriptNavigationUrls. If the built-in animating URL attributes list contains the pair (elementName, attrName), and
+ attribute's value is " To determine whether an attribute attribute contains a Let url be the result of running the basic URL parser on
- attribute's value. If url is failure, then return false. Return true if url's scheme is " Return " The root insertion target, which is null or a A boolean allow declarative shadow roots (initially false). The scripting mode, which is a parser scripting mode. The frameset-ok flag is set to "ok" when the parser is created. It is set to "not
ok" after certain tokens are seen. A SanitizerConfig-or-null parser sanitizer configuration, initially
+ null. A boolean remove javascript navigation URLs, initially false. The insertion target redirection map is an ordered map, initially
+ empty.Document document and a
- string html:Document document, a
+ string html, an optional SanitizerConfig or null
+ configuration (default null), and an optional boolean safe (default
+ false):
@@ -125758,14 +125768,14 @@ enum DOMParserSupportedType {
data-x="concept-document-allow-declarative-shadow-roots">allow declarative shadow roots to
true.
- DOMParserSupportedType {
data-x="concept-document-allow-declarative-shadow-roots">allow declarative shadow roots,
associated with document.element.setHTML(html, options)sanitizer" member, and
- unsafe content is removed.sanitizer" member, and unsafe content is removed.
shadowRoot.setHTML(html, options)sanitizer" member, and options's "sanitizer" member, and unsafe content is removed.element.setHTMLUnsafe(html, options)sanitizer" member, it is used to
- sanitize the parsed fragment before it is inserted into element. If the
- options dictionary's "runScripts" member is true, scripts contained
- in html will be executed immediately after the node tree is updated.runScripts" member is
+ true, scripts contained in html will be executed immediately after the node tree is
+ updated.
shadowRoot.setHTMLUnsafe(html, options)sanitizer" member, it is used to
- sanitize the parsed fragment before it is inserted into shadowRoot. If
- the options dictionary's "runScripts" member is true, scripts contained
- in html will be executed immediately after the node tree is updated.runScripts" member is
+ true, scripts contained in html will be executed immediately after the node tree is
+ updated.
doc = Document.parseHTML(html, options)Document containing the result. The resulting document is sanitized based on the options's "sanitizer" member, and unsafe content is removed.Document containing the result. The resulting document is sanitized based on
+ the options's "sanitizer" member,
+ and unsafe content is removed.
doc = Document.parseHTMLUnsafe(html, options)about:blank. If the options dictionary contains a "sanitizer" member, it is used to
- sanitize the resulting DOM.
+ data-x="dom-ParseHTMLUnsafeOptions-sanitizer">sanitizer" member, it is used to sanitize
+ the resulting DOM.
@@ -125725,8 +125730,13 @@ enum DOMParserSupportedType {
Node node with a Sanitizer
- sanitizer and a boolean safe:
-
javascript:
+ URL:
+
javascript", and false otherwise.Node node, a
- SanitizerConfig configuration, and a boolean
- handleJavascriptNavigationUrls:comments"] is true; otherwise false.
+ processingInstructions"] exists, then:
-
+ Text, Comment,
- Element, ProcessingInstruction, or DocumentType
- node.processingInstructions"] does not
+ contain piTarget, then return false.DocumentType or Text node, then
- continue.removeProcessingInstructions"]
+ contains piTarget, return false.Comment node:
-
comments"] is not true, then remove child.Element element given a
+ SanitizerConfig configuration and a boolean
+ removeJavascriptNavigationUrls:
+
-
+ replaceWithChildrenElements"]
+ exists and configuration["replaceWithChildrenElements"]
+ contains elementName, then return "Replace with children".elements"]
+ exists, then:
+ ProcessingInstruction node:elements"]
+ does not contain elementName, then return
+ "Remove".
-
-
+ removeElements"] contains elementName, return "Remove".processingInstructions"] exists:
-
- processingInstructions"] does
- not contain piTarget, then remove child.
+
+
-
-
- removeProcessingInstructions"]
- contains piTarget, then remove child.elements"] exists
+ and configuration["elements"]
+ contains elementName, then set
+ elementWithLocalAttributes to configuration["elements"][elementName].removeAttributes"]
+ exists and elementWithLocalAttributes["removeAttributes"]
+ contains attrName, then remove attribute from
+ element's attribute list and continue.attributes"] exists, then:
-
+ replaceWithChildrenElements"]
- exists and configuration["replaceWithChildrenElements"]
- contains elementName:
-
- Document.DocumentFragment whose node
- document is node's node document.elements"] exists:
-
- elements"] does not contain elementName, then remove child and
- continue.
-
+ data-x="dom-SanitizerConfig-attributes">attributes"] does not contain attrName and
+ elementWithLocalAttributes["removeElements"] contains elementName, then remove child and
- continue.attributes"] with default « » does not contain attrName, and if "data-" is not a
+ code unit prefix of attribute's local name or attribute's namespace is not null or
+ configuration["dataAttributes"] is not true, then remove attribute from
+ element's attribute list and continue.
name"] is "template" and
- elementName["namespace"] is the HTML
- namespace, then run the inner sanitize steps given child's
- template contents, configuration, and
- handleJavascriptNavigationUrls.elements"] exists and configuration["elements"] contains elementName, then set
- elementWithLocalAttributes to configuration["elements"][elementName].
-
removeAttributes"]
- exists and elementWithLocalAttributes["removeAttributes"]
- contains attrName, then remove attribute.attributes"] exists:
-
- attributes"] does not contain attrName and
- elementWithLocalAttributes["attributes"] with default « » does not contain attrName, and if "data-" is
- not a code unit prefix of attribute's local name or attribute's namespace is not null or
- configuration["dataAttributes"] is not true, then
- remove
- attribute.
+
+ attributes"] exists and elementWithLocalAttributes["attributes"] does not
+ contain attrName, then remove attribute from
+ element's attribute list and continue.removeAttributes"] contains attrName, remove attribute from
+ element's attribute list and continue.
-
- attributes"] exists and elementWithLocalAttributes["attributes"] does
- not contain attrName, then remove attribute.removeAttributes"] contains attrName, then remove attribute.javascript: URL, then remove attribute from
+ element's attribute list.
-
-
- javascript: URL, then remove attribute.href",
- attribute's namespace is
- null or the XLink namespace, and attribute contains a
- javascript: URL, then remove attribute.href" or "xlink:href", then remove attribute.href",
+ attribute's namespace is null or
+ the XLink namespace, and attribute contains a
+ javascript: URL, then remove attribute from
+ element's attribute list.href" or "xlink:href", then remove attribute from
+ element's attribute list.javascript:
- URL:
-
javascript", and false otherwise.Keep".Other parsing state flags
- DocumentFragment
- (initially null).Tokenization
@@ -144308,7 +144242,6 @@ dictionary StorageEventInit : EventInit {
recognized that practical concerns will likely force user agents to impose nesting depth
constraints.
While the parser is processing a token, it can enable or disable exists, then set adjustedInsertionLocation to + that.
+ +Return adjustedInsertionLocation.
Let insertionLocation be the adjusted insertion location.
Let the insertionLocation be the adjusted insertion + location.
If the parser's parser sanitizer configuration is not null, then:
+ +Let action be the result of sanitizing + element given the parser's parser sanitizer configuration and the + parser's remove javascript navigation URLs.
Switch on action:
+ +Replace with children"Remove"Keep"If it is not possible to insert element at insertionLocation, abort these steps.
Let insertionLocation be the adjusted insertion location.
If insertionLocation is null, then return.
If insertionLocation is in a Document node, then return.
If insertionLocation is in a Document node,
+ then return.
The DOM will not let Document nodes have Text node
children, so they are dropped on the floor.
If the parser's parser sanitizer configuration is non-null and does not + allow comments, then abort these + steps.
Let data be the data given in the comment token being processed.
Set insertionLocation to the adjusted insertion location given insertionLocation.
Create a Comment node whose data attribute is set to
- data and whose node document is the same as that of the node in which the
- insertionLocation finds itself.
If insertionLocation is null, then abort these steps.
Let comment be a Comment node whose data
+ attribute is set to data and whose node document is the same as that of
+ the node in which the insertionLocation finds itself.
Insert the newly created node at insertionLocation.
Insert comment at insertionLocation.
Let target be the target given in the processing instruction token being processed.
If the parser's parser sanitizer configuration is non-null and it does not + allow + target, then abort these steps.
Let data be the data given in the processing instruction token being processed.
Set insertionLocation to the adjusted insertion location given insertionLocation.
Create a Let pi be a new Insert the newly created node at insertionLocation. Insert pi at insertionLocation.ProcessingInstruction node whose ProcessingInstruction node whose target is target, data is data, and node document is the
same as that of the node in which the insertionLocation finds itself.
The HTML fragment parsing algorithm, given an Element or
- DocumentFragment target, a string input, an optional boolean
- allowDeclarativeShadowRoots (default false), and an optional parser scripting
- mode scriptingMode (default Inert),
+ DocumentFragment target, a string input, an
+ optional boolean allowDeclarativeShadowRoots (default false), an optional
+ parser scripting mode scriptingMode (default Inert), an optional SanitizerConfig or null
+ configuration (default null), and an optional boolean safe (default false),
is the following steps. They return a DocumentFragment.
Parts marked fragment case in algorithms in the HTML
@@ -149677,15 +149654,16 @@ console.assert(container.firstChild instanceof SuperP);
document's mode to "limited-quirks".
Create a new HTML parser whose allow declarative shadow roots is - allowDeclarativeShadowRoots, and associate it with document.
Create a new HTML parser whose parser sanitizer configuration is + configuration, allow declarative shadow roots is + allowDeclarativeShadowRoots, scripting mode is + scriptingMode, and remove javascript navigation URLs + is safe, and associate it with document.
If contextDocument's scripting is disabled, then set scriptingMode to Disabled.
Set the parser's scripting mode to scriptingMode.
Set the state of the HTML parser's tokenization stage as follows, switching on context:
@@ -149739,7 +149717,8 @@ console.assert(container.firstChild instanceof SuperP);Let fragment be a new DocumentFragment whose node
document is target's node document.
Set the parser's root insertion target to fragment.
Set the parser's insertion target redirection map[root] to + fragment, right after its last child (if exists).
If context is a If elementWithLocalAttributes[" Otherwise, if configuration["template
element, then push "in template" onto the
From 3f460b9149706f379cf8ec4497d86603fc172111 Mon Sep 17 00:00:00 2001
From: Noam Rosenthal removeAttributes"]
- exists and elementWithLocalAttributes["removeAttributes"]
- contains attrName, then remove attribute from
+ data-x="dom-SanitizerElementNamespaceWithAttributes-removeAttributes"
+ >removeAttributes"] exists and
+ elementWithLocalAttributes["removeAttributes"] contains attrName,
+ then remove attribute from
element's attribute list and continue.attributes"] exists, then:
element.setHTML(html, options)Parses html using the HTML parser with options options, and replaces
the children of element with the result. element provides context for the
- HTML parser. The parsed fragment is sanitized based on the options's "sanitizer" member, and unsafe content is removed.
sanitizer" member, and
+ unsafe content is removed.
shadowRoot.setHTML(html, options)Parses html using the HTML parser with options options, and replaces
the children of shadowRoot with the result. shadowRoot's host provides context for the HTML parser. The
- parsed fragment is sanitized based on the options's "sanitizer" member, and sanitized based on the options's
+ "sanitizer" member, and unsafe content is removed.
element.setHTMLUnsafe(html, options)Parses html using the HTML parser with options options, and replaces
the children of element with the result. element provides context for the
HTML parser. If the options dictionary contains a "sanitizer" member, it is used to sanitize the
- parsed fragment before it is inserted into element. If the options
- dictionary's "runScripts" member is
- true, scripts contained in html will be executed immediately after the node tree is
- updated.
runScripts" member is true, scripts contained
+ in html will be executed immediately after the node tree is updated.
shadowRoot.setHTMLUnsafe(html, options)Parses html using the HTML parser with options options, and replaces
the children of shadowRoot with the result. shadowRoot's host provides context for the HTML parser. If the
options dictionary contains a "sanitizer" member, it is used to sanitize the
- parsed fragment before it is inserted into shadowRoot. If the options
- dictionary's "runScripts" member is
- true, scripts contained in html will be executed immediately after the node tree is
- updated.
runScripts" member is true, scripts contained
+ in html will be executed immediately after the node tree is updated.
doc = Document.parseHTML(html, options)Parses html using the HTML parser with options options, and returns
- a new Document containing the result. The resulting document is sanitized based on
- the options's "sanitizer" member,
- and unsafe content is removed.
Document containing the result. The resulting document is sanitized based on the options's "sanitizer" member, and unsafe content is removed.
doc = Document.parseHTMLUnsafe(html, options)about:blank. If the options dictionary contains a "sanitizer" member, it is used to sanitize
- the resulting DOM.
+ data-x="dom-ParseHTMLUnsafeOptions-sanitizer">sanitizer" member, it is used to
+ sanitize the resulting DOM.
From 09ffc0a273b663fbd1d1c145a4a3c816b6cc162d Mon Sep 17 00:00:00 2001
From: Noam Rosenthal If insertionLocation is null, then return.
If insertionLocation is in a Document node,
- then return.
If insertionLocation is in a Document node, then return.
The DOM will not let Document nodes have Text node
children, so they are dropped on the floor.
Set up the HTML parser's stack of open elements so that it contains just the single element root.
Let fragment be a new DocumentFragment whose node
- document is target's node document.
Let fragment be a new DocumentFragment whose node
+ document is document.
The DocumentFragment is created as part of the inert document to
+ avoid creation time side effects before sanitization.
Set the parser's insertion target redirection map[root] to fragment, right after its last child (if exists).
Let sanitizer be the result of calling getting a sanitizer from options given safe.
Let configuration be sanitizer's +
Let sanitizerConfig be sanitizer's configuration.
If safe is true, then remove unsafe from - configuration.
Let scriptingMode be Inert.
Let fragment be the result of parsing a fragment given target, html, true, - scriptingMode, configuration, and safe.
+Let fragment be the result of invoking the HTML fragment parsing + algorithm given target, html, true, scriptingMode, + sanitizerConfig, and safe.
Scripts in fragment will only execute once inserted into target.
@@ -127804,7 +127804,7 @@ dictionary SanitizerConfig {If configuration["elements"]
- exists, then:
Let the insertionLocation be the adjusted insertion - location.
Let insertionLocation be the adjusted insertion location.
If the parser's parser sanitizer configuration is not null, then:
@@ -144690,8 +144689,6 @@ dictionary StorageEventInit : EventInit {Let insertionLocation be the adjusted insertion location.
If insertionLocation is null, then return.
If insertionLocation is in a Document node, then return.
Set insertionLocation to the adjusted insertion location given insertionLocation.
If insertionLocation is null, then abort these steps.
Let comment be a Comment node whose data
attribute is set to data and whose node document is the same as that of
the node in which the insertionLocation finds itself.
Set insertionLocation to the adjusted insertion location given insertionLocation.
Let pi be a new Create a new Insert pi at insertionLocation. Insert the newly created node at insertionLocation.ProcessingInstruction node whose ProcessingInstruction node whose target is target, data is data, and node document is the
same as that of the node in which the insertionLocation finds itself.
Let targetParent be the node in which adjustedInsertionLocation finds itself.
If the parser's insertion target redirection map[targetParent] - exists, then set adjustedInsertionLocation to - that.
If the parser's insertion target redirection map[targetParent] + exists, then:
+ +Let redirectedLocation be the parser's insertion target redirection + map[targetParent].
Let redirectedParent be the node in which redirectedLocation + finds itself.
If adjustedInsertionLocation is immediately before a node + referenceChild, and referenceChild's parent node is + redirectedParent, then set adjustedInsertionLocation to inside + redirectedParent, immediately before referenceChild.
+Otherwise, set adjustedInsertionLocation to + redirectedLocation.
Return adjustedInsertionLocation.
Let targetParent be the node in which adjustedInsertionLocation finds itself.
If the parser's insertion target redirection map[targetParent] - exists, then:
+If the parser's insertion target redirection map[targetParent] + does not exist, then return + adjustedInsertionLocation.
Let redirectedLocation be the parser's insertion target redirection - map[targetParent].
Let refChild be the node before which adjustedInsertionLocation + finds itself, if any.
Let redirectedParent be the node in which redirectedLocation - finds itself.
Let redirectedLocation be the parser's insertion target redirection + map[targetParent].
If adjustedInsertionLocation is immediately before a node - referenceChild, and referenceChild's parent node is - redirectedParent, then set adjustedInsertionLocation to inside - redirectedParent, immediately before referenceChild.
-Let redirectedParent be the node in which redirectedLocation + finds itself.
Otherwise, set adjustedInsertionLocation to - redirectedLocation.
If refChild is a node whose parent node is + redirectedParent, then return a location inside redirectedParent, + immediately before refChild.
Return adjustedInsertionLocation.
Return redirectedLocation.
Let overrideTarget be null if insertionLocation is null; - otherwise the node in which insertionLocation finds itself.
Let the adjustedInsertionLocation be the appropriate place for inserting - a node given overrideTarget.
Let targetParent be the node in which adjustedInsertionLocation - finds itself.
If the parser's insertion target redirection map[targetParent] - does not exist, then return - adjustedInsertionLocation.
Let refChild be the node before which adjustedInsertionLocation - finds itself, if any.
Let redirectedLocation be the parser's insertion target redirection - map[targetParent].
Let redirectedLocation be the parser's insertion target redirection + map[targetParent].
+ +The insertion target redirection map is used to insert elements to
+ the target DocumentFragment during the fragment parsing algorithm
+ steps, or for elements that are replaced with children as
+ part of sanitization.
Let redirectedParent be the node in which redirectedLocation - finds itself.
If refChild is a node whose parent node is - redirectedParent, then return a location inside redirectedParent, - immediately before refChild.
If refChild is a node whose parent node is redirectedParent, then + return a location inside redirectedParent, immediately before + refChild.
+ +This can occur when an element is replaced with its children as + part of sanitization in the middle of foster parenting.
+Return redirectedLocation.
Parse HTML from a string given document and - html.
Let sanitizer be the result of calling get a sanitizer instance from options with options and true.