/*
         * Else, ignore remaining data
         * TODO add a way to remove current tag
         */

/*
         * Remove the node if it is not unique.
         * We are going through the array from the end, so we only
         * have to check nodes that preceed the node under consideration in the array.
         */

/*
         * Self-closing tags will be on the top of the stack
         * (cheaper check than in onclosetag)
         */

/*
     * Check if each node (or one of its ancestors) is already contained in the
     * array.
     */

/*
 * All of the following exports exist for backwards-compatibility.
 * They should probably be removed eventually.
 */

/*
 * Module dependencies
 */

/* AfterAttributeName */

/* AfterCdata1 */

/* AfterCdata2 */

/* AfterClosingTagName */

/* AfterComment1 */

/* AfterComment2 */

/* AfterScript1 */

/* AfterScript2 */

/* AfterScript3 */

/* AfterScript4 */

/* AfterScript5 */

/* AfterStyle1 */

/* AfterStyle2 */

/* AfterStyle3 */

/* AfterStyle4 */

/* AfterTitle1 */

/* AfterTitle2 */

/* AfterTitle3 */

/* AfterTitle4 */

/* BeforeAttributeName */

/* BeforeAttributeValue */

/* BeforeCdata1 */

/* BeforeCdata2 */

/* BeforeCdata3 */

/* BeforeCdata4 */

/* BeforeCdata5 */

/* BeforeCdata6 */

/* BeforeClosingTagName */

/* BeforeComment */

/* BeforeDeclaration */

/* BeforeEntity */

/* BeforeNumericEntity */

/* BeforeScript1 */

/* BeforeScript2 */

/* BeforeScript3 */

/* BeforeScript4 */

/* BeforeScript5 */

/* BeforeSpecialS */

/* BeforeSpecialSEnd */

/* BeforeSpecialT */

/* BeforeSpecialTEnd */

/* BeforeStyle1 */

/* BeforeStyle2 */

/* BeforeStyle3 */

/* BeforeStyle4 */

/* BeforeTagName */

/* BeforeTitle1 */

/* BeforeTitle2 */

/* BeforeTitle3 */

/* BeforeTitle4 */

/* CONTAINED_BY */

/* CONTAINS */

/* DISCONNECTED */

/* Exit foreign mode at integration points */

/* FOLLOWING */

/* Fix up mixed-case attribute names */

/* Fix up mixed-case element names */

/* InAttributeName */

/* InAttributeValueDq */

/* InAttributeValueNq */

/* InAttributeValueSq */

/* InCdata */

/* InClosingTagName */

/* InComment */

/* InDeclaration */

/* InHexEntity */

/* InNamedEntity */

/* InNumericEntity */

/* InProcessingInstruction */

/* InSelfClosingTag */

/* InSpecialComment */

/* InTagName */

/* None */

/* PRECEDING */

/* Script */

/* Style */

/* Text */

/* Title */

/* c8 ignore next */

/* c8 ignore next 2 */

/* c8 ignore next 3 */

/* c8 ignore next 7 */

/* c8 ignore start */

/* c8 ignore stop */

/* eslint-disable no-console */

/*!
 * is-plain-object <https://github.com/jonschlinkert/is-plain-object>
 *
 * Copyright (c) 2014-2017, Jon Schlinkert.
 * Released under the MIT License.
 */

/**
		 * Adds descriptor properties to a candidate, pushes to the candidates array
		 * @return undefined
		 */

/**
		 * Tokenizes descriptor properties prior to parsing
		 * Returns undefined.
		 */

/**
         * Data that has already been processed will be removed from the buffer occasionally.
         * `_bufferOffset` keeps track of how many characters have been removed, to make sure position information is accurate.
         */

/**
         * Same as {@link children}.
         * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
         */

/**
         * Same as {@link data}.
         * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
         */

/**
         * Same as {@link name}.
         * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
         */

/**
         * Same as {@link next}.
         * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
         */

/**
         * Same as {@link parent}.
         * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
         */

/**
         * Same as {@link prev}.
         * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
         */

/**
         * [DOM spec](https://dom.spec.whatwg.org/#dom-node-nodetype)-compatible
         * node {@link type}.
         */

/**
     *
     * @param callback
     * @param options
     */

/**
     *
     * @param type The type of the node.
     */

/**
     * @param callback Called once parsing has completed.
     * @param options Settings for the handler.
     * @param elementCB Callback whenever a tag is closed.
     */

/**
     * @param name Name of the tag, eg. `div`, `span`.
     * @param attribs Object mapping attribute names to attribute values.
     * @param children Children of the node.
     */

/**
     * @param type The type of the node
     * @param data The content of the data node
     */

/**
     * @param type Type of the node.
     * @param children Children of the node. Only certain node types can have children.
     */

/**
     * Alias of `end`, for backwards compatibility.
     *
     * @param chunk Optional final chunk to parse.
     * @deprecated
     */

/**
     * Alias of `write`, for backwards compatibility.
     *
     * @param chunk Chunk to parse.
     * @deprecated
     */

/**
     * Clone this node, and optionally its children.
     *
     * @param recursive Clone child nodes as well.
     * @returns A clone of the node.
     */

/**
     * HTML only allows ASCII alpha characters (a-z and A-Z) at the beginning of a tag name.
     *
     * XML allows a lot more characters here (@see https://www.w3.org/TR/REC-xml/#NT-NameStartChar).
     * We allow anything that wouldn't end the tag.
     */

/**
     * Iterates through the buffer, calling the function corresponding to the current state.
     *
     * States that are more likely to be hit are higher up, as a performance improvement.
     */

/**
     * Parses a chunk of data and calls the corresponding callbacks.
     *
     * @param chunk Chunk to parse.
     */

/**
     * Parses the end of the buffer and clears the stack, calls onend.
     *
     * @param chunk Optional final chunk to parse.
     */

/**
     * Pauses parsing. The parser won't emit events until `resume` is called.
     */

/**
     * Resets the parser to a blank state, ready to parse a new HTML document
     */

/**
     * Resets the parser, then parses a complete document and
     * pushes it to the handler.
     *
     * @param data Document to parse.
     */

/**
     * Resumes parsing after `pause` was called.
     */

/**
     * The current index within all of the written data.
     */

/**
    * Filters the existing attributes for the given property. Discards any attributes
    * which don't match the allowlist.
    *
    * @param  {object} selectedRule             - Example: { color: red, font-family: helvetica }
    * @param  {array} allowedDeclarationsList   - List of declarations which pass the allowlist.
    * @param  {object} attributeObject          - Object representing the current css property.
    * @property {string} attributeObject.type   - Typically 'declaration'.
    * @property {string} attributeObject.prop   - The CSS property, i.e 'color'.
    * @property {string} attributeObject.value  - The corresponding value to the css property, i.e 'red'.
    * @return {function}                        - When used in Array.reduce, will return an array of Declaration objects
    */

/**
   * Extracts the style attributes from an AbstractSyntaxTree and formats those
   * values in the inline style attribute format.
   *
   * @param  {AbstractSyntaxTree} filteredAST
   * @return {string}             - Example: "color:yellow;text-align:center !important;font-family:helvetica;"
   */

/**
   * Filters user input css properties by allowlisted regex attributes.
   * Modifies the abstractSyntaxTree object.
   *
   * @param {object} abstractSyntaxTree  - Object representation of CSS attributes.
   * @property {array[Declaration]} abstractSyntaxTree.nodes[0] - Each object cointains prop and value key, i.e { prop: 'color', value: 'red' }.
   * @param {object} allowedStyles       - Keys are properties (i.e color), value is list of permitted regex rules (i.e /green/i).
   * @return {object}                    - The modified tree.
   */

/**
 * @param a First function to combine.
 * @param b Second function to combine.
 * @returns A function taking a node and returning `true` if either
 * of the input functions returns `true` for the node.
 */

/**
 * @param attrib Attribute to check.
 * @param value Attribute value to look for.
 * @returns A function to check whether the a node has an attribute with a particular value.
 */

/**
 * @param id The unique ID attribute value to look for.
 * @param nodes Nodes to search through.
 * @param recurse Also consider child nodes.
 * @returns The node with the supplied ID.
 */

/**
 * @param node Node to check.
 * @returns `true` if the node has the type `CDATA`, `false` otherwise.
 */

/**
 * @param node Node to check.
 * @returns `true` if the node has the type `Comment`, `false` otherwise.
 */

/**
 * @param node Node to check.
 * @returns `true` if the node has the type `ProcessingInstruction`, `false` otherwise.
 */

/**
 * @param node Node to check.
 * @returns `true` if the node has the type `Text`, `false` otherwise.
 */

/**
 * @param node Node to check.
 * @returns `true` if the node is a `Element`, `false` otherwise.
 */

/**
 * @param node Node to check.
 * @returns `true` if the node is a `NodeWithChildren` (has children), `false` otherwise.
 */

/**
 * @param node Node to get the inner HTML of.
 * @param options Options for serialization.
 * @deprecated Use the `dom-serializer` module directly.
 * @returns `node`'s inner HTML.
 */

/**
 * @param node Node to get the outer HTML of.
 * @param options Options for serialization.
 * @deprecated Use the `dom-serializer` module directly.
 * @returns `node`'s outer HTML.
 */

/**
 * @param options An object describing nodes to look for.
 * @param node The element to test.
 * @returns Whether the element matches the description in `options`.
 */

/**
 * @param options An object describing nodes to look for.
 * @param nodes Nodes to search through.
 * @param recurse Also consider child nodes.
 * @param limit Maximum number of nodes to return.
 * @returns All nodes that match `options`.
 */

/**
 * @param options An object describing nodes to look for.
 * @returns A function executing all checks in `options` and returning `true`
 * if any of them match a node.
 */

/**
 * @param tagName Tag name to search for.
 * @param nodes Nodes to search through.
 * @param recurse Also consider child nodes.
 * @param limit Maximum number of nodes to return.
 * @returns All nodes with the supplied `tagName`.
 */

/**
 * @param test Function to test nodes on.
 * @param nodes Array of nodes to search.
 * @returns Whether a tree of nodes contains at least one node passing a test.
 */

/**
 * @param type Element type to look for.
 * @param nodes Nodes to search through.
 * @param recurse Also consider child nodes.
 * @param limit Maximum number of nodes to return.
 * @returns All nodes with the supplied `type`.
 */

/**
 * A `Node` that can have children.
 */

/**
 * A node that contains some data.
 */

/**
 * Adds a property to an object if it has a value.
 *
 * @param obj Object to be extended
 * @param prop Property name
 * @param tagName Tag name that contains the conditionally added property
 * @param where Element to search for the property
 * @param recurse Whether to recurse into child nodes.
 */

/**
 * An element within the DOM.
 */

/**
 * Append a child to an element.
 *
 * @param elem The element to append to.
 * @param child The element to be added as a child.
 */

/**
 * Append an element after another.
 *
 * @param elem The element to append after.
 * @param next The element be added.
 */

/**
 * Checks if an element is a feed root node.
 *
 * @param value The name of the element to check.
 * @returns Whether an element is a feed root node.
 */

/**
 * Checks whether an element has an attribute.
 *
 * @param elem Element to check.
 * @param name Attribute name to look for.
 * @returns Returns whether `elem` has the attribute `name`.
 */

/**
 * Clone a node, and optionally its children.
 *
 * @param recursive Clone child nodes as well.
 * @returns A clone of the node.
 */

/**
 * Comments within the document.
 */

/**
 * Compare the position of one node against another node in any other document.
 * The return value is a bitmask with the following values:
 *
 * Document order:
 * > There is an ordering, document order, defined on all the nodes in the
 * > document corresponding to the order in which the first character of the
 * > XML representation of each node occurs in the XML representation of the
 * > document after expansion of general entities. Thus, the document element
 * > node will be the first node. Element nodes occur before their children.
 * > Thus, document order orders element nodes in order of the occurrence of
 * > their start-tag in the XML (after expansion of entities). The attribute
 * > nodes of an element occur after the element and before its children. The
 * > relative order of attribute nodes is implementation-dependent./
 *
 * Source:
 * http://www.w3.org/TR/DOM-Level-3-Core/glossary.html#dt-document-order
 *
 * @param nodeA The first node to use in the comparison
 * @param nodeB The second node to use in the comparison
 * @returns A bitmask describing the input nodes' relative position.
 *
 * See http://dom.spec.whatwg.org/#dom-node-comparedocumentposition for
 * a description of these values.
 */

/**
 * Creates a parser instance, with an attached DOM handler.
 *
 * @param cb A callback that will be called once parsing has been completed.
 * @param options Optional options for the parser and DOM builder.
 * @param elementCb An optional callback that will be called every time a tag has been completed inside of the DOM.
 */

/**
 * Decodes a string with entities.
 *
 * @param data String to decode.
 * @param level Optional level to decode at. 0 = XML, 1 = HTML. Default is 0.
 * @deprecated Use `decodeXML` or `decodeHTML` directly.
 */

/**
 * Decodes a string with entities. Does not allow missing trailing semicolons for entities.
 *
 * @param data String to decode.
 * @param level Optional level to decode at. 0 = XML, 1 = HTML. Default is 0.
 * @deprecated Use `decodeHTMLStrict` or `decodeXML` directly.
 */

/**
 * Encodes a string with entities.
 *
 * @param data String to encode.
 * @param level Optional level to encode at. 0 = XML, 1 = HTML. Default is 0.
 * @deprecated Use `encodeHTML`, `encodeXML` or `encodeNonAsciiHTML` directly.
 */

/**
 * Encodes all characters not valid in XML documents using numeric hexadecimal
 * reference (eg. `&#xfc;`).
 *
 * Note that the output will be character-set dependent.
 *
 * @param data String to escape.
 */

/**
 * Encodes all entities and non-ASCII characters in the input.
 *
 * This includes characters that are valid ASCII characters in HTML documents.
 * For example `#` will be encoded as `&num;`. To get a more compact output,
 * consider using the `encodeNonAsciiHTML` function.
 *
 * If a character has no equivalent entity, a
 * numeric hexadecimal reference (eg. `&#xfc;`) will be used.
 */

/**
 * Encodes all non-ASCII characters, as well as characters not valid in HTML
 * documents using HTML entities.
 *
 * If a character has no equivalent entity, a
 * numeric hexadecimal reference (eg. `&#xfc;`) will be used.
 */

/**
 * Encodes all non-ASCII characters, as well as characters not valid in XML
 * documents using XML entities.
 *
 * If a character has no equivalent entity, a
 * numeric hexadecimal reference (eg. `&#xfc;`) will be used.
 */

/**
 * Encodes all non-ASCII characters, as well as characters not valid in XML
 * documents using numeric hexadecimal reference (eg. `&#xfc;`).
 *
 * Have a look at `escapeUTF8` if you want a more concise output at the expense
 * of reduced transportability.
 *
 * @param data String to escape.
 */

/**
 * Finds one element in a tree that passes a test.
 *
 * @param test Function to test nodes on.
 * @param nodes Array of nodes to search.
 * @param recurse Also consider child nodes.
 * @returns The first child node that passes `test`.
 */

/**
 * Finds the first element inside of an array that matches a test function.
 *
 * @param test Function to test nodes on.
 * @param nodes Array of nodes to search.
 * @returns The first node in the array that passes `test`.
 */

/**
 * Format attributes
 */

/**
 * Get a node's children.
 *
 * @param elem Node to get the children of.
 * @returns `elem`'s children, or an empty array.
 */

/**
 * Get a node's inner text.
 *
 * @param node Node to get the inner text of.
 * @returns `node`'s inner text.
 * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Node/innerText}
 */

/**
 * Get a node's inner text. Same as `textContent`, but inserts newlines for `<br>` tags.
 *
 * @deprecated Use `textContent` instead.
 * @param node Node to get the inner text of.
 * @returns `node`'s inner text.
 */

/**
 * Get a node's parent.
 *
 * @param elem Node to get the parent of.
 * @returns `elem`'s parent node.
 */

/**
 * Get a node's text content.
 *
 * @param node Node to get the text content of.
 * @returns `node`'s text content.
 * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent}
 */

/**
 * Get all media elements of a feed item.
 *
 * @param where Nodes to search in.
 * @returns Media elements.
 */

/**
 * Get one element by tag name.
 *
 * @param tagName Tag name to look for
 * @param node Node to search in
 * @returns The element or null
 */

/**
 * Get the feed object from the root of a DOM tree.
 *
 * @param doc - The DOM to to extract the feed from.
 * @returns The feed.
 */

/**
 * Get the tag name of an element.
 *
 * @param elem The element to get the name for.
 * @returns The tag name of `elem`.
 */

/**
 * Get the text content of an element with a certain tag name.
 *
 * @param tagName Tag name to look for.
 * @param where  Node to search in.
 * @param recurse Whether to recurse into child nodes.
 * @returns The text content of the element.
 */

/**
 * Gets an attribute from an element.
 *
 * @param elem Element to check.
 * @param name Attribute name to retrieve.
 * @returns The element's attribute value, or `undefined`.
 */

/**
 * Gets an elements siblings, including the element itself.
 *
 * Attempts to get the children through the element's parent first.
 * If we don't have a parent (the element is a root node),
 * we walk the element's `prev` & `next` to get all remaining nodes.
 *
 * @param elem Element to get the siblings of.
 * @returns `elem`'s siblings.
 */

/**
 * Given an array of nodes, remove any member that is contained by another.
 *
 * @param nodes Nodes to filter.
 * @returns Remaining nodes that aren't subtrees of each other.
 */

/**
 * Parse a RSS feed.
 *
 * @param feedRoot The root of the feed.
 * @returns The parsed feed.
 */

/**
 * Parse a feed.
 *
 * @param feed The feed that should be parsed, as a string.
 * @param options Optionally, options for parsing. When using this option, you should set `xmlMode` to `true`.
 */

/**
 * Parse an Atom feed.
 *
 * @param feedRoot The root of the feed.
 * @returns The parsed feed.
 */

/**
 * Parses data, returns an array of the root nodes.
 *
 * Note that the root nodes still have a `Document` node as their parent.
 * Use `parseDocument` to get the `Document` node instead.
 *
 * @param data The data that should be parsed.
 * @param options Optional options for the parser and DOM builder.
 * @deprecated Use `parseDocument` instead.
 */

/**
 * Parses the data, returns the resulting document.
 *
 * @param data The data that should be parsed.
 * @param options Optional options for the parser and DOM builder.
 */

/**
 * Prepend a child to an element.
 *
 * @param elem The element to prepend before.
 * @param child The element to be added as a child.
 */

/**
 * Prepend an element before another.
 *
 * @param elem The element to prepend before.
 * @param prev The element be added.
 */

/**
 * Processing instructions, including doc types.
 */

/**
 * Remove an element from the dom
 *
 * @param elem The element to be removed
 */

/**
 * Renders a DOM node or an array of DOM nodes to a string.
 *
 * Can be thought of as the equivalent of the `outerHTML` of the passed node(s).
 *
 * @param node Node to be rendered.
 * @param options Changes serialization behavior
 */

/**
 * Replace an element in the dom
 *
 * @param elem The element to be replaced
 * @param replacement The element to be added
 */

/**
 * Returns the next element sibling of a node.
 *
 * @param elem The element to get the next sibling of.
 * @returns `elem`'s next sibling that is a tag.
 */

/**
 * Returns the previous element sibling of a node.
 *
 * @param elem The element to get the previous sibling of.
 * @returns `elem`'s previous sibling that is a tag.
 */

/**
 * Search a node and its children for nodes passing a test function.
 *
 * @param test Function to test nodes on.
 * @param node Node to search. Will be included in the result set if it matches.
 * @param recurse Also consider child nodes.
 * @param limit Maximum number of nodes to return.
 * @returns All nodes passing `test`.
 */

/**
 * Search an array of node and its children for nodes passing a test function.
 *
 * @param test Function to test nodes on.
 * @param nodes Array of nodes to search.
 * @param recurse Also consider child nodes.
 * @param limit Maximum number of nodes to return.
 * @returns All nodes passing `test`.
 */

/**
 * Search and array of nodes and its children for nodes passing a test function.
 *
 * Same as `find`, only with less options, leading to reduced complexity.
 *
 * @param test Function to test nodes on.
 * @param nodes Array of nodes to search.
 * @returns All nodes passing `test`.
 */

/**
 * Self-enclosing tags
 */

/**
 * Sort an array of nodes based on their relative position in the document and
 * remove any duplicate nodes. If the array contains nodes that do not belong
 * to the same document, sort order is unspecified.
 *
 * @param nodes Array of DOM nodes.
 * @returns Collection of unique nodes, sorted in document order.
 */

/**
 * Srcset Parser
 *
 * By Alex Bell |  MIT License
 *
 * JS Parser for the string value that appears in markup <img srcset="here">
 *
 * @returns Array [{url: _, d: _, w: _, h:_}, ...]
 *
 * Based super duper closely on the reference algorithm at:
 * https://html.spec.whatwg.org/multipage/embedded-content.html#parse-a-srcset-attribute
 *
 * Most comments are copied in directly from the spec
 * (except for comments in parens).
 */

/**
 * Tests whether an element is a tag or not.
 *
 * @param elem Element to test
 */

/**
 * Text within the document.
 */

/**
 * The root node of the document.
 */

/** @class */

/** @deprecated Use these methods from `domhandler` directly. */

/** A data node that is still being written to. */

/** First child of the node. */

/** For special parsing behavior inside of script and style tags. */

/** Indicated whether parsing has been completed. */

/** Indicates whether the tokenizer has been paused. */

/** Indicates whether the tokenizer has finished running / `.end` has been called. */

/** Last child of the node. */

/** Next sibling */

/** Parent of the node */

/** Previous sibling */

/** Reference to the parser instance. Used for location information. */

/** Some behavior, eg. when decoding entities, is done while we are in another state. This keeps track of the other state type. */

/** Stack of open tags. */

/** The beginning of the section that is currently being read. */

/** The current state the tokenizer is in. */

/** The elements of the DOM */

/** The end index of the last event. */

/** The end index of the node. Requires `withEndIndices` on the handler to be `true. */

/** The index within the buffer that we are currently looking at. */

/** The read buffer. */

/** The root element for the DOM */

/** The start index of the last event. */

/** The start index of the node. Requires `withStartIndices` on the handler to be `true. */

/** Type for <!-- ... --> */

/** Type for <![CDATA[ ... ]]> */

/** Type for <!doctype ...> */

/** Type for <? ... ?> */

/** Type for <script> tags */

/** Type for <style> tags */

/** Type for Any tag */

/** Type for Text */

/** Type for the root element of a document */

/** Types of elements found in htmlparser2's DOM */

/***/

//

//		(1). Remove all trailing U+002C COMMA characters from url. If this removed

//         more than one character, that is a parse error.

//    and let that be url.

//    characters or U+002C COMMA characters. If any U+002C COMMA characters

//    of the string.

//    were collected, that is a parse error.

//   * unexpected-character-in-attribute-name

//   * unexpected-equals-sign-before-attribute-name

//   * unexpected-null-character

//  Do the following depending on the value of state.

//  For the purpose of this step, "EOF" is a special character representing

//  that position is past the end of input.

// ( Positive or negative or unsigned integers or decimals, without or without exponents.

// (Close of big while loop.)

// (Don't use \s, to avoid matching non-breaking space)

// (Jump ahead to step 9 to skip tokenization and just push the candidate).

// (close parseDescriptors fn)

// (close step 13 for loop)

// (close while true loop)

// (end "in descriptor"

// (we're done, this is the sole return path)

// /[^\0-\x7F]/gu

// 1. Let input be the value passed to this algorithm.

// 10. Let width be absent.

// 11. Let density be absent.

// 12. Let future-compat-h be absent. (We're implementing it now as h)

// 13. For each descriptor in descriptors, run the appropriate set of steps

// 15. If error is still no, then append a new image source to candidates whose

// 2. Let position be a pointer into input, initially pointing at the start

// 3. Let candidates be an initially empty source set.

// 4. Splitting loop: Collect a sequence of characters that are space

// 5. If position is past the end of input, return candidates and abort these steps.

// 6. Collect a sequence of characters that are not space characters,

// 7. Let descriptors be a new empty list.

// 8. If url ends with a U+002C COMMA character (,), follow these substeps:

// 8.1. Descriptor tokeniser: Skip whitespace

// 8.2. Let current descriptor be the empty string.

// 8.3. Let state be in descriptor.

// 8.4. Let c be the character at position.

// 9. Descriptor parser: Let error be no.

// A valid attribute name.

// According to spec tests any decimal point must be followed by a digit.

// Adapted from https://github.com/mathiasbynens/he/blob/master/src/he.js#L94-L119

// Add ranges to single characters.

// Add value to multiple array

// Add value to single array

// Advance position to the next character in input.

// Advance position to the next character in input. If current descriptor

// After descriptor

// Aliases

// Allow more characters after the first so we don't get faked

// Already had

// Already output />

// Also drop any whitespace at that point in the URL

// An attempt to exploit our workaround for base URLs being

// And because we need it after that one we do +1 to get the next one.

// Anything else

// Append c to current descriptor.

// Append c to current descriptor. Set state to in descriptor.

// Append c to current descriptor. Set state to in parens.

// Apply the rules for parsing floating-point number values to the descriptor.

// Apply the rules for parsing non-negative integers to the descriptor.

// Avoid false positives with .__proto__, .hasOwnProperty, etc.

// Browsers ignore character codes of 32 (space) and below in a surprising

// Build a placeholder "base URL" against which any reasonable

// Case insensitive so we don't get faked out by JAVASCRIPT #1

// Chrome accepts \ as a substitute for / in the // at the

// Clobber any comments in URLs, which the browser might

// Content sectioning

// DOM Level 1 aliases

// Declared outside of the while loop so that it's only created once.

// Default options

// Defaults are accessible to you so that you can use them as a starting point

// Detect style by other nodes

// Do not crash on bad markup

// Do the following, depending on the value of c:

// Else: stay in AFTER_CDATA_2 (`]]]>`)

// Else: stay in AFTER_COMMENT_2 (`--->`)

// Errors

// Escape characters with special meaning either inside or outside character sets.

// Exports for backwards compatibility

// Find the end of a run of characters

// Floating child without parent

// For entities terminated with a semicolon

// For other tags you would drop the tag but keep its content.

// Hack for first rule in CSS

// Handle SVG / MathML in HTML

// Helper methods

// Helpers

// Hook for Safe Parser

// If `enforceHtmlBoundary` is `true` and this has found the opening

// If current descriptor is not empty, append current descriptor to

// If entities weren't decoded, no need to encode them back

// If has modified constructor

// If has modified prototype

// If height and density are not both absent, then let error be yes.

// If inner text was set by transform function then let's use it

// If the descriptor consists of a valid non-negative integer followed by

// If the result is less than zero, let error be yes. Otherwise, let density

// If the result is zero, let error be yes.

// If the result is zero, let error be yes. Otherwise, let future-compat-h

// If the token is a word, e.g. `!important`, `red` or any other valid property's value.

// If there is remaining data, emit it in a reasonable way

// If this property is allowlisted...

// If we are not allowing these tags, we should drop their content too.

// If width and density are not both absent, then let error be yes.

// If width, density and future-compat-h are not all absent, then let error

// Ignore the _recursing flag; it's there for recursive

// Implicitly allows the class attribute

// In XML mode or foreign mode, and user hasn't explicitly turned off self-closing tags

// In descriptor

// In parens

// Inline text semantics

// Legacy aliases (deprecated)

// Locate the last sourceMappingURL to avoid pickin

// Lots of these won't come up by default because we don't allow them

// Make it possible to skip arguments, for backwards-compatibility

// Manual is faster than RegEx

// Merge global and tag-specific styles into new AST.

// Must include at least one digit.

// No leading plus sign is allowed.)

// No scheme

// Node inner text

// Offset = 1

// Otherwise, let width be the result.

// Parse as legacy entity, without allowing additional characters.

// Parse entity

// Parses legacy entities (without trailing semicolon)

// Protects from prototype poisoning and unexpected merging up the prototype chain.

// Protocol-relative URL starting with any combination of '/' and '\'

// Read-only aliases

// Read-write aliases for properties

// Remove 2 trailing chars

// Remove everything unnecessary

// Resets the handler back to starting state

// Retry as legacy entity if entity wasn't parsed

// Returns those elements of `a` for which `cb(a)` returns truthy

// Sections derived from MDN element categories and limited to the more

// Set state to after descriptor.

// Set state to in descriptor. Set position to the previous character in input.

// Signals the handler that parsing is done

// Skip everything until ">"

// Space character

// Space character: Stay in this state.

// TODO consider creating a merged map

// TODO: Consume data as it is coming in

// TODO: this is inadequate because it will pass `&0;`. This approach

// Table content

// Tags that contain something other than HTML, or where discarding

// Text content

// The characters accepted are ones which can be appended to the attribute

// The max length of legacy entities is 6

// The min length of legacy entities is 2

// The section just started

// Then we need to return the colon after that word token. [3] is the "end" colon of that word.

// This prevents part of an attribute name in the output from being

// Tokenizer event handlers

// U+0028 LEFT PARENTHESIS (()

// U+0029 RIGHT PARENTHESIS ())

// U+002C COMMA (,)

// URL is url, associated with a width width if not absent and a pixel

// URL parser, reject it

// URL schemes we permit

// UTILITY FUNCTIONS

// Unparseable iframe src

// Unparseable srcset

// Use a simple backslash escape when it’s always valid, and a \unnnn escape when the simpler form would be disallowed by Unicode patterns’ stricter grammar.

// Used for hot swapping the result variable with an empty string in order to "capture" the text written to it.

// User explicitly asked for self-closing tags, even in HTML mode

// We don't currently allow img itself by default, but

// We exclude the empty string because it's impossible to get to the after

// We know the stack has sufficient elements.

// We use a tolerant definition based on the set of strings defined by

// We want the contents but not this tag

// We want to replace at least three characters

// `html` tag, reset the state.

// `root` nodes in `document` should use only their own raws

// a U+0077 LATIN SMALL LETTER W character

// a javascript: URL to be snuck through

// and also unsafe if they're nonenumerable.

// and html.spec.whatwg.org/multipage/parsing.html#attribute-name-state .

// are cool. Here we are concerned just with allowed hostnames and

// as necessary if there are specific values defined.

// attribute name state with an empty attribute name buffer.

// be the result.

// be yes.

// benign categories.

// carriage return

// check allowedAttributesMap for the element and attribute and modify the value

// cloneUnlessOtherwiseSpecified is added to `options` so that custom arrayMerge()

// default value of allowIframeRelativeUrls is true

// density density if not absent. Otherwise, there is a parse error.

// descriptors and let current descriptor be the empty string.

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion

// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition

// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing

// eslint-disable-next-line no-console

// eslint-disable-next-line no-control-regex

// form feed

// from the following list:

// horizontal tab

// html.spec.whatwg.org/multipage/parsing.html#before-attribute-name-state

// htmlparser2 gives us these as-is. Escaping them ruins the content. Allowing

// http://bjorn.tipling.com/state-and-regular-expressions-in-javascript

// http://jsperf.com/whitespace-character/5

// http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae

// https://developer.mozilla.org/en-US/docs/Web/HTML/Element

// https://github.com/fb55/htmlparser2/issues/105

// https://html.spec.whatwg.org/multipage/infrastructure.html#valid-floating-point-number

// https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet#Embedded_tab

// if it is not. If this bothers you, don't set parser.decodeEntities

// implementations can use it. The caller may not replace it.

// interpret inside an XML data island, allowing

// interpreted as the end of an attribute, or end of a tag.

// invocation as a guard against this exploit:

// is followed by a 100% syntactically valid entity or not, and escaped

// is not empty, append current descriptor to descriptors. Jump to the step

// labeled descriptor parser.

// mandatory for relative URL validation in the WHATWG

// name buffer without triggering a parse error:

// naughtyHref is in charge of whether protocol relative URLs

// new line

// number of situations. Start reading here:

// out by certain schemes browsers accept

// programmatically if you wish

// relative URL may be parsed successfully

// script tags is, by definition, game over for XSS protection, so if that's

// see https://github.com/facebook/react/blob/b5ac963fb791d1298e7f396236383bc955f916c1/src/isomorphic/classic/element/ReactElement.js#L21-L25

// sourceMappingURLs from comments, strings, etc.

// space

// start of a URL, so rewrite accordingly to prevent exploit.

// the text when the tag is disallowed makes sense for other reasons.

// these attributes would make sense if we did.

// to false. (The default is true.)

// type needs to be passed to super, otherwise child roots won't be normalized correctly

// unless allowedIframeHostnames or allowedIframeDomains specified

// verified an allowed value matches the entire attribute value

// verify the values that are allowed

// vulnerableTags

// whether to allow relative URLs.

// which have their own collection of XSS vectors.

// will not work, each & must be considered with regard to whether it

// your concern, don't allow them. The same is essentially true for style tags
