Merge "Installer: don't treat the existance of main page as an error"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Tue, 24 Jan 2017 19:03:07 +0000 (19:03 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Tue, 24 Jan 2017 19:03:07 +0000 (19:03 +0000)
13 files changed:
includes/skins/SkinTemplate.php
includes/tidy/Balancer.php
resources/src/mediawiki.rcfilters/dm/mw.rcfilters.dm.FilterItem.js
resources/src/mediawiki.rcfilters/dm/mw.rcfilters.dm.FiltersViewModel.js
resources/src/mediawiki.rcfilters/styles/mw.rcfilters.ui.FilterCapsuleMultiselectWidget.less
resources/src/mediawiki.rcfilters/styles/mw.rcfilters.ui.FilterGroupWidget.less
resources/src/mediawiki.rcfilters/styles/mw.rcfilters.ui.FilterItemWidget.less
resources/src/mediawiki.rcfilters/ui/mw.rcfilters.ui.FilterGroupWidget.js
resources/src/mediawiki.rcfilters/ui/mw.rcfilters.ui.FilterItemWidget.js
resources/src/mediawiki.rcfilters/ui/mw.rcfilters.ui.FilterWrapperWidget.js
tests/phpunit/includes/tidy/BalancerTest.php
tests/phpunit/includes/tidy/html5lib-tests.json
tests/qunit/suites/resources/mediawiki.rcfilters/dm.FiltersViewModel.test.js

index 575a9ac..1a4554f 100644 (file)
@@ -1326,7 +1326,7 @@ class SkinTemplate extends Skin {
                                $nav_urls['userrights'] = [
                                        'text' => $this->msg(
                                                $canChange ? 'tool-link-userrights' : 'tool-link-userrights-readonly',
-                                               $this->getUser()->getName()
+                                               $rootUser
                                        )->text(),
                                        'href' => self::makeSpecialUrlSubpage( 'Userrights', $rootUser )
                                ];
index 95cbe09..8da1553 100644 (file)
@@ -75,7 +75,7 @@ class BalanceSets {
                self::HTML_NAMESPACE => [
                        'html' => true, 'head' => true, 'body' => true, 'frameset' => true,
                        'frame' => true,
-                       'plaintext' => true, 'isindex' => true,
+                       'plaintext' => true,
                        'xmp' => true, 'iframe' => true, 'noembed' => true,
                        'noscript' => true, 'script' => true,
                        'title' => true
@@ -119,9 +119,9 @@ class BalanceSets {
                        'h2' => true, 'h3' => true, 'h4' => true, 'h5' => true,
                        'h6' => true, 'head' => true, 'header' => true, 'hgroup' => true,
                        'hr' => true, 'html' => true, 'iframe' => true, 'img' => true,
-                       'input' => true, 'isindex' => true, 'li' => true, 'link' => true,
+                       'input' => true, 'li' => true, 'link' => true,
                        'listing' => true, 'main' => true, 'marquee' => true,
-                       'menu' => true, 'menuitem' => true, 'meta' => true, 'nav' => true,
+                       'menu' => true, 'meta' => true, 'nav' => true,
                        'noembed' => true, 'noframes' => true, 'noscript' => true,
                        'object' => true, 'ol' => true, 'p' => true, 'param' => true,
                        'plaintext' => true, 'pre' => true, 'script' => true,
@@ -156,7 +156,8 @@ class BalanceSets {
 
        public static $impliedEndTagsSet = [
                self::HTML_NAMESPACE => [
-                       'dd' => true, 'dt' => true, 'li' => true, 'optgroup' => true,
+                       'dd' => true, 'dt' => true, 'li' => true,
+                       'menuitem' => true, 'optgroup' => true,
                        'option' => true, 'p' => true, 'rb' => true, 'rp' => true,
                        'rt' => true, 'rtc' => true
                ]
@@ -498,6 +499,16 @@ class BalanceElement {
                                        $this->attribs = [ 'class' => "mw-empty-elt" ];
                                }
                                $blank = false;
+                       } elseif (
+                               $this->isA( BalanceSets::$extraLinefeedSet ) &&
+                               count( $this->children ) > 0 &&
+                               substr( $this->children[0], 0, 1 ) == "\n"
+                       ) {
+                               // Double the linefeed after pre/listing/textarea
+                               // according to the (old) HTML5 fragment serialization
+                               // algorithm (see https://github.com/whatwg/html/issues/944)
+                               // to ensure this will round-trip.
+                               array_unshift( $this->children, "\n" );
                        }
                        $flat = $blank ? '' : "{$this}";
                } else {
@@ -529,15 +540,6 @@ class BalanceElement {
                                $out .= "{$elt}";
                        }
                        $out .= "</{$this->localName}>";
-                       if (
-                               $this->isA( BalanceSets::$extraLinefeedSet ) &&
-                               $out[$len] === "\n"
-                       ) {
-                               // Double the linefeed after pre/listing/textarea
-                               // according to the HTML5 fragment serialization algorithm.
-                               $out = substr( $out, 0, $len + 1 ) .
-                                       substr( $out, $len );
-                       }
                } else {
                        $out = "<{$this->localName}{$encAttribs} />";
                        Assert::invariant(
@@ -1770,7 +1772,7 @@ class BalanceActiveFormattingElements {
  *   and escaped.
  * - All null characters are assumed to have been removed.
  * - The following elements are disallowed: <html>, <head>, <body>, <frameset>,
- *   <frame>, <plaintext>, <isindex>, <xmp>, <iframe>,
+ *   <frame>, <plaintext>, <xmp>, <iframe>,
  *   <noembed>, <noscript>, <script>, <title>.  As a result,
  *   further simplifications can be made:
  *   - `frameset-ok` is not tracked.
@@ -1865,7 +1867,9 @@ class Balancer {
         *         provide historical compatibility with the old "tidy"
         *         program: <p>-wrapping is done to the children of
         *         <body> and <blockquote> elements, and empty elements
-        *         are removed.
+        *         are removed.  The <pre>/<listing>/<textarea> serialization
+        *         is also tweaked to allow lossless round trips.
+        *         (See: https://github.com/whatwg/html/issues/944)
         *     'allowComments': boolean, defaults to true.
         *         When true, allows HTML comments in the input.
         *         The Sanitizer generally strips all comments, so if you
@@ -1997,6 +2001,7 @@ class Balancer {
                // Some hoops we have to jump through
                $adjusted = $this->stack->adjustedCurrentNode( $this->fragmentContext );
 
+               // The spec calls this the "tree construction dispatcher".
                $isForeign = true;
                if (
                        $this->stack->length() === 0 ||
@@ -2037,6 +2042,9 @@ class Balancer {
                if ( $token === 'text' ) {
                        $this->stack->insertText( $value );
                        return true;
+               } elseif ( $token === 'comment' ) {
+                       $this->stack->insertComment( $value );
+                       return true;
                } elseif ( $token === 'tag' ) {
                        switch ( $value ) {
                        case 'font':
@@ -2468,7 +2476,6 @@ class Balancer {
                        case 'header':
                        case 'hgroup':
                        case 'main':
-                       case 'menu':
                        case 'nav':
                        case 'ol':
                        case 'p':
@@ -2481,6 +2488,16 @@ class Balancer {
                                $this->stack->insertHTMLElement( $value, $attribs );
                                return true;
 
+                       case 'menu':
+                               if ( $this->stack->inButtonScope( "p" ) ) {
+                                       $this->inBodyMode( 'endtag', 'p' );
+                               }
+                               if ( $this->stack->currentNode->isHtmlNamed( 'menuitem' ) ) {
+                                       $this->stack->pop();
+                               }
+                               $this->stack->insertHTMLElement( $value, $attribs );
+                               return true;
+
                        case 'h1':
                        case 'h2':
                        case 'h3':
@@ -2656,7 +2673,6 @@ class Balancer {
                                // (hence we don't need to examine the tag's "type" attribute)
                                return true;
 
-                       case 'menuitem':
                        case 'param':
                        case 'source':
                        case 'track':
@@ -2668,6 +2684,9 @@ class Balancer {
                                if ( $this->stack->inButtonScope( 'p' ) ) {
                                        $this->inBodyMode( 'endtag', 'p' );
                                }
+                               if ( $this->stack->currentNode->isHtmlNamed( 'menuitem' ) ) {
+                                       $this->stack->pop();
+                               }
                                $this->stack->insertHTMLElement( $value, $attribs );
                                $this->stack->pop();
                                return true;
@@ -2676,8 +2695,6 @@ class Balancer {
                                // warts!
                                return $this->inBodyMode( $token, 'img', $attribs, $selfClose );
 
-                       // OMITTED: <isindex>
-
                        case 'textarea':
                                $this->stack->insertHTMLElement( $value, $attribs );
                                $this->ignoreLinefeed = true;
@@ -2715,6 +2732,14 @@ class Balancer {
                                $this->stack->insertHTMLElement( $value, $attribs );
                                return true;
 
+                       case 'menuitem':
+                               if ( $this->stack->currentNode->isHtmlNamed( 'menuitem' ) ) {
+                                       $this->stack->pop();
+                               }
+                               $this->afe->reconstruct( $this->stack );
+                               $this->stack->insertHTMLElement( $value, $attribs );
+                               return true;
+
                        case 'rb':
                        case 'rtc':
                                if ( $this->stack->inScope( 'ruby' ) ) {
index 63db0ea..f6fef5b 100644 (file)
@@ -11,6 +11,9 @@
         * @cfg {string} [label] The label for the filter
         * @cfg {string} [description] The description of the filter
         * @cfg {boolean} [selected] Filter is selected
+        * @cfg {boolean} [active=true] The filter is active and affecting the result
+        * @cfg {string[]} [excludes=[]] A list of filter names this filter, if
+        *  selected, makes inactive.
         */
        mw.rcfilters.dm.FilterItem = function MwRcfiltersDmFilterItem( name, config ) {
                config = config || {};
@@ -24,6 +27,8 @@
                this.description = config.description;
 
                this.selected = !!config.selected;
+               this.active = config.active === undefined ? true : !!config.active;
+               this.excludes = config.excludes || [];
        };
 
        /* Initialization */
                return this.selected;
        };
 
+       /**
+        * Check if this filter is active
+        *
+        * @return {boolean} Filter is active
+        */
+       mw.rcfilters.dm.FilterItem.prototype.isActive = function () {
+               return this.active;
+       };
+
+       /**
+        * Check if this filter has a list of excluded filters
+        *
+        * @return {boolean} Filter has a list of excluded filters
+        */
+       mw.rcfilters.dm.FilterItem.prototype.hasExcludedFilters = function () {
+               return !!this.excludes.length;
+       };
+
+       /**
+        * Get this filter's list of excluded filters
+        *
+        * @return {string[]} Array of excluded filter names
+        */
+       mw.rcfilters.dm.FilterItem.prototype.getExcludedFilters = function () {
+               return this.excludes;
+       };
+
+       /**
+        * Toggle the active state of the item
+        *
+        * @param {boolean} [isActive] Filter is active
+        * @fires update
+        */
+       mw.rcfilters.dm.FilterItem.prototype.toggleActive = function ( isActive ) {
+               isActive = isActive === undefined ? !this.active : isActive;
+
+               if ( this.active !== isActive ) {
+                       this.active = isActive;
+                       this.emit( 'update' );
+               }
+       };
+
        /**
         * Toggle the selected state of the item
         *
index 3217d0d..59a34f4 100644 (file)
                OO.EmitterList.call( this );
 
                this.groups = {};
+               this.excludedByMap = {};
 
                // Events
-               this.aggregate( { update: 'itemUpdate' } );
+               this.aggregate( { update: 'filterItemUpdate' } );
+               this.connect( this, { filterItemUpdate: 'onFilterItemUpdate' } );
        };
 
        /* Initialization */
 
        /* Methods */
 
+       /**
+        * Respond to filter item change.
+        *
+        * @param {mw.rcfilters.dm.FilterItem} item Updated filter
+        * @fires itemUpdate
+        */
+       mw.rcfilters.dm.FiltersViewModel.prototype.onFilterItemUpdate = function ( item ) {
+               // Reapply the active state of filters
+               this.reapplyActiveFilters( item );
+
+               this.emit( 'itemUpdate', item );
+       };
+
+       /**
+        * Calculate the active state of the filters, based on selected filters in the group.
+        *
+        * @param {mw.rcfilters.dm.FilterItem} item Changed item
+        */
+       mw.rcfilters.dm.FiltersViewModel.prototype.reapplyActiveFilters = function ( item ) {
+               var selectedItemsCount,
+                       group = item.getGroup(),
+                       model = this;
+               if (
+                       !this.groups[ group ].exclusionType ||
+                       this.groups[ group ].exclusionType === 'default'
+               ) {
+                       // Default behavior
+                       // If any parameter is selected, but:
+                       // - If there are unselected items in the group, they are inactive
+                       // - If the entire group is selected, all are inactive
+
+                       // Check what's selected in the group
+                       selectedItemsCount = this.groups[ group ].filters.filter( function ( filterItem ) {
+                               return filterItem.isSelected();
+                       } ).length;
+
+                       this.groups[ group ].filters.forEach( function ( filterItem ) {
+                               filterItem.toggleActive(
+                                       selectedItemsCount > 0 ?
+                                               // If some items are selected
+                                               (
+                                                       selectedItemsCount === model.groups[ group ].filters.length ?
+                                                       // If **all** items are selected, they're all inactive
+                                                       false :
+                                                       // If not all are selected, then the selected are active
+                                                       // and the unselected are inactive
+                                                       filterItem.isSelected()
+                                               ) :
+                                               // No item is selected, everything is active
+                                               true
+                               );
+                       } );
+               } else if ( this.groups[ group ].exclusionType === 'explicit' ) {
+                       // Explicit behavior
+                       // - Go over the list of excluded filters to change their
+                       //   active states accordingly
+
+                       // For each item in the list, see if there are other selected
+                       // filters that also exclude it. If it does, it will still be
+                       // inactive.
+
+                       item.getExcludedFilters().forEach( function ( filterName ) {
+                               var filterItem = model.getItemByName( filterName );
+
+                               // Note to reduce confusion:
+                               // - item is the filter whose state changed and should exclude the other filters
+                               //   in its list of exclusions
+                               // - filterItem is the filter that is potentially being excluded by the current item
+                               // - anotherExcludingFilter is any other filter that excludes filterItem; we must check
+                               //   if that filter is selected, because if it is, we should not touch the excluded item
+                               if (
+                                       // Check if there are any filters (other than the current one)
+                                       // that also exclude the filterName
+                                       !model.excludedByMap[ filterName ].some( function ( anotherExcludingFilterName ) {
+                                               var anotherExcludingFilter = model.getItemByName( anotherExcludingFilterName );
+
+                                               return (
+                                                       anotherExcludingFilterName !== item.getName() &&
+                                                       anotherExcludingFilter.isSelected()
+                                               );
+                                       } )
+                               ) {
+                                       // Only change the state for filters that aren't
+                                       // also affected by other excluding selected filters
+                                       filterItem.toggleActive( !item.isSelected() );
+                               }
+                       } );
+               }
+       };
+
        /**
         * Set filters and preserve a group relationship based on
         * the definition given by an object
         * @param {Object} filters Filter group definition
         */
        mw.rcfilters.dm.FiltersViewModel.prototype.initializeFilters = function ( filters ) {
-               var i, filterItem,
+               var i, filterItem, excludedFilters,
                        model = this,
-                       items = [];
+                       items = [],
+                       addToMap = function ( excludedFilters ) {
+                               excludedFilters.forEach( function ( filterName ) {
+                                       model.excludedByMap[ filterName ] = model.excludedByMap[ filterName ] || [];
+                                       model.excludedByMap[ filterName ].push( filterItem.getName() );
+                               } );
+                       };
 
                // Reset
                this.clearItems();
                this.groups = {};
+               this.excludedByMap = {};
 
                $.each( filters, function ( group, data ) {
                        model.groups[ group ] = model.groups[ group ] || {};
                        model.groups[ group ].title = data.title;
                        model.groups[ group ].type = data.type;
                        model.groups[ group ].separator = data.separator || '|';
+                       model.groups[ group ].exclusionType = data.exclusionType || 'default';
 
                        for ( i = 0; i < data.filters.length; i++ ) {
+                               excludedFilters = data.filters[ i ].excludes || [];
+
                                filterItem = new mw.rcfilters.dm.FilterItem( data.filters[ i ].name, {
                                        group: group,
                                        label: data.filters[ i ].label,
                                        description: data.filters[ i ].description,
-                                       selected: data.filters[ i ].selected
+                                       selected: data.filters[ i ].selected,
+                                       excludes: excludedFilters
                                } );
 
+                               // Map filters and what excludes them
+                               addToMap( excludedFilters );
+
                                model.groups[ group ].filters.push( filterItem );
                                items.push( filterItem );
                        }
        };
 
        /**
-        * Get the current state of the filters
+        * Get the current state of the filters.
+        *
+        * Checks whether the filter group is active. This means at least one
+        * filter is selected, but not all filters are selected.
         *
-        * @return {Object} Filters current state
+        * @param {string} groupName Group name
+        * @return {boolean} Filter group is active
         */
-       mw.rcfilters.dm.FiltersViewModel.prototype.getState = function () {
+       mw.rcfilters.dm.FiltersViewModel.prototype.isFilterGroupActive = function ( groupName ) {
+               var count = 0,
+                       filters = this.groups[ groupName ].filters;
+
+               filters.forEach( function ( filterItem ) {
+                       count += Number( filterItem.isSelected() );
+               } );
+
+               return (
+                       count > 0 &&
+                       count < filters.length
+               );
+       };
+
+       /**
+        * Update the representation of the parameters. These are the back-end
+        * parameters representing the filters, but they represent the given
+        * current state regardless of validity.
+        *
+        * This should only run after filters are already set.
+        *
+        * @param {Object} params Parameter state
+        */
+       mw.rcfilters.dm.FiltersViewModel.prototype.updateParameters = function ( params ) {
+               var model = this;
+
+               $.each( params, function ( name, value ) {
+                       // Only store the parameters that exist in the system
+                       if ( model.getItemByName( name ) ) {
+                               model.parameters[ name ] = value;
+                       }
+               } );
+       };
+
+       /**
+        * Get the value of a specific parameter
+        *
+        * @param {string} name Parameter name
+        * @return {number|string} Parameter value
+        */
+       mw.rcfilters.dm.FiltersViewModel.prototype.getParamValue = function ( name ) {
+               return this.parameters[ name ];
+       };
+
+       /**
+        * Get the current selected state of the filters
+        *
+        * @return {Object} Filters selected state
+        */
+       mw.rcfilters.dm.FiltersViewModel.prototype.getSelectedState = function () {
                var i,
                        items = this.getItems(),
                        result = {};
                return result;
        };
 
+       /**
+        * Get the current full state of the filters
+        *
+        * @return {Object} Filters full state
+        */
+       mw.rcfilters.dm.FiltersViewModel.prototype.getFullState = function () {
+               var i,
+                       items = this.getItems(),
+                       result = {};
+
+               for ( i = 0; i < items.length; i++ ) {
+                       result[ items[ i ].getName() ] = {
+                               selected: items[ i ].isSelected(),
+                               active: items[ i ].isActive()
+                       };
+               }
+
+               return result;
+       };
+
        /**
         * Analyze the groups and their filters and output an object representing
         * the state of the parameters they represent.
                        model = this,
                        base = this.getParametersFromFilters(),
                        // Start with current state
-                       result = this.getState();
+                       result = this.getSelectedState();
 
                params = $.extend( {}, base, params );
 
index 4e55add..ea1671b 100644 (file)
@@ -4,6 +4,10 @@
                color: #54595d;
        }
 
+       &-item-inactive {
+               opacity: 0.5;
+       }
+
        .oo-ui-capsuleItemWidget {
                color: #222;
                background-color: #fff;
index 70982d4..3723916 100644 (file)
@@ -8,6 +8,12 @@
                color: #555a5d;
        }
 
+       &-active {
+               .mw-rcfilters-ui-filterGroupWidget-title {
+                       font-weight: bold;
+               }
+       }
+
        &-invalid-notice {
                padding: 0.5em;
                font-style: italic;
index ad0b816..912e75c 100644 (file)
@@ -15,4 +15,8 @@
        .oo-ui-fieldLayout.oo-ui-fieldLayout-align-inline {
                margin-bottom: 0 !important;
        }
+
+       &-inactive {
+               opacity: 0.5;
+       }
 }
index 92ae4d1..2723258 100644 (file)
                return this.name;
        };
 
+       /**
+        * Toggle the active state of this group
+        *
+        * @param {boolean} isActive The group is active
+        */
+       mw.rcfilters.ui.FilterGroupWidget.prototype.toggleActiveState = function ( isActive ) {
+               this.$element.toggleClass( 'mw-rcfilters-ui-filterGroupWidget-active', isActive );
+       };
+
 }( mediaWiki, jQuery ) );
index b77df3b..f353051 100644 (file)
         */
        mw.rcfilters.ui.FilterItemWidget.prototype.onModelUpdate = function () {
                this.checkboxWidget.setSelected( this.model.isSelected() );
+
+               this.$element.toggleClass(
+                       'mw-rcfilters-ui-filterItemWidget-inactive',
+                       !this.model.isActive()
+               );
        };
 
        /**
index 3fcfc47..3353e54 100644 (file)
         * @param {mw.rcfilters.dm.FilterItem} item Filter item that was updated
         */
        mw.rcfilters.ui.FilterWrapperWidget.prototype.onModelItemUpdate = function ( item ) {
+               var widget = this;
+
                if ( item.isSelected() ) {
                        this.capsule.addItemsFromData( [ item.getName() ] );
+
+                       // Deal with active/inactive capsule filter items
+                       this.capsule.getItemFromData( item.getName() ).$element
+                               .toggleClass( 'mw-rcfilters-ui-filterCapsuleMultiselectWidget-item-inactive', !item.isActive() );
                } else {
                        this.capsule.removeItemsFromData( [ item.getName() ] );
                }
+
+               // Toggle the active state of the group
+               this.filterPopup.getItems().forEach( function ( groupWidget ) {
+                       if ( groupWidget.getName() === item.getGroup() ) {
+                               groupWidget.toggleActiveState( widget.model.isFilterGroupActive( groupWidget.getName() ) );
+                       }
+               } );
        };
 }( mediaWiki ) );
index f69ecaf..d93181c 100644 (file)
@@ -1,7 +1,6 @@
 <?php
 
 class BalancerTest extends MediaWikiTestCase {
-       private $balancer;
 
        /**
         * Anything that needs to happen before your tests should go here.
@@ -11,20 +10,20 @@ class BalancerTest extends MediaWikiTestCase {
                // This makes sure that all the various cleanup and restorations
                // happen as they should (including the restoration for setMwGlobals).
                parent::setUp();
-               $this->balancer = new MediaWiki\Tidy\Balancer( [
-                       'strict' => false, /* not strict */
-                       'allowedHtmlElements' => null, /* no sanitization */
-                       'tidyCompat' => false, /* standard parser */
-                       'allowComments' => true, /* comment parsing */
-               ] );
        }
 
        /**
         * @covers MediaWiki\Tidy\Balancer::balance
         * @dataProvider provideBalancerTests
         */
-       public function testBalancer( $description, $input, $expected ) {
-               $output = $this->balancer->balance( $input );
+       public function testBalancer( $description, $input, $expected, $useTidy ) {
+               $balancer = new MediaWiki\Tidy\Balancer( [
+                       'strict' => false, /* not strict */
+                       'allowedHtmlElements' => null, /* no sanitization */
+                       'tidyCompat' => $useTidy, /* standard parser */
+                       'allowComments' => true, /* comment parsing */
+               ] );
+               $output = $balancer->balance( $input );
 
                // Ignore self-closing tags
                $output = preg_replace( '/\s*\/>/', '>', $output );
@@ -86,7 +85,7 @@ class BalancerTest extends MediaWikiTestCase {
                                        // Skip tests involving unusual doctypes.
                                        continue;
                                }
-                               $literalre = "~ <rdar: | <isindex | < /? (
+                               $literalre = "~ <rdar: | < /? (
                                        html | head | body | frame | frameset | plaintext
                                ) > ~xi";
                                if ( preg_match( $literalre, $case['data'] ) ) {
@@ -146,10 +145,20 @@ class BalancerTest extends MediaWikiTestCase {
                                $tests[] = [
                                        $filename, # use better description?
                                        $data,
-                                       $html
+                                       $html,
+                                       false # strict HTML5 compat mode, no tidy
                                ];
                        }
                }
+
+               # Some additional tests for mediawiki-specific features
+               $tests[] = [
+                       'Round-trip serialization for <pre>/<listing>/<textarea>',
+                       "<pre>\n\na</pre><listing>\n\nb</listing><textarea>\n\nc</textarea>",
+                       "<pre>\n\na</pre><listing>\n\nb</listing><textarea>\n\nc</textarea>",
+                       true # use the tidy-compatible mode
+               ];
+
                return $tests;
        }
 }
index beb3659..2b1c3e8 100644 (file)
         "html": "<html><head></head><body><p><b><b><b><b></b></b></b></b></p><p><b><b><b>x</b></b></b></p></body></html>",
         "noQuirksBodyHtml": "<p><b><b><b><b></b></b></b></b></p><p><b><b><b>x</b></b></b></p>"
       }
+    },
+    {
+      "data": "<b><em><foo><foob><fooc><aside></b></em>",
+      "errors": [
+        "(1,35): adoption-agency-1.3",
+        "(1,40): adoption-agency-1.3",
+        "(1,40): expected-closing-tag-but-got-eof"
+      ],
+      "fragment": {
+        "name": "div"
+      },
+      "document": {
+        "props": {
+          "tags": {
+            "b": true,
+            "em": true,
+            "foo": true,
+            "foob": true,
+            "fooc": true,
+            "aside": true
+          }
+        },
+        "tree": [
+          {
+            "tag": "b",
+            "children": [
+              {
+                "tag": "em",
+                "children": [
+                  {
+                    "tag": "foo",
+                    "children": [
+                      {
+                        "tag": "foob",
+                        "children": [
+                          {
+                            "tag": "fooc"
+                          }
+                        ]
+                      }
+                    ]
+                  }
+                ]
+              }
+            ]
+          },
+          {
+            "tag": "aside",
+            "children": [
+              {
+                "tag": "b"
+              }
+            ]
+          }
+        ],
+        "html": "<b><em><foo><foob><fooc></fooc></foob></foo></em></b><aside><b></b></aside>",
+        "noQuirksBodyHtml": "<b><em><foo><foob><fooc></fooc></foob></foo></em></b><aside><b></b></aside>"
+      }
     }
   ],
   "adoption02.dat": [
       "data": "FOO&#11111111111ZOO",
       "errors": [
         "(1,3): expected-doctype-but-got-chars",
-        "(1,13): illegal-codepoint-for-numeric-entity"
+        "(1,16): numeric-entity-without-semicolon",
+        "(1,16): illegal-codepoint-for-numeric-entity"
       ],
       "document": {
         "props": {
       "data": "FOO&#1111111111ZOO",
       "errors": [
         "(1,3): expected-doctype-but-got-chars",
-        "(1,13): illegal-codepoint-for-numeric-entity"
+        "(1,15): numeric-entity-without-semicolon",
+        "(1,15): illegal-codepoint-for-numeric-entity"
       ],
       "document": {
         "props": {
       "data": "FOO&#111111111111ZOO",
       "errors": [
         "(1,3): expected-doctype-but-got-chars",
-        "(1,13): illegal-codepoint-for-numeric-entity"
+        "(1,17): numeric-entity-without-semicolon",
+        "(1,17): illegal-codepoint-for-numeric-entity"
       ],
       "document": {
         "props": {
     {
       "data": "<plaintext><foo>",
       "errors": [
-        "16: End of file seen and there were open elements.",
-        "11: Unclosed element “plaintext”."
+        "(1,16): expected-closing-tag-but-got-eof"
       ],
       "fragment": {
         "name": "desc",
       "data": "<isindex>",
       "errors": [
         "(1,9): expected-doctype-but-got-start-tag",
-        "(1,9): deprecated-tag"
+        "(1,9): expected-closing-tag-but-got-eof"
       ],
       "document": {
         "props": {
             "html": true,
             "head": true,
             "body": true,
-            "form": true,
-            "hr": true,
-            "label": true,
-            "input": true
+            "isindex": true
           }
         },
         "tree": [
                 "tag": "body",
                 "children": [
                   {
-                    "tag": "form",
-                    "children": [
-                      {
-                        "tag": "hr"
-                      },
-                      {
-                        "tag": "label",
-                        "children": [
-                          {
-                            "text": "This is a searchable index. Enter search keywords: "
-                          },
-                          {
-                            "tag": "input",
-                            "attrs": [
-                              {
-                                "name": "name",
-                                "value": "isindex"
-                              }
-                            ]
-                          }
-                        ]
-                      },
-                      {
-                        "tag": "hr"
-                      }
-                    ]
+                    "tag": "isindex"
                   }
                 ]
               }
             ]
           }
         ],
-        "html": "<html><head></head><body><form><hr><label>This is a searchable index. Enter search keywords: <input name=\"isindex\"></label><hr></form></body></html>",
-        "noQuirksBodyHtml": "<form><hr><label>This is a searchable index. Enter search keywords: <input name=\"isindex\"></label><hr></form>"
+        "html": "<html><head></head><body><isindex></isindex></body></html>",
+        "noQuirksBodyHtml": "<isindex></isindex>"
       }
     },
     {
       "data": "<isindex name=\"A\" action=\"B\" prompt=\"C\" foo=\"D\">",
       "errors": [
         "(1,48): expected-doctype-but-got-start-tag",
-        "(1,48): deprecated-tag"
+        "(1,48): expected-closing-tag-but-got-eof"
       ],
       "document": {
         "props": {
             "html": true,
             "head": true,
             "body": true,
-            "form": true,
-            "hr": true,
-            "label": true,
-            "input": true
+            "isindex": true
           }
         },
         "tree": [
                 "tag": "body",
                 "children": [
                   {
-                    "tag": "form",
+                    "tag": "isindex",
                     "attrs": [
                       {
                         "name": "action",
                         "value": "B"
-                      }
-                    ],
-                    "children": [
+                      },
                       {
-                        "tag": "hr"
+                        "name": "foo",
+                        "value": "D"
                       },
                       {
-                        "tag": "label",
-                        "children": [
-                          {
-                            "text": "C"
-                          },
-                          {
-                            "tag": "input",
-                            "attrs": [
-                              {
-                                "name": "foo",
-                                "value": "D"
-                              },
-                              {
-                                "name": "name",
-                                "value": "isindex"
-                              }
-                            ]
-                          }
-                        ]
+                        "name": "name",
+                        "value": "A"
                       },
                       {
-                        "tag": "hr"
+                        "name": "prompt",
+                        "value": "C"
                       }
                     ]
                   }
             ]
           }
         ],
-        "html": "<html><head></head><body><form action=\"B\"><hr><label>C<input name=\"isindex\" foo=\"D\"></label><hr></form></body></html>",
-        "noQuirksBodyHtml": "<form action=\"B\"><hr><label>C<input name=\"isindex\" foo=\"D\"></label><hr></form>"
+        "html": "<html><head></head><body><isindex name=\"A\" action=\"B\" prompt=\"C\" foo=\"D\"></isindex></body></html>",
+        "noQuirksBodyHtml": "<isindex name=\"A\" action=\"B\" prompt=\"C\" foo=\"D\"></isindex>"
       }
     },
     {
       "data": "<form><isindex>",
       "errors": [
         "(1,6): expected-doctype-but-got-start-tag",
-        "(1,15): deprecated-tag",
         "(1,15): expected-closing-tag-but-got-eof"
       ],
       "document": {
             "html": true,
             "head": true,
             "body": true,
-            "form": true
+            "form": true,
+            "isindex": true
           }
         },
         "tree": [
                 "tag": "body",
                 "children": [
                   {
-                    "tag": "form"
+                    "tag": "form",
+                    "children": [
+                      {
+                        "tag": "isindex"
+                      }
+                    ]
                   }
                 ]
               }
             ]
           }
         ],
-        "html": "<html><head></head><body><form></form></body></html>",
-        "noQuirksBodyHtml": "<form></form>"
+        "html": "<html><head></head><body><form><isindex></isindex></form></body></html>",
+        "noQuirksBodyHtml": "<form><isindex></isindex></form>"
+      }
+    },
+    {
+      "data": "<!doctype html><isindex>x</isindex>x",
+      "errors": [],
+      "document": {
+        "props": {
+          "tags": {
+            "html": true,
+            "head": true,
+            "body": true,
+            "isindex": true
+          },
+          "doctype": true
+        },
+        "tree": [
+          {
+            "doctype": "html"
+          },
+          {
+            "tag": "html",
+            "children": [
+              {
+                "tag": "head"
+              },
+              {
+                "tag": "body",
+                "children": [
+                  {
+                    "tag": "isindex",
+                    "children": [
+                      {
+                        "text": "x"
+                      }
+                    ]
+                  },
+                  {
+                    "text": "x"
+                  }
+                ]
+              }
+            ]
+          }
+        ],
+        "html": "<!DOCTYPE html><html><head></head><body><isindex>x</isindex>x</body></html>",
+        "noQuirksBodyHtml": "<isindex>x</isindex>x"
       }
     }
   ],
       }
     },
     {
-      "data": "<!doctype html><main><p>foo</main>bar",
-      "errors": [],
+      "data": "<!doctype html><main><p>foo</main>bar",
+      "errors": [],
+      "document": {
+        "props": {
+          "tags": {
+            "html": true,
+            "head": true,
+            "body": true,
+            "main": true,
+            "p": true
+          },
+          "doctype": true
+        },
+        "tree": [
+          {
+            "doctype": "html"
+          },
+          {
+            "tag": "html",
+            "children": [
+              {
+                "tag": "head"
+              },
+              {
+                "tag": "body",
+                "children": [
+                  {
+                    "tag": "main",
+                    "children": [
+                      {
+                        "tag": "p",
+                        "children": [
+                          {
+                            "text": "foo"
+                          }
+                        ]
+                      }
+                    ]
+                  },
+                  {
+                    "text": "bar"
+                  }
+                ]
+              }
+            ]
+          }
+        ],
+        "html": "<!DOCTYPE html><html><head></head><body><main><p>foo</p></main>bar</body></html>",
+        "noQuirksBodyHtml": "<main><p>foo</p></main>bar"
+      }
+    },
+    {
+      "data": "<!DOCTYPE html>xxx<svg><x><g><a><main><b>",
+      "errors": [
+        " * (1,42) unexpected HTML-like start tag token in foreign content",
+        " * (1,42) unexpected end of file"
+      ],
+      "document": {
+        "props": {
+          "tags": {
+            "html": true,
+            "head": true,
+            "body": true,
+            "svg svg": true,
+            "svg x": true,
+            "svg g": true,
+            "svg a": true,
+            "svg main": true,
+            "b": true
+          },
+          "doctype": true
+        },
+        "tree": [
+          {
+            "doctype": "html"
+          },
+          {
+            "tag": "html",
+            "children": [
+              {
+                "tag": "head"
+              },
+              {
+                "tag": "body",
+                "children": [
+                  {
+                    "text": "xxx"
+                  },
+                  {
+                    "tag": "svg",
+                    "ns": "http://www.w3.org/2000/svg",
+                    "children": [
+                      {
+                        "tag": "x",
+                        "ns": "http://www.w3.org/2000/svg",
+                        "children": [
+                          {
+                            "tag": "g",
+                            "ns": "http://www.w3.org/2000/svg",
+                            "children": [
+                              {
+                                "tag": "a",
+                                "ns": "http://www.w3.org/2000/svg",
+                                "children": [
+                                  {
+                                    "tag": "main",
+                                    "ns": "http://www.w3.org/2000/svg"
+                                  }
+                                ]
+                              }
+                            ]
+                          }
+                        ]
+                      }
+                    ]
+                  },
+                  {
+                    "tag": "b"
+                  }
+                ]
+              }
+            ]
+          }
+        ],
+        "html": "<!DOCTYPE html><html><head></head><body>xxx<svg><x><g><a><main></main></a></g></x></svg><b></b></body></html>",
+        "noQuirksBodyHtml": "xxx<svg><x><g><a><main><b></b></main></a></g></x></svg>"
+      }
+    }
+  ],
+  "math.dat": [
+    {
+      "data": "<math><tr><td><mo><tr>",
+      "errors": [],
+      "fragment": {
+        "name": "td"
+      },
+      "document": {
+        "props": {
+          "tags": {
+            "math math": true,
+            "math tr": true,
+            "math td": true,
+            "math mo": true
+          }
+        },
+        "tree": [
+          {
+            "tag": "math",
+            "ns": "http://www.w3.org/1998/Math/MathML",
+            "children": [
+              {
+                "tag": "tr",
+                "ns": "http://www.w3.org/1998/Math/MathML",
+                "children": [
+                  {
+                    "tag": "td",
+                    "ns": "http://www.w3.org/1998/Math/MathML",
+                    "children": [
+                      {
+                        "tag": "mo",
+                        "ns": "http://www.w3.org/1998/Math/MathML"
+                      }
+                    ]
+                  }
+                ]
+              }
+            ]
+          }
+        ],
+        "html": "<math><tr><td><mo></mo></td></tr></math>",
+        "noQuirksBodyHtml": "<math><tr><td><mo></mo></td></tr></math>"
+      }
+    },
+    {
+      "data": "<math><tr><td><mo><tr>",
+      "errors": [],
+      "fragment": {
+        "name": "tr"
+      },
+      "document": {
+        "props": {
+          "tags": {
+            "math math": true,
+            "math tr": true,
+            "math td": true,
+            "math mo": true
+          }
+        },
+        "tree": [
+          {
+            "tag": "math",
+            "ns": "http://www.w3.org/1998/Math/MathML",
+            "children": [
+              {
+                "tag": "tr",
+                "ns": "http://www.w3.org/1998/Math/MathML",
+                "children": [
+                  {
+                    "tag": "td",
+                    "ns": "http://www.w3.org/1998/Math/MathML",
+                    "children": [
+                      {
+                        "tag": "mo",
+                        "ns": "http://www.w3.org/1998/Math/MathML"
+                      }
+                    ]
+                  }
+                ]
+              }
+            ]
+          }
+        ],
+        "html": "<math><tr><td><mo></mo></td></tr></math>",
+        "noQuirksBodyHtml": "<math><tr><td><mo></mo></td></tr></math>"
+      }
+    },
+    {
+      "data": "<math><thead><mo><tbody>",
+      "errors": [],
+      "fragment": {
+        "name": "thead"
+      },
+      "document": {
+        "props": {
+          "tags": {
+            "math math": true,
+            "math thead": true,
+            "math mo": true
+          }
+        },
+        "tree": [
+          {
+            "tag": "math",
+            "ns": "http://www.w3.org/1998/Math/MathML",
+            "children": [
+              {
+                "tag": "thead",
+                "ns": "http://www.w3.org/1998/Math/MathML",
+                "children": [
+                  {
+                    "tag": "mo",
+                    "ns": "http://www.w3.org/1998/Math/MathML"
+                  }
+                ]
+              }
+            ]
+          }
+        ],
+        "html": "<math><thead><mo></mo></thead></math>",
+        "noQuirksBodyHtml": "<math><thead><mo></mo></thead></math>"
+      }
+    },
+    {
+      "data": "<math><tfoot><mo><tbody>",
+      "errors": [],
+      "fragment": {
+        "name": "tfoot"
+      },
+      "document": {
+        "props": {
+          "tags": {
+            "math math": true,
+            "math tfoot": true,
+            "math mo": true
+          }
+        },
+        "tree": [
+          {
+            "tag": "math",
+            "ns": "http://www.w3.org/1998/Math/MathML",
+            "children": [
+              {
+                "tag": "tfoot",
+                "ns": "http://www.w3.org/1998/Math/MathML",
+                "children": [
+                  {
+                    "tag": "mo",
+                    "ns": "http://www.w3.org/1998/Math/MathML"
+                  }
+                ]
+              }
+            ]
+          }
+        ],
+        "html": "<math><tfoot><mo></mo></tfoot></math>",
+        "noQuirksBodyHtml": "<math><tfoot><mo></mo></tfoot></math>"
+      }
+    },
+    {
+      "data": "<math><tbody><mo><tfoot>",
+      "errors": [],
+      "fragment": {
+        "name": "tbody"
+      },
+      "document": {
+        "props": {
+          "tags": {
+            "math math": true,
+            "math tbody": true,
+            "math mo": true
+          }
+        },
+        "tree": [
+          {
+            "tag": "math",
+            "ns": "http://www.w3.org/1998/Math/MathML",
+            "children": [
+              {
+                "tag": "tbody",
+                "ns": "http://www.w3.org/1998/Math/MathML",
+                "children": [
+                  {
+                    "tag": "mo",
+                    "ns": "http://www.w3.org/1998/Math/MathML"
+                  }
+                ]
+              }
+            ]
+          }
+        ],
+        "html": "<math><tbody><mo></mo></tbody></math>",
+        "noQuirksBodyHtml": "<math><tbody><mo></mo></tbody></math>"
+      }
+    },
+    {
+      "data": "<math><tbody><mo></table>",
+      "errors": [],
+      "fragment": {
+        "name": "tbody"
+      },
+      "document": {
+        "props": {
+          "tags": {
+            "math math": true,
+            "math tbody": true,
+            "math mo": true
+          }
+        },
+        "tree": [
+          {
+            "tag": "math",
+            "ns": "http://www.w3.org/1998/Math/MathML",
+            "children": [
+              {
+                "tag": "tbody",
+                "ns": "http://www.w3.org/1998/Math/MathML",
+                "children": [
+                  {
+                    "tag": "mo",
+                    "ns": "http://www.w3.org/1998/Math/MathML"
+                  }
+                ]
+              }
+            ]
+          }
+        ],
+        "html": "<math><tbody><mo></mo></tbody></math>",
+        "noQuirksBodyHtml": "<math><tbody><mo></mo></tbody></math>"
+      }
+    },
+    {
+      "data": "<math><thead><mo></table>",
+      "errors": [],
+      "fragment": {
+        "name": "tbody"
+      },
+      "document": {
+        "props": {
+          "tags": {
+            "math math": true,
+            "math thead": true,
+            "math mo": true
+          }
+        },
+        "tree": [
+          {
+            "tag": "math",
+            "ns": "http://www.w3.org/1998/Math/MathML",
+            "children": [
+              {
+                "tag": "thead",
+                "ns": "http://www.w3.org/1998/Math/MathML",
+                "children": [
+                  {
+                    "tag": "mo",
+                    "ns": "http://www.w3.org/1998/Math/MathML"
+                  }
+                ]
+              }
+            ]
+          }
+        ],
+        "html": "<math><thead><mo></mo></thead></math>",
+        "noQuirksBodyHtml": "<math><thead><mo></mo></thead></math>"
+      }
+    },
+    {
+      "data": "<math><tfoot><mo></table>",
+      "errors": [],
+      "fragment": {
+        "name": "tbody"
+      },
+      "document": {
+        "props": {
+          "tags": {
+            "math math": true,
+            "math tfoot": true,
+            "math mo": true
+          }
+        },
+        "tree": [
+          {
+            "tag": "math",
+            "ns": "http://www.w3.org/1998/Math/MathML",
+            "children": [
+              {
+                "tag": "tfoot",
+                "ns": "http://www.w3.org/1998/Math/MathML",
+                "children": [
+                  {
+                    "tag": "mo",
+                    "ns": "http://www.w3.org/1998/Math/MathML"
+                  }
+                ]
+              }
+            ]
+          }
+        ],
+        "html": "<math><tfoot><mo></mo></tfoot></math>",
+        "noQuirksBodyHtml": "<math><tfoot><mo></mo></tfoot></math>"
+      }
+    }
+  ],
+  "menuitem-element.dat": [
+    {
+      "data": "<menuitem>",
+      "errors": [
+        "10: Start tag seen without seeing a doctype first. Expected “<!DOCTYPE html>”."
+      ],
+      "document": {
+        "props": {
+          "tags": {
+            "html": true,
+            "head": true,
+            "body": true,
+            "menuitem": true
+          }
+        },
+        "tree": [
+          {
+            "tag": "html",
+            "children": [
+              {
+                "tag": "head"
+              },
+              {
+                "tag": "body",
+                "children": [
+                  {
+                    "tag": "menuitem"
+                  }
+                ]
+              }
+            ]
+          }
+        ],
+        "html": "<html><head></head><body><menuitem></menuitem></body></html>",
+        "noQuirksBodyHtml": "<menuitem></menuitem>"
+      }
+    },
+    {
+      "data": "</menuitem>",
+      "errors": [
+        "11: End tag seen without seeing a doctype first. Expected “<!DOCTYPE html>”.",
+        "11: Stray end tag “menuitem”."
+      ],
+      "document": {
+        "props": {
+          "tags": {
+            "html": true,
+            "head": true,
+            "body": true
+          }
+        },
+        "tree": [
+          {
+            "tag": "html",
+            "children": [
+              {
+                "tag": "head"
+              },
+              {
+                "tag": "body"
+              }
+            ]
+          }
+        ],
+        "html": "<html><head></head><body></body></html>",
+        "noQuirksBodyHtml": ""
+      }
+    },
+    {
+      "data": "<!DOCTYPE html><body><menuitem>A",
+      "errors": [],
+      "document": {
+        "props": {
+          "tags": {
+            "html": true,
+            "head": true,
+            "body": true,
+            "menuitem": true
+          },
+          "doctype": true
+        },
+        "tree": [
+          {
+            "doctype": "html"
+          },
+          {
+            "tag": "html",
+            "children": [
+              {
+                "tag": "head"
+              },
+              {
+                "tag": "body",
+                "children": [
+                  {
+                    "tag": "menuitem",
+                    "children": [
+                      {
+                        "text": "A"
+                      }
+                    ]
+                  }
+                ]
+              }
+            ]
+          }
+        ],
+        "html": "<!DOCTYPE html><html><head></head><body><menuitem>A</menuitem></body></html>",
+        "noQuirksBodyHtml": "<menuitem>A</menuitem>"
+      }
+    },
+    {
+      "data": "<!DOCTYPE html><body><menuitem>A<menuitem>B",
+      "errors": [],
+      "document": {
+        "props": {
+          "tags": {
+            "html": true,
+            "head": true,
+            "body": true,
+            "menuitem": true
+          },
+          "doctype": true
+        },
+        "tree": [
+          {
+            "doctype": "html"
+          },
+          {
+            "tag": "html",
+            "children": [
+              {
+                "tag": "head"
+              },
+              {
+                "tag": "body",
+                "children": [
+                  {
+                    "tag": "menuitem",
+                    "children": [
+                      {
+                        "text": "A"
+                      }
+                    ]
+                  },
+                  {
+                    "tag": "menuitem",
+                    "children": [
+                      {
+                        "text": "B"
+                      }
+                    ]
+                  }
+                ]
+              }
+            ]
+          }
+        ],
+        "html": "<!DOCTYPE html><html><head></head><body><menuitem>A</menuitem><menuitem>B</menuitem></body></html>",
+        "noQuirksBodyHtml": "<menuitem>A</menuitem><menuitem>B</menuitem>"
+      }
+    },
+    {
+      "data": "<!DOCTYPE html><body><menuitem>A<menu>B</menu>",
+      "errors": [],
+      "document": {
+        "props": {
+          "tags": {
+            "html": true,
+            "head": true,
+            "body": true,
+            "menuitem": true,
+            "menu": true
+          },
+          "doctype": true
+        },
+        "tree": [
+          {
+            "doctype": "html"
+          },
+          {
+            "tag": "html",
+            "children": [
+              {
+                "tag": "head"
+              },
+              {
+                "tag": "body",
+                "children": [
+                  {
+                    "tag": "menuitem",
+                    "children": [
+                      {
+                        "text": "A"
+                      }
+                    ]
+                  },
+                  {
+                    "tag": "menu",
+                    "children": [
+                      {
+                        "text": "B"
+                      }
+                    ]
+                  }
+                ]
+              }
+            ]
+          }
+        ],
+        "html": "<!DOCTYPE html><html><head></head><body><menuitem>A</menuitem><menu>B</menu></body></html>",
+        "noQuirksBodyHtml": "<menuitem>A</menuitem><menu>B</menu>"
+      }
+    },
+    {
+      "data": "<!DOCTYPE html><body><menuitem>A<hr>B",
+      "errors": [],
+      "document": {
+        "props": {
+          "tags": {
+            "html": true,
+            "head": true,
+            "body": true,
+            "menuitem": true,
+            "hr": true
+          },
+          "doctype": true
+        },
+        "tree": [
+          {
+            "doctype": "html"
+          },
+          {
+            "tag": "html",
+            "children": [
+              {
+                "tag": "head"
+              },
+              {
+                "tag": "body",
+                "children": [
+                  {
+                    "tag": "menuitem",
+                    "children": [
+                      {
+                        "text": "A"
+                      }
+                    ]
+                  },
+                  {
+                    "tag": "hr"
+                  },
+                  {
+                    "text": "B"
+                  }
+                ]
+              }
+            ]
+          }
+        ],
+        "html": "<!DOCTYPE html><html><head></head><body><menuitem>A</menuitem><hr>B</body></html>",
+        "noQuirksBodyHtml": "<menuitem>A</menuitem><hr>B"
+      }
+    },
+    {
+      "data": "<!DOCTYPE html><li><menuitem><li>",
+      "errors": [],
+      "document": {
+        "props": {
+          "tags": {
+            "html": true,
+            "head": true,
+            "body": true,
+            "li": true,
+            "menuitem": true
+          },
+          "doctype": true
+        },
+        "tree": [
+          {
+            "doctype": "html"
+          },
+          {
+            "tag": "html",
+            "children": [
+              {
+                "tag": "head"
+              },
+              {
+                "tag": "body",
+                "children": [
+                  {
+                    "tag": "li",
+                    "children": [
+                      {
+                        "tag": "menuitem"
+                      }
+                    ]
+                  },
+                  {
+                    "tag": "li"
+                  }
+                ]
+              }
+            ]
+          }
+        ],
+        "html": "<!DOCTYPE html><html><head></head><body><li><menuitem></menuitem></li><li></li></body></html>",
+        "noQuirksBodyHtml": "<li><menuitem></menuitem></li><li></li>"
+      }
+    },
+    {
+      "data": "<!DOCTYPE html><menuitem><p></menuitem>x",
+      "errors": [
+        "39: Stray end tag “menuitem”."
+      ],
+      "document": {
+        "props": {
+          "tags": {
+            "html": true,
+            "head": true,
+            "body": true,
+            "menuitem": true,
+            "p": true
+          },
+          "doctype": true
+        },
+        "tree": [
+          {
+            "doctype": "html"
+          },
+          {
+            "tag": "html",
+            "children": [
+              {
+                "tag": "head"
+              },
+              {
+                "tag": "body",
+                "children": [
+                  {
+                    "tag": "menuitem",
+                    "children": [
+                      {
+                        "tag": "p",
+                        "children": [
+                          {
+                            "text": "x"
+                          }
+                        ]
+                      }
+                    ]
+                  }
+                ]
+              }
+            ]
+          }
+        ],
+        "html": "<!DOCTYPE html><html><head></head><body><menuitem><p>x</p></menuitem></body></html>",
+        "noQuirksBodyHtml": "<menuitem><p>x</p></menuitem>"
+      }
+    },
+    {
+      "data": "<!DOCTYPE html><p><b></p><menuitem>",
+      "errors": [
+        "25: End tag “p” seen, but there were open elements.",
+        "21: Unclosed element “b”.",
+        "35: End of file seen and there were open elements."
+      ],
+      "document": {
+        "props": {
+          "tags": {
+            "html": true,
+            "head": true,
+            "body": true,
+            "p": true,
+            "b": true,
+            "menuitem": true
+          },
+          "doctype": true
+        },
+        "tree": [
+          {
+            "doctype": "html"
+          },
+          {
+            "tag": "html",
+            "children": [
+              {
+                "tag": "head"
+              },
+              {
+                "tag": "body",
+                "children": [
+                  {
+                    "tag": "p",
+                    "children": [
+                      {
+                        "tag": "b"
+                      }
+                    ]
+                  },
+                  {
+                    "tag": "b",
+                    "children": [
+                      {
+                        "tag": "menuitem"
+                      }
+                    ]
+                  }
+                ]
+              }
+            ]
+          }
+        ],
+        "html": "<!DOCTYPE html><html><head></head><body><p><b></b></p><b><menuitem></menuitem></b></body></html>",
+        "noQuirksBodyHtml": "<p><b></b></p><b><menuitem></menuitem></b>"
+      }
+    },
+    {
+      "data": "<!DOCTYPE html><menuitem><asdf></menuitem>x",
+      "errors": [
+        "40: End tag “menuitem” seen, but there were open elements.",
+        "31: Unclosed element “asdf”."
+      ],
+      "document": {
+        "props": {
+          "tags": {
+            "html": true,
+            "head": true,
+            "body": true,
+            "menuitem": true,
+            "asdf": true
+          },
+          "doctype": true
+        },
+        "tree": [
+          {
+            "doctype": "html"
+          },
+          {
+            "tag": "html",
+            "children": [
+              {
+                "tag": "head"
+              },
+              {
+                "tag": "body",
+                "children": [
+                  {
+                    "tag": "menuitem",
+                    "children": [
+                      {
+                        "tag": "asdf"
+                      }
+                    ]
+                  },
+                  {
+                    "text": "x"
+                  }
+                ]
+              }
+            ]
+          }
+        ],
+        "html": "<!DOCTYPE html><html><head></head><body><menuitem><asdf></asdf></menuitem>x</body></html>",
+        "noQuirksBodyHtml": "<menuitem><asdf></asdf></menuitem>x"
+      }
+    },
+    {
+      "data": "<!DOCTYPE html></menuitem>",
+      "errors": [
+        "26: Stray end tag “menuitem”."
+      ],
+      "document": {
+        "props": {
+          "tags": {
+            "html": true,
+            "head": true,
+            "body": true
+          },
+          "doctype": true
+        },
+        "tree": [
+          {
+            "doctype": "html"
+          },
+          {
+            "tag": "html",
+            "children": [
+              {
+                "tag": "head"
+              },
+              {
+                "tag": "body"
+              }
+            ]
+          }
+        ],
+        "html": "<!DOCTYPE html><html><head></head><body></body></html>",
+        "noQuirksBodyHtml": ""
+      }
+    },
+    {
+      "data": "<!DOCTYPE html><html></menuitem>",
+      "errors": [
+        "26: Stray end tag “menuitem”."
+      ],
+      "document": {
+        "props": {
+          "tags": {
+            "html": true,
+            "head": true,
+            "body": true
+          },
+          "doctype": true
+        },
+        "tree": [
+          {
+            "doctype": "html"
+          },
+          {
+            "tag": "html",
+            "children": [
+              {
+                "tag": "head"
+              },
+              {
+                "tag": "body"
+              }
+            ]
+          }
+        ],
+        "html": "<!DOCTYPE html><html><head></head><body></body></html>",
+        "noQuirksBodyHtml": ""
+      }
+    },
+    {
+      "data": "<!DOCTYPE html><head></menuitem>",
+      "errors": [
+        "26: Stray end tag “menuitem”."
+      ],
+      "document": {
+        "props": {
+          "tags": {
+            "html": true,
+            "head": true,
+            "body": true
+          },
+          "doctype": true
+        },
+        "tree": [
+          {
+            "doctype": "html"
+          },
+          {
+            "tag": "html",
+            "children": [
+              {
+                "tag": "head"
+              },
+              {
+                "tag": "body"
+              }
+            ]
+          }
+        ],
+        "html": "<!DOCTYPE html><html><head></head><body></body></html>",
+        "noQuirksBodyHtml": ""
+      }
+    },
+    {
+      "data": "<!DOCTYPE html><select><menuitem></select>",
+      "errors": [
+        "33: Stray start tag “menuitem”."
+      ],
+      "document": {
+        "props": {
+          "tags": {
+            "html": true,
+            "head": true,
+            "body": true,
+            "select": true
+          },
+          "doctype": true
+        },
+        "tree": [
+          {
+            "doctype": "html"
+          },
+          {
+            "tag": "html",
+            "children": [
+              {
+                "tag": "head"
+              },
+              {
+                "tag": "body",
+                "children": [
+                  {
+                    "tag": "select"
+                  }
+                ]
+              }
+            ]
+          }
+        ],
+        "html": "<!DOCTYPE html><html><head></head><body><select></select></body></html>",
+        "noQuirksBodyHtml": "<select></select>"
+      }
+    },
+    {
+      "data": "<!DOCTYPE html><option><menuitem>",
+      "errors": [],
+      "document": {
+        "props": {
+          "tags": {
+            "html": true,
+            "head": true,
+            "body": true,
+            "option": true,
+            "menuitem": true
+          },
+          "doctype": true
+        },
+        "tree": [
+          {
+            "doctype": "html"
+          },
+          {
+            "tag": "html",
+            "children": [
+              {
+                "tag": "head"
+              },
+              {
+                "tag": "body",
+                "children": [
+                  {
+                    "tag": "option",
+                    "children": [
+                      {
+                        "tag": "menuitem"
+                      }
+                    ]
+                  }
+                ]
+              }
+            ]
+          }
+        ],
+        "html": "<!DOCTYPE html><html><head></head><body><option><menuitem></menuitem></option></body></html>",
+        "noQuirksBodyHtml": "<option><menuitem></menuitem></option>"
+      }
+    },
+    {
+      "data": "<!DOCTYPE html><menuitem><option>",
+      "errors": [],
+      "document": {
+        "props": {
+          "tags": {
+            "html": true,
+            "head": true,
+            "body": true,
+            "menuitem": true,
+            "option": true
+          },
+          "doctype": true
+        },
+        "tree": [
+          {
+            "doctype": "html"
+          },
+          {
+            "tag": "html",
+            "children": [
+              {
+                "tag": "head"
+              },
+              {
+                "tag": "body",
+                "children": [
+                  {
+                    "tag": "menuitem",
+                    "children": [
+                      {
+                        "tag": "option"
+                      }
+                    ]
+                  }
+                ]
+              }
+            ]
+          }
+        ],
+        "html": "<!DOCTYPE html><html><head></head><body><menuitem><option></option></menuitem></body></html>",
+        "noQuirksBodyHtml": "<menuitem><option></option></menuitem>"
+      }
+    },
+    {
+      "data": "<!DOCTYPE html><menuitem></body>",
+      "errors": [],
+      "document": {
+        "props": {
+          "tags": {
+            "html": true,
+            "head": true,
+            "body": true,
+            "menuitem": true
+          },
+          "doctype": true
+        },
+        "tree": [
+          {
+            "doctype": "html"
+          },
+          {
+            "tag": "html",
+            "children": [
+              {
+                "tag": "head"
+              },
+              {
+                "tag": "body",
+                "children": [
+                  {
+                    "tag": "menuitem"
+                  }
+                ]
+              }
+            ]
+          }
+        ],
+        "html": "<!DOCTYPE html><html><head></head><body><menuitem></menuitem></body></html>",
+        "noQuirksBodyHtml": "<menuitem></menuitem>"
+      }
+    },
+    {
+      "data": "<!DOCTYPE html><menuitem></html>",
+      "errors": [],
+      "document": {
+        "props": {
+          "tags": {
+            "html": true,
+            "head": true,
+            "body": true,
+            "menuitem": true
+          },
+          "doctype": true
+        },
+        "tree": [
+          {
+            "doctype": "html"
+          },
+          {
+            "tag": "html",
+            "children": [
+              {
+                "tag": "head"
+              },
+              {
+                "tag": "body",
+                "children": [
+                  {
+                    "tag": "menuitem"
+                  }
+                ]
+              }
+            ]
+          }
+        ],
+        "html": "<!DOCTYPE html><html><head></head><body><menuitem></menuitem></body></html>",
+        "noQuirksBodyHtml": "<menuitem></menuitem>"
+      }
+    },
+    {
+      "data": "<!DOCTYPE html><menuitem><p>",
+      "errors": [],
+      "document": {
+        "props": {
+          "tags": {
+            "html": true,
+            "head": true,
+            "body": true,
+            "menuitem": true,
+            "p": true
+          },
+          "doctype": true
+        },
+        "tree": [
+          {
+            "doctype": "html"
+          },
+          {
+            "tag": "html",
+            "children": [
+              {
+                "tag": "head"
+              },
+              {
+                "tag": "body",
+                "children": [
+                  {
+                    "tag": "menuitem",
+                    "children": [
+                      {
+                        "tag": "p"
+                      }
+                    ]
+                  }
+                ]
+              }
+            ]
+          }
+        ],
+        "html": "<!DOCTYPE html><html><head></head><body><menuitem><p></p></menuitem></body></html>",
+        "noQuirksBodyHtml": "<menuitem><p></p></menuitem>"
+      }
+    },
+    {
+      "data": "<!DOCTYPE html><menuitem><li>",
+      "errors": [],
+      "document": {
+        "props": {
+          "tags": {
+            "html": true,
+            "head": true,
+            "body": true,
+            "menuitem": true,
+            "li": true
+          },
+          "doctype": true
+        },
+        "tree": [
+          {
+            "doctype": "html"
+          },
+          {
+            "tag": "html",
+            "children": [
+              {
+                "tag": "head"
+              },
+              {
+                "tag": "body",
+                "children": [
+                  {
+                    "tag": "menuitem",
+                    "children": [
+                      {
+                        "tag": "li"
+                      }
+                    ]
+                  }
+                ]
+              }
+            ]
+          }
+        ],
+        "html": "<!DOCTYPE html><html><head></head><body><menuitem><li></li></menuitem></body></html>",
+        "noQuirksBodyHtml": "<menuitem><li></li></menuitem>"
+      }
+    }
+  ],
+  "namespace-sensitivity.dat": [
+    {
+      "data": "<body><table><tr><td><svg><td><foreignObject><span></td>Foo",
+      "errors": [],
+      "document": {
+        "props": {
+          "tags": {
+            "html": true,
+            "head": true,
+            "body": true,
+            "table": true,
+            "tbody": true,
+            "tr": true,
+            "td": true,
+            "svg svg": true,
+            "svg td": true,
+            "svg foreignObject": true,
+            "span": true
+          }
+        },
+        "tree": [
+          {
+            "tag": "html",
+            "children": [
+              {
+                "tag": "head"
+              },
+              {
+                "tag": "body",
+                "children": [
+                  {
+                    "text": "Foo"
+                  },
+                  {
+                    "tag": "table",
+                    "children": [
+                      {
+                        "tag": "tbody",
+                        "children": [
+                          {
+                            "tag": "tr",
+                            "children": [
+                              {
+                                "tag": "td",
+                                "children": [
+                                  {
+                                    "tag": "svg",
+                                    "ns": "http://www.w3.org/2000/svg",
+                                    "children": [
+                                      {
+                                        "tag": "td",
+                                        "ns": "http://www.w3.org/2000/svg",
+                                        "children": [
+                                          {
+                                            "tag": "foreignObject",
+                                            "ns": "http://www.w3.org/2000/svg",
+                                            "children": [
+                                              {
+                                                "tag": "span"
+                                              }
+                                            ]
+                                          }
+                                        ]
+                                      }
+                                    ]
+                                  }
+                                ]
+                              }
+                            ]
+                          }
+                        ]
+                      }
+                    ]
+                  }
+                ]
+              }
+            ]
+          }
+        ],
+        "html": "<html><head></head><body>Foo<table><tbody><tr><td><svg><td><foreignObject><span></span></foreignObject></td></svg></td></tr></tbody></table></body></html>",
+        "noQuirksBodyHtml": "Foo<table><tbody><tr><td><svg><td><foreignObject><span></span></foreignObject></td></svg></td></tr></tbody></table>"
+      }
+    }
+  ],
+  "noscript01.dat": [
+    {
+      "data": "<head><noscript><!doctype html><!--foo--></noscript>",
+      "errors": [
+        "Line: 1 Col: 6 Unexpected start tag (head). Expected DOCTYPE.",
+        "Line: 1 Col: 31 Unexpected DOCTYPE. Ignored."
+      ],
+      "script": "off",
+      "document": {
+        "props": {
+          "tags": {
+            "html": true,
+            "head": true,
+            "noscript": true,
+            "body": true
+          },
+          "comment": true
+        },
+        "tree": [
+          {
+            "tag": "html",
+            "children": [
+              {
+                "tag": "head",
+                "children": [
+                  {
+                    "tag": "noscript",
+                    "children": [
+                      {
+                        "comment": "foo"
+                      }
+                    ]
+                  }
+                ]
+              },
+              {
+                "tag": "body"
+              }
+            ]
+          }
+        ],
+        "html": "<html><head><noscript><!--foo--></noscript></head><body></body></html>",
+        "noQuirksBodyHtml": "<noscript><!--foo--></noscript>"
+      }
+    },
+    {
+      "data": "<head><noscript><html class=\"foo\"><!--foo--></noscript>",
+      "errors": [
+        "Line: 1 Col: 6 Unexpected start tag (head). Expected DOCTYPE.",
+        "Line: 1 Col: 34 html needs to be the first start tag."
+      ],
+      "script": "off",
+      "document": {
+        "props": {
+          "tags": {
+            "html": true,
+            "head": true,
+            "noscript": true,
+            "body": true
+          },
+          "comment": true
+        },
+        "tree": [
+          {
+            "tag": "html",
+            "attrs": [
+              {
+                "name": "class",
+                "value": "foo"
+              }
+            ],
+            "children": [
+              {
+                "tag": "head",
+                "children": [
+                  {
+                    "tag": "noscript",
+                    "children": [
+                      {
+                        "comment": "foo"
+                      }
+                    ]
+                  }
+                ]
+              },
+              {
+                "tag": "body"
+              }
+            ]
+          }
+        ],
+        "html": "<html class=\"foo\"><head><noscript><!--foo--></noscript></head><body></body></html>",
+        "noQuirksBodyHtml": "<noscript><!--foo--></noscript>"
+      }
+    },
+    {
+      "data": "<head><noscript></noscript>",
+      "errors": [
+        "(1,6): expected-doctype-but-got-tag"
+      ],
+      "script": "off",
+      "document": {
+        "props": {
+          "tags": {
+            "html": true,
+            "head": true,
+            "noscript": true,
+            "body": true
+          }
+        },
+        "tree": [
+          {
+            "tag": "html",
+            "children": [
+              {
+                "tag": "head",
+                "children": [
+                  {
+                    "tag": "noscript"
+                  }
+                ]
+              },
+              {
+                "tag": "body"
+              }
+            ]
+          }
+        ],
+        "html": "<html><head><noscript></noscript></head><body></body></html>",
+        "noQuirksBodyHtml": "<noscript></noscript>"
+      }
+    },
+    {
+      "data": "<head><noscript>   </noscript>",
+      "errors": [
+        "Line: 1 Col: 6 Unexpected start tag (head). Expected DOCTYPE."
+      ],
+      "script": "off",
+      "document": {
+        "props": {
+          "tags": {
+            "html": true,
+            "head": true,
+            "noscript": true,
+            "body": true
+          },
+          "no_escape": true
+        },
+        "tree": [
+          {
+            "tag": "html",
+            "children": [
+              {
+                "tag": "head",
+                "children": [
+                  {
+                    "tag": "noscript",
+                    "children": [
+                      {
+                        "text": "   ",
+                        "no_escape": true
+                      }
+                    ]
+                  }
+                ]
+              },
+              {
+                "tag": "body"
+              }
+            ]
+          }
+        ],
+        "html": "<html><head><noscript>   </noscript></head><body></body></html>",
+        "noQuirksBodyHtml": "<noscript>   </noscript>"
+      }
+    },
+    {
+      "data": "<head><noscript><!--foo--></noscript>",
+      "errors": [
+        "(1,6): expected-doctype-but-got-tag"
+      ],
+      "script": "off",
+      "document": {
+        "props": {
+          "tags": {
+            "html": true,
+            "head": true,
+            "noscript": true,
+            "body": true
+          },
+          "comment": true
+        },
+        "tree": [
+          {
+            "tag": "html",
+            "children": [
+              {
+                "tag": "head",
+                "children": [
+                  {
+                    "tag": "noscript",
+                    "children": [
+                      {
+                        "comment": "foo"
+                      }
+                    ]
+                  }
+                ]
+              },
+              {
+                "tag": "body"
+              }
+            ]
+          }
+        ],
+        "html": "<html><head><noscript><!--foo--></noscript></head><body></body></html>",
+        "noQuirksBodyHtml": "<noscript><!--foo--></noscript>"
+      }
+    },
+    {
+      "data": "<head><noscript><basefont><!--foo--></noscript>",
+      "errors": [
+        "Line: 1 Col: 6 Unexpected start tag (head). Expected DOCTYPE."
+      ],
+      "script": "off",
+      "document": {
+        "props": {
+          "tags": {
+            "html": true,
+            "head": true,
+            "noscript": true,
+            "basefont": true,
+            "body": true
+          },
+          "comment": true
+        },
+        "tree": [
+          {
+            "tag": "html",
+            "children": [
+              {
+                "tag": "head",
+                "children": [
+                  {
+                    "tag": "noscript",
+                    "children": [
+                      {
+                        "tag": "basefont"
+                      },
+                      {
+                        "comment": "foo"
+                      }
+                    ]
+                  }
+                ]
+              },
+              {
+                "tag": "body"
+              }
+            ]
+          }
+        ],
+        "html": "<html><head><noscript><basefont><!--foo--></noscript></head><body></body></html>",
+        "noQuirksBodyHtml": "<noscript><basefont><!--foo--></noscript>"
+      }
+    },
+    {
+      "data": "<head><noscript><bgsound><!--foo--></noscript>",
+      "errors": [
+        "Line: 1 Col: 6 Unexpected start tag (head). Expected DOCTYPE."
+      ],
+      "script": "off",
+      "document": {
+        "props": {
+          "tags": {
+            "html": true,
+            "head": true,
+            "noscript": true,
+            "bgsound": true,
+            "body": true
+          },
+          "comment": true
+        },
+        "tree": [
+          {
+            "tag": "html",
+            "children": [
+              {
+                "tag": "head",
+                "children": [
+                  {
+                    "tag": "noscript",
+                    "children": [
+                      {
+                        "tag": "bgsound"
+                      },
+                      {
+                        "comment": "foo"
+                      }
+                    ]
+                  }
+                ]
+              },
+              {
+                "tag": "body"
+              }
+            ]
+          }
+        ],
+        "html": "<html><head><noscript><bgsound><!--foo--></noscript></head><body></body></html>",
+        "noQuirksBodyHtml": "<noscript><bgsound><!--foo--></noscript>"
+      }
+    },
+    {
+      "data": "<head><noscript><link><!--foo--></noscript>",
+      "errors": [
+        "Line: 1 Col: 6 Unexpected start tag (head). Expected DOCTYPE."
+      ],
+      "script": "off",
       "document": {
         "props": {
           "tags": {
             "html": true,
             "head": true,
-            "body": true,
-            "main": true,
-            "p": true
+            "noscript": true,
+            "link": true,
+            "body": true
           },
-          "doctype": true
+          "comment": true
         },
         "tree": [
-          {
-            "doctype": "html"
-          },
           {
             "tag": "html",
             "children": [
               {
-                "tag": "head"
-              },
-              {
-                "tag": "body",
+                "tag": "head",
                 "children": [
                   {
-                    "tag": "main",
+                    "tag": "noscript",
                     "children": [
                       {
-                        "tag": "p",
-                        "children": [
-                          {
-                            "text": "foo"
-                          }
-                        ]
+                        "tag": "link"
+                      },
+                      {
+                        "comment": "foo"
                       }
                     ]
-                  },
-                  {
-                    "text": "bar"
                   }
                 ]
+              },
+              {
+                "tag": "body"
               }
             ]
           }
         ],
-        "html": "<!DOCTYPE html><html><head></head><body><main><p>foo</p></main>bar</body></html>",
-        "noQuirksBodyHtml": "<main><p>foo</p></main>bar"
+        "html": "<html><head><noscript><link><!--foo--></noscript></head><body></body></html>",
+        "noQuirksBodyHtml": "<noscript><link><!--foo--></noscript>"
       }
     },
     {
-      "data": "<!DOCTYPE html>xxx<svg><x><g><a><main><b>",
+      "data": "<head><noscript><meta><!--foo--></noscript>",
       "errors": [
-        " * (1,42) unexpected HTML-like start tag token in foreign content",
-        " * (1,42) unexpected end of file"
+        "Line: 1 Col: 6 Unexpected start tag (head). Expected DOCTYPE."
       ],
+      "script": "off",
       "document": {
         "props": {
           "tags": {
             "html": true,
             "head": true,
-            "body": true,
-            "svg svg": true,
-            "svg x": true,
-            "svg g": true,
-            "svg a": true,
-            "svg main": true,
-            "b": true
+            "noscript": true,
+            "meta": true,
+            "body": true
           },
-          "doctype": true
+          "comment": true
         },
         "tree": [
-          {
-            "doctype": "html"
-          },
           {
             "tag": "html",
             "children": [
               {
-                "tag": "head"
-              },
-              {
-                "tag": "body",
+                "tag": "head",
                 "children": [
                   {
-                    "text": "xxx"
-                  },
-                  {
-                    "tag": "svg",
-                    "ns": "http://www.w3.org/2000/svg",
+                    "tag": "noscript",
                     "children": [
                       {
-                        "tag": "x",
-                        "ns": "http://www.w3.org/2000/svg",
-                        "children": [
-                          {
-                            "tag": "g",
-                            "ns": "http://www.w3.org/2000/svg",
-                            "children": [
-                              {
-                                "tag": "a",
-                                "ns": "http://www.w3.org/2000/svg",
-                                "children": [
-                                  {
-                                    "tag": "main",
-                                    "ns": "http://www.w3.org/2000/svg"
-                                  }
-                                ]
-                              }
-                            ]
-                          }
-                        ]
+                        "tag": "meta"
+                      },
+                      {
+                        "comment": "foo"
                       }
                     ]
-                  },
-                  {
-                    "tag": "b"
                   }
                 ]
+              },
+              {
+                "tag": "body"
               }
             ]
           }
         ],
-        "html": "<!DOCTYPE html><html><head></head><body>xxx<svg><x><g><a><main></main></a></g></x></svg><b></b></body></html>",
-        "noQuirksBodyHtml": "xxx<svg><x><g><a><main><b></b></main></a></g></x></svg>"
+        "html": "<html><head><noscript><meta><!--foo--></noscript></head><body></body></html>",
+        "noQuirksBodyHtml": "<noscript><meta><!--foo--></noscript>"
       }
-    }
-  ],
-  "math.dat": [
+    },
     {
-      "data": "<math><tr><td><mo><tr>",
-      "errors": [],
-      "fragment": {
-        "name": "td"
-      },
+      "data": "<head><noscript><noframes>XXX</noscript></noframes></noscript>",
+      "errors": [
+        "Line: 1 Col: 6 Unexpected start tag (head). Expected DOCTYPE."
+      ],
+      "script": "off",
       "document": {
         "props": {
           "tags": {
-            "math math": true,
-            "math tr": true,
-            "math td": true,
-            "math mo": true
-          }
+            "html": true,
+            "head": true,
+            "noscript": true,
+            "noframes": true,
+            "body": true
+          },
+          "no_escape": true
         },
         "tree": [
           {
-            "tag": "math",
-            "ns": "http://www.w3.org/1998/Math/MathML",
+            "tag": "html",
             "children": [
               {
-                "tag": "tr",
-                "ns": "http://www.w3.org/1998/Math/MathML",
+                "tag": "head",
                 "children": [
                   {
-                    "tag": "td",
-                    "ns": "http://www.w3.org/1998/Math/MathML",
+                    "tag": "noscript",
                     "children": [
                       {
-                        "tag": "mo",
-                        "ns": "http://www.w3.org/1998/Math/MathML"
+                        "tag": "noframes",
+                        "children": [
+                          {
+                            "text": "XXX</noscript>",
+                            "no_escape": true
+                          }
+                        ]
                       }
                     ]
                   }
                 ]
+              },
+              {
+                "tag": "body"
               }
             ]
           }
         ],
-        "html": "<math><tr><td><mo></mo></td></tr></math>",
-        "noQuirksBodyHtml": "<math><tr><td><mo></mo></td></tr></math>"
+        "html": "<html><head><noscript><noframes>XXX</noscript></noframes></noscript></head><body></body></html>",
+        "noQuirksBodyHtml": "<noscript><noframes>XXX</noscript></noframes></noscript>"
       }
     },
     {
-      "data": "<math><tr><td><mo><tr>",
-      "errors": [],
-      "fragment": {
-        "name": "tr"
-      },
+      "data": "<head><noscript><style>XXX</style></noscript>",
+      "errors": [
+        "Line: 1 Col: 6 Unexpected start tag (head). Expected DOCTYPE."
+      ],
+      "script": "off",
       "document": {
         "props": {
           "tags": {
-            "math math": true,
-            "math tr": true,
-            "math td": true,
-            "math mo": true
-          }
+            "html": true,
+            "head": true,
+            "noscript": true,
+            "style": true,
+            "body": true
+          },
+          "no_escape": true
         },
         "tree": [
           {
-            "tag": "math",
-            "ns": "http://www.w3.org/1998/Math/MathML",
+            "tag": "html",
             "children": [
               {
-                "tag": "tr",
-                "ns": "http://www.w3.org/1998/Math/MathML",
+                "tag": "head",
                 "children": [
                   {
-                    "tag": "td",
-                    "ns": "http://www.w3.org/1998/Math/MathML",
+                    "tag": "noscript",
                     "children": [
                       {
-                        "tag": "mo",
-                        "ns": "http://www.w3.org/1998/Math/MathML"
+                        "tag": "style",
+                        "children": [
+                          {
+                            "text": "XXX",
+                            "no_escape": true
+                          }
+                        ]
                       }
                     ]
                   }
                 ]
+              },
+              {
+                "tag": "body"
               }
             ]
           }
         ],
-        "html": "<math><tr><td><mo></mo></td></tr></math>",
-        "noQuirksBodyHtml": "<math><tr><td><mo></mo></td></tr></math>"
+        "html": "<html><head><noscript><style>XXX</style></noscript></head><body></body></html>",
+        "noQuirksBodyHtml": "<noscript><style>XXX</style></noscript>"
       }
     },
     {
-      "data": "<math><thead><mo><tbody>",
-      "errors": [],
-      "fragment": {
-        "name": "thead"
-      },
+      "data": "<head><noscript></br><!--foo--></noscript>",
+      "errors": [
+        "Line: 1 Col: 6 Unexpected start tag (head). Expected DOCTYPE.",
+        "Line: 1 Col: 21 Element br not allowed in a inhead-noscript context",
+        "Line: 1 Col: 21 Unexpected end tag (br). Treated as br element.",
+        "Line: 1 Col: 42 Unexpected end tag (noscript). Ignored."
+      ],
+      "script": "off",
       "document": {
         "props": {
           "tags": {
-            "math math": true,
-            "math thead": true,
-            "math mo": true
-          }
+            "html": true,
+            "head": true,
+            "noscript": true,
+            "body": true,
+            "br": true
+          },
+          "comment": true
         },
         "tree": [
           {
-            "tag": "math",
-            "ns": "http://www.w3.org/1998/Math/MathML",
+            "tag": "html",
             "children": [
               {
-                "tag": "thead",
-                "ns": "http://www.w3.org/1998/Math/MathML",
+                "tag": "head",
                 "children": [
                   {
-                    "tag": "mo",
-                    "ns": "http://www.w3.org/1998/Math/MathML"
+                    "tag": "noscript"
+                  }
+                ]
+              },
+              {
+                "tag": "body",
+                "children": [
+                  {
+                    "tag": "br"
+                  },
+                  {
+                    "comment": "foo"
                   }
                 ]
               }
             ]
           }
         ],
-        "html": "<math><thead><mo></mo></thead></math>",
-        "noQuirksBodyHtml": "<math><thead><mo></mo></thead></math>"
+        "html": "<html><head><noscript></noscript></head><body><br><!--foo--></body></html>",
+        "noQuirksBodyHtml": "<noscript><br><!--foo--></noscript>"
       }
     },
     {
-      "data": "<math><tfoot><mo><tbody>",
-      "errors": [],
-      "fragment": {
-        "name": "tfoot"
-      },
+      "data": "<head><noscript><head class=\"foo\"><!--foo--></noscript>",
+      "errors": [
+        "Line: 1 Col: 6 Unexpected start tag (head). Expected DOCTYPE.",
+        "Line: 1 Col: 34 Unexpected start tag (head)."
+      ],
+      "script": "off",
       "document": {
         "props": {
           "tags": {
-            "math math": true,
-            "math tfoot": true,
-            "math mo": true
-          }
+            "html": true,
+            "head": true,
+            "noscript": true,
+            "body": true
+          },
+          "comment": true
         },
         "tree": [
           {
-            "tag": "math",
-            "ns": "http://www.w3.org/1998/Math/MathML",
+            "tag": "html",
             "children": [
               {
-                "tag": "tfoot",
-                "ns": "http://www.w3.org/1998/Math/MathML",
+                "tag": "head",
                 "children": [
                   {
-                    "tag": "mo",
-                    "ns": "http://www.w3.org/1998/Math/MathML"
+                    "tag": "noscript",
+                    "children": [
+                      {
+                        "comment": "foo"
+                      }
+                    ]
                   }
                 ]
+              },
+              {
+                "tag": "body"
               }
             ]
           }
         ],
-        "html": "<math><tfoot><mo></mo></tfoot></math>",
-        "noQuirksBodyHtml": "<math><tfoot><mo></mo></tfoot></math>"
+        "html": "<html><head><noscript><!--foo--></noscript></head><body></body></html>",
+        "noQuirksBodyHtml": "<noscript><!--foo--></noscript>"
       }
     },
     {
-      "data": "<math><tbody><mo><tfoot>",
-      "errors": [],
-      "fragment": {
-        "name": "tbody"
-      },
+      "data": "<head><noscript><noscript class=\"foo\"><!--foo--></noscript>",
+      "errors": [
+        "Line: 1 Col: 6 Unexpected start tag (head). Expected DOCTYPE.",
+        "Line: 1 Col: 34 Unexpected start tag (noscript)."
+      ],
+      "script": "off",
       "document": {
         "props": {
           "tags": {
-            "math math": true,
-            "math tbody": true,
-            "math mo": true
-          }
+            "html": true,
+            "head": true,
+            "noscript": true,
+            "body": true
+          },
+          "comment": true
         },
         "tree": [
           {
-            "tag": "math",
-            "ns": "http://www.w3.org/1998/Math/MathML",
+            "tag": "html",
             "children": [
               {
-                "tag": "tbody",
-                "ns": "http://www.w3.org/1998/Math/MathML",
+                "tag": "head",
                 "children": [
                   {
-                    "tag": "mo",
-                    "ns": "http://www.w3.org/1998/Math/MathML"
+                    "tag": "noscript",
+                    "children": [
+                      {
+                        "comment": "foo"
+                      }
+                    ]
                   }
                 ]
+              },
+              {
+                "tag": "body"
               }
             ]
           }
         ],
-        "html": "<math><tbody><mo></mo></tbody></math>",
-        "noQuirksBodyHtml": "<math><tbody><mo></mo></tbody></math>"
+        "html": "<html><head><noscript><!--foo--></noscript></head><body></body></html>",
+        "noQuirksBodyHtml": "<noscript><noscript class=\"foo\"><!--foo--></noscript></noscript>"
       }
     },
     {
-      "data": "<math><tbody><mo></table>",
-      "errors": [],
-      "fragment": {
-        "name": "tbody"
-      },
+      "data": "<head><noscript></p><!--foo--></noscript>",
+      "errors": [
+        "Line: 1 Col: 6 Unexpected start tag (head). Expected DOCTYPE.",
+        "Line: 1 Col: 20 Unexpected end tag (p). Ignored."
+      ],
+      "script": "off",
       "document": {
         "props": {
           "tags": {
-            "math math": true,
-            "math tbody": true,
-            "math mo": true
-          }
+            "html": true,
+            "head": true,
+            "noscript": true,
+            "body": true
+          },
+          "comment": true
         },
         "tree": [
           {
-            "tag": "math",
-            "ns": "http://www.w3.org/1998/Math/MathML",
+            "tag": "html",
             "children": [
               {
-                "tag": "tbody",
-                "ns": "http://www.w3.org/1998/Math/MathML",
+                "tag": "head",
                 "children": [
                   {
-                    "tag": "mo",
-                    "ns": "http://www.w3.org/1998/Math/MathML"
+                    "tag": "noscript",
+                    "children": [
+                      {
+                        "comment": "foo"
+                      }
+                    ]
                   }
                 ]
+              },
+              {
+                "tag": "body"
               }
             ]
           }
         ],
-        "html": "<math><tbody><mo></mo></tbody></math>",
-        "noQuirksBodyHtml": "<math><tbody><mo></mo></tbody></math>"
+        "html": "<html><head><noscript><!--foo--></noscript></head><body></body></html>",
+        "noQuirksBodyHtml": "<noscript><p></p><!--foo--></noscript>"
       }
     },
     {
-      "data": "<math><thead><mo></table>",
-      "errors": [],
-      "fragment": {
-        "name": "tbody"
-      },
+      "data": "<head><noscript><p><!--foo--></noscript>",
+      "errors": [
+        "Line: 1 Col: 6 Unexpected start tag (head). Expected DOCTYPE.",
+        "Line: 1 Col: 19 Element p not allowed in a inhead-noscript context",
+        "Line: 1 Col: 40 Unexpected end tag (noscript). Ignored."
+      ],
+      "script": "off",
       "document": {
         "props": {
           "tags": {
-            "math math": true,
-            "math thead": true,
-            "math mo": true
-          }
+            "html": true,
+            "head": true,
+            "noscript": true,
+            "body": true,
+            "p": true
+          },
+          "comment": true
         },
         "tree": [
           {
-            "tag": "math",
-            "ns": "http://www.w3.org/1998/Math/MathML",
+            "tag": "html",
             "children": [
               {
-                "tag": "thead",
-                "ns": "http://www.w3.org/1998/Math/MathML",
+                "tag": "head",
                 "children": [
                   {
-                    "tag": "mo",
-                    "ns": "http://www.w3.org/1998/Math/MathML"
+                    "tag": "noscript"
+                  }
+                ]
+              },
+              {
+                "tag": "body",
+                "children": [
+                  {
+                    "tag": "p",
+                    "children": [
+                      {
+                        "comment": "foo"
+                      }
+                    ]
                   }
                 ]
               }
             ]
           }
         ],
-        "html": "<math><thead><mo></mo></thead></math>",
-        "noQuirksBodyHtml": "<math><thead><mo></mo></thead></math>"
+        "html": "<html><head><noscript></noscript></head><body><p><!--foo--></p></body></html>",
+        "noQuirksBodyHtml": "<noscript><p><!--foo--></p></noscript>"
       }
     },
     {
-      "data": "<math><tfoot><mo></table>",
-      "errors": [],
-      "fragment": {
-        "name": "tbody"
-      },
+      "data": "<head><noscript>XXX<!--foo--></noscript></head>",
+      "errors": [
+        "Line: 1 Col: 6 Unexpected start tag (head). Expected DOCTYPE.",
+        "Line: 1 Col: 19 Unexpected non-space character. Expected inhead-noscript content",
+        "Line: 1 Col: 30 Unexpected end tag (noscript). Ignored.",
+        "Line: 1 Col: 37 Unexpected end tag (head). Ignored."
+      ],
+      "script": "off",
       "document": {
         "props": {
           "tags": {
-            "math math": true,
-            "math tfoot": true,
-            "math mo": true
-          }
+            "html": true,
+            "head": true,
+            "noscript": true,
+            "body": true
+          },
+          "comment": true
         },
         "tree": [
           {
-            "tag": "math",
-            "ns": "http://www.w3.org/1998/Math/MathML",
+            "tag": "html",
             "children": [
               {
-                "tag": "tfoot",
-                "ns": "http://www.w3.org/1998/Math/MathML",
+                "tag": "head",
                 "children": [
                   {
-                    "tag": "mo",
-                    "ns": "http://www.w3.org/1998/Math/MathML"
+                    "tag": "noscript"
+                  }
+                ]
+              },
+              {
+                "tag": "body",
+                "children": [
+                  {
+                    "text": "XXX"
+                  },
+                  {
+                    "comment": "foo"
                   }
                 ]
               }
             ]
           }
         ],
-        "html": "<math><tfoot><mo></mo></tfoot></math>",
-        "noQuirksBodyHtml": "<math><tfoot><mo></mo></tfoot></math>"
+        "html": "<html><head><noscript></noscript></head><body>XXX<!--foo--></body></html>",
+        "noQuirksBodyHtml": "<noscript>XXX<!--foo--></noscript>"
       }
-    }
-  ],
-  "namespace-sensitivity.dat": [
+    },
     {
-      "data": "<body><table><tr><td><svg><td><foreignObject><span></td>Foo",
-      "errors": [],
+      "data": "<head><noscript>",
+      "errors": [
+        "(1,6): expected-doctype-but-got-tag",
+        "(1,6): eof-in-head-noscript"
+      ],
+      "script": "off",
       "document": {
         "props": {
           "tags": {
             "html": true,
             "head": true,
-            "body": true,
-            "table": true,
-            "tbody": true,
-            "tr": true,
-            "td": true,
-            "svg svg": true,
-            "svg td": true,
-            "svg foreignObject": true,
-            "span": true
+            "noscript": true,
+            "body": true
           }
         },
         "tree": [
             "tag": "html",
             "children": [
               {
-                "tag": "head"
-              },
-              {
-                "tag": "body",
+                "tag": "head",
                 "children": [
                   {
-                    "text": "Foo"
-                  },
-                  {
-                    "tag": "table",
-                    "children": [
-                      {
-                        "tag": "tbody",
-                        "children": [
-                          {
-                            "tag": "tr",
-                            "children": [
-                              {
-                                "tag": "td",
-                                "children": [
-                                  {
-                                    "tag": "svg",
-                                    "ns": "http://www.w3.org/2000/svg",
-                                    "children": [
-                                      {
-                                        "tag": "td",
-                                        "ns": "http://www.w3.org/2000/svg",
-                                        "children": [
-                                          {
-                                            "tag": "foreignObject",
-                                            "ns": "http://www.w3.org/2000/svg",
-                                            "children": [
-                                              {
-                                                "tag": "span"
-                                              }
-                                            ]
-                                          }
-                                        ]
-                                      }
-                                    ]
-                                  }
-                                ]
-                              }
-                            ]
-                          }
-                        ]
-                      }
-                    ]
+                    "tag": "noscript"
                   }
                 ]
+              },
+              {
+                "tag": "body"
               }
             ]
           }
         ],
-        "html": "<html><head></head><body>Foo<table><tbody><tr><td><svg><td><foreignObject><span></span></foreignObject></td></svg></td></tr></tbody></table></body></html>",
-        "noQuirksBodyHtml": "Foo<table><tbody><tr><td><svg><td><foreignObject><span></span></foreignObject></td></svg></td></tr></tbody></table>"
+        "html": "<html><head><noscript></noscript></head><body></body></html>",
+        "noQuirksBodyHtml": "<noscript></noscript>"
       }
     }
   ],
             "body": true,
             "pre": true
           },
-          "doctype": true,
-          "extraNL": true
+          "doctype": true
         },
         "tree": [
           {
                     "tag": "pre",
                     "children": [
                       {
-                        "text": "\nA",
-                        "extraNL": true
+                        "text": "\nA"
                       }
                     ]
                   }
             ]
           }
         ],
-        "html": "<!DOCTYPE html><html><head></head><body><pre>\n\nA</pre></body></html>",
-        "noQuirksBodyHtml": "<pre>\n\nA</pre>"
+        "html": "<!DOCTYPE html><html><head></head><body><pre>\nA</pre></body></html>",
+        "noQuirksBodyHtml": "<pre>\nA</pre>"
       }
     },
     {
             "body": true,
             "pre": true
           },
-          "doctype": true,
-          "extraNL": true
+          "doctype": true
         },
         "tree": [
           {
                     "tag": "pre",
                     "children": [
                       {
-                        "text": "\nA",
-                        "extraNL": true
+                        "text": "\nA"
                       }
                     ]
                   }
             ]
           }
         ],
-        "html": "<!DOCTYPE html><html><head></head><body><pre>\n\nA</pre></body></html>",
-        "noQuirksBodyHtml": "<pre>\n\nA</pre>"
+        "html": "<!DOCTYPE html><html><head></head><body><pre>\nA</pre></body></html>",
+        "noQuirksBodyHtml": "<pre>\nA</pre>"
       }
     },
     {
     {
       "data": "<html><ruby>a<rb>b<span></ruby></html>",
       "errors": [
-        "(1,6): expected-doctype-but-got-start-tag"
+        "(1,6): expected-doctype-but-got-start-tag",
+        "(1,31): unexpected-end-tag"
       ],
       "document": {
         "props": {
     {
       "data": "<html><ruby>a<rt>b<span></ruby></html>",
       "errors": [
-        "(1,6): expected-doctype-but-got-start-tag"
+        "(1,6): expected-doctype-but-got-start-tag",
+        "(1,31): unexpected-end-tag"
       ],
       "document": {
         "props": {
     {
       "data": "<html><ruby>a<rp>b<span></ruby></html>",
       "errors": [
-        "(1,6): expected-doctype-but-got-start-tag"
+        "(1,6): expected-doctype-but-got-start-tag",
+        "(1,31): unexpected-end-tag"
       ],
       "document": {
         "props": {
         "(1,11): unexpected-start-tag-in-select",
         "(1,27): unexpected-select-in-select",
         "(1,39): unexpected-end-tag",
-        "(1,48): unexpected-end-tag",
-        "(1,49): expected-closing-tag-but-got-eof"
+        "(1,48): unexpected-end-tag"
       ],
       "document": {
         "props": {
         "(1,11): unexpected-start-tag-in-select",
         "(1,27): unexpected-select-in-select",
         "(1,39): unexpected-end-tag",
-        "(1,48): unexpected-end-tag",
-        "(1,48): expected-closing-tag-but-got-eof"
+        "(1,48): unexpected-end-tag"
       ],
       "document": {
         "props": {
         "noQuirksBodyHtml": "<math attributename=\"\" attributetype=\"\" basefrequency=\"\" baseprofile=\"\" calcmode=\"\" clippathunits=\"\" diffuseconstant=\"\" edgemode=\"\" filterunits=\"\" glyphref=\"\" gradienttransform=\"\" gradientunits=\"\" kernelmatrix=\"\" kernelunitlength=\"\" keypoints=\"\" keysplines=\"\" keytimes=\"\" lengthadjust=\"\" limitingconeangle=\"\" markerheight=\"\" markerunits=\"\" markerwidth=\"\" maskcontentunits=\"\" maskunits=\"\" numoctaves=\"\" pathlength=\"\" patterncontentunits=\"\" patterntransform=\"\" patternunits=\"\" pointsatx=\"\" pointsaty=\"\" pointsatz=\"\" preservealpha=\"\" preserveaspectratio=\"\" primitiveunits=\"\" refx=\"\" refy=\"\" repeatcount=\"\" repeatdur=\"\" requiredextensions=\"\" requiredfeatures=\"\" specularconstant=\"\" specularexponent=\"\" spreadmethod=\"\" startoffset=\"\" stddeviation=\"\" stitchtiles=\"\" surfacescale=\"\" systemlanguage=\"\" tablevalues=\"\" targetx=\"\" targety=\"\" textlength=\"\" viewbox=\"\" viewtarget=\"\" xchannelselector=\"\" ychannelselector=\"\" zoomandpan=\"\"></math>"
       }
     },
+    {
+      "data": "<!DOCTYPE html><body><svg contentScriptType='' contentStyleType='' externalResourcesRequired='' filterRes=''></svg>",
+      "errors": [],
+      "document": {
+        "props": {
+          "tags": {
+            "html": true,
+            "head": true,
+            "body": true,
+            "svg svg": true
+          },
+          "doctype": true
+        },
+        "tree": [
+          {
+            "doctype": "html"
+          },
+          {
+            "tag": "html",
+            "children": [
+              {
+                "tag": "head"
+              },
+              {
+                "tag": "body",
+                "children": [
+                  {
+                    "tag": "svg",
+                    "ns": "http://www.w3.org/2000/svg",
+                    "attrs": [
+                      {
+                        "name": "contentscripttype",
+                        "value": ""
+                      },
+                      {
+                        "name": "contentstyletype",
+                        "value": ""
+                      },
+                      {
+                        "name": "externalresourcesrequired",
+                        "value": ""
+                      },
+                      {
+                        "name": "filterres",
+                        "value": ""
+                      }
+                    ]
+                  }
+                ]
+              }
+            ]
+          }
+        ],
+        "html": "<!DOCTYPE html><html><head></head><body><svg contentscripttype=\"\" contentstyletype=\"\" externalresourcesrequired=\"\" filterres=\"\"></svg></body></html>",
+        "noQuirksBodyHtml": "<svg contentScriptType=\"\" contentStyleType=\"\" externalResourcesRequired=\"\" filterres=\"\"></svg>"
+      }
+    },
+    {
+      "data": "<!DOCTYPE html><body><svg CONTENTSCRIPTTYPE='' CONTENTSTYLETYPE='' EXTERNALRESOURCESREQUIRED='' FILTERRES=''></svg>",
+      "errors": [],
+      "document": {
+        "props": {
+          "tags": {
+            "html": true,
+            "head": true,
+            "body": true,
+            "svg svg": true
+          },
+          "doctype": true
+        },
+        "tree": [
+          {
+            "doctype": "html"
+          },
+          {
+            "tag": "html",
+            "children": [
+              {
+                "tag": "head"
+              },
+              {
+                "tag": "body",
+                "children": [
+                  {
+                    "tag": "svg",
+                    "ns": "http://www.w3.org/2000/svg",
+                    "attrs": [
+                      {
+                        "name": "contentscripttype",
+                        "value": ""
+                      },
+                      {
+                        "name": "contentstyletype",
+                        "value": ""
+                      },
+                      {
+                        "name": "externalresourcesrequired",
+                        "value": ""
+                      },
+                      {
+                        "name": "filterres",
+                        "value": ""
+                      }
+                    ]
+                  }
+                ]
+              }
+            ]
+          }
+        ],
+        "html": "<!DOCTYPE html><html><head></head><body><svg contentscripttype=\"\" contentstyletype=\"\" externalresourcesrequired=\"\" filterres=\"\"></svg></body></html>",
+        "noQuirksBodyHtml": "<svg contentScriptType=\"\" contentStyleType=\"\" externalResourcesRequired=\"\" filterres=\"\"></svg>"
+      }
+    },
+    {
+      "data": "<!DOCTYPE html><body><svg contentscripttype='' contentstyletype='' externalresourcesrequired='' filterres=''></svg>",
+      "errors": [],
+      "document": {
+        "props": {
+          "tags": {
+            "html": true,
+            "head": true,
+            "body": true,
+            "svg svg": true
+          },
+          "doctype": true
+        },
+        "tree": [
+          {
+            "doctype": "html"
+          },
+          {
+            "tag": "html",
+            "children": [
+              {
+                "tag": "head"
+              },
+              {
+                "tag": "body",
+                "children": [
+                  {
+                    "tag": "svg",
+                    "ns": "http://www.w3.org/2000/svg",
+                    "attrs": [
+                      {
+                        "name": "contentscripttype",
+                        "value": ""
+                      },
+                      {
+                        "name": "contentstyletype",
+                        "value": ""
+                      },
+                      {
+                        "name": "externalresourcesrequired",
+                        "value": ""
+                      },
+                      {
+                        "name": "filterres",
+                        "value": ""
+                      }
+                    ]
+                  }
+                ]
+              }
+            ]
+          }
+        ],
+        "html": "<!DOCTYPE html><html><head></head><body><svg contentscripttype=\"\" contentstyletype=\"\" externalresourcesrequired=\"\" filterres=\"\"></svg></body></html>",
+        "noQuirksBodyHtml": "<svg contentScriptType=\"\" contentStyleType=\"\" externalResourcesRequired=\"\" filterres=\"\"></svg>"
+      }
+    },
+    {
+      "data": "<!DOCTYPE html><body><math contentScriptType='' contentStyleType='' externalResourcesRequired='' filterRes=''></math>",
+      "errors": [],
+      "document": {
+        "props": {
+          "tags": {
+            "html": true,
+            "head": true,
+            "body": true,
+            "math math": true
+          },
+          "doctype": true
+        },
+        "tree": [
+          {
+            "doctype": "html"
+          },
+          {
+            "tag": "html",
+            "children": [
+              {
+                "tag": "head"
+              },
+              {
+                "tag": "body",
+                "children": [
+                  {
+                    "tag": "math",
+                    "ns": "http://www.w3.org/1998/Math/MathML",
+                    "attrs": [
+                      {
+                        "name": "contentscripttype",
+                        "value": ""
+                      },
+                      {
+                        "name": "contentstyletype",
+                        "value": ""
+                      },
+                      {
+                        "name": "externalresourcesrequired",
+                        "value": ""
+                      },
+                      {
+                        "name": "filterres",
+                        "value": ""
+                      }
+                    ]
+                  }
+                ]
+              }
+            ]
+          }
+        ],
+        "html": "<!DOCTYPE html><html><head></head><body><math contentscripttype=\"\" contentstyletype=\"\" externalresourcesrequired=\"\" filterres=\"\"></math></body></html>",
+        "noQuirksBodyHtml": "<math contentscripttype=\"\" contentstyletype=\"\" externalresourcesrequired=\"\" filterres=\"\"></math>"
+      }
+    },
     {
       "data": "<!DOCTYPE html><body><svg><altGlyph /><altGlyphDef /><altGlyphItem /><animateColor /><animateMotion /><animateTransform /><clipPath /><feBlend /><feColorMatrix /><feComponentTransfer /><feComposite /><feConvolveMatrix /><feDiffuseLighting /><feDisplacementMap /><feDistantLight /><feFlood /><feFuncA /><feFuncB /><feFuncG /><feFuncR /><feGaussianBlur /><feImage /><feMerge /><feMergeNode /><feMorphology /><feOffset /><fePointLight /><feSpecularLighting /><feSpotLight /><feTile /><feTurbulence /><foreignObject /><glyphRef /><linearGradient /><radialGradient /><textPath /></svg>",
       "errors": [],
     {
       "data": "<!doctype html><script><!",
       "errors": [
+        "(1,25): expected-script-data-but-got-eof",
         "(1,25): expected-named-closing-tag-but-got-eof"
       ],
       "document": {
           }
         ],
         "html": "<!DOCTYPE html><html><head><noscript><!--<noscript></noscript></head><body>--&gt;</body></html>",
-        "noQuirksBodyHtml": "<noscript>&lt;!--&lt;noscript&gt;</noscript>--&gt;"
+        "noQuirksBodyHtml": "<noscript><!--<noscript></noscript>--></noscript>"
       }
     },
     {
           }
         ],
         "html": "<!DOCTYPE html><html><head><noscript><!--<noscript></noscript>--></noscript></head><body></body></html>",
-        "noQuirksBodyHtml": "<noscript>&lt;!--&lt;noscript&gt;</noscript>--&gt;"
+        "noQuirksBodyHtml": "<noscript><!--<noscript></noscript>--></noscript>"
       }
     },
     {
           }
         ],
         "html": "<!DOCTYPE html><html><head><noscript><!--</noscript></head><body>X<noscript>--></noscript></body></html>",
-        "noQuirksBodyHtml": "<noscript>&lt;!--</noscript>X<noscript>--&gt;</noscript>"
+        "noQuirksBodyHtml": "<noscript><!--</noscript>X<noscript>--></noscript>"
       }
     },
     {
           }
         ],
         "html": "<!DOCTYPE html><html><head><noscript><!--</noscript>X<noscript>--></noscript></head><body></body></html>",
-        "noQuirksBodyHtml": "<noscript>&lt;!--</noscript>X<noscript>--&gt;</noscript>"
+        "noQuirksBodyHtml": "<noscript><!--</noscript>X<noscript>--></noscript>"
       }
     },
     {
           }
         ],
         "html": "<!DOCTYPE html><html><head><noscript><iframe></noscript></head><body>X</body></html>",
-        "noQuirksBodyHtml": "<noscript>&lt;iframe&gt;</noscript>X"
+        "noQuirksBodyHtml": "<noscript><iframe></noscript>X</iframe></noscript>"
       }
     },
     {
           }
         ],
         "html": "<!DOCTYPE html><html><head><noscript></noscript></head><body><iframe></noscript>X</iframe></body></html>",
-        "noQuirksBodyHtml": "<noscript>&lt;iframe&gt;</noscript>X"
+        "noQuirksBodyHtml": "<noscript><iframe></noscript>X</iframe></noscript>"
       }
     },
     {
       "data": "<script><!",
       "errors": [
         "(1,8): expected-doctype-but-got-start-tag",
+        "(1,10): expected-script-data-but-got-eof",
         "(1,10): expected-named-closing-tag-but-got-eof"
       ],
       "document": {
           }
         ],
         "html": "<html><head><noscript><!--<noscript></noscript></head><body>--&gt;</body></html>",
-        "noQuirksBodyHtml": "<noscript>&lt;!--&lt;noscript&gt;</noscript>--&gt;"
+        "noQuirksBodyHtml": "<noscript><!--<noscript></noscript>--></noscript>"
       }
     },
     {
           }
         ],
         "html": "<html><head><noscript><!--<noscript></noscript>--></noscript></head><body></body></html>",
-        "noQuirksBodyHtml": "<noscript>&lt;!--&lt;noscript&gt;</noscript>--&gt;"
+        "noQuirksBodyHtml": "<noscript><!--<noscript></noscript>--></noscript>"
       }
     },
     {
           }
         ],
         "html": "<html><head><noscript><!--</noscript></head><body>X<noscript>--></noscript></body></html>",
-        "noQuirksBodyHtml": "<noscript>&lt;!--</noscript>X<noscript>--&gt;</noscript>"
+        "noQuirksBodyHtml": "<noscript><!--</noscript>X<noscript>--></noscript>"
       }
     },
     {
           }
         ],
         "html": "<html><head><noscript><!--</noscript>X<noscript>--></noscript></head><body></body></html>",
-        "noQuirksBodyHtml": "<noscript>&lt;!--</noscript>X<noscript>--&gt;</noscript>"
+        "noQuirksBodyHtml": "<noscript><!--</noscript>X<noscript>--></noscript>"
       }
     },
     {
           }
         ],
         "html": "<html><head><noscript><iframe></noscript></head><body>X</body></html>",
-        "noQuirksBodyHtml": "<noscript>&lt;iframe&gt;</noscript>X"
+        "noQuirksBodyHtml": "<noscript><iframe></noscript>X</iframe></noscript>"
       }
     },
     {
           }
         ],
         "html": "<html><head><noscript></noscript></head><body><iframe></noscript>X</iframe></body></html>",
-        "noQuirksBodyHtml": "<noscript>&lt;iframe&gt;</noscript>X"
+        "noQuirksBodyHtml": "<noscript><iframe></noscript>X</iframe></noscript>"
       }
     },
     {
         "noQuirksBodyHtml": "<p></p><h1></h1>"
       }
     },
-    {
-      "data": "<!doctype html><form><isindex>",
-      "errors": [
-        "(1,30): deprecated-tag",
-        "(1,30): expected-closing-tag-but-got-eof"
-      ],
-      "document": {
-        "props": {
-          "tags": {
-            "html": true,
-            "head": true,
-            "body": true,
-            "form": true
-          },
-          "doctype": true
-        },
-        "tree": [
-          {
-            "doctype": "html"
-          },
-          {
-            "tag": "html",
-            "children": [
-              {
-                "tag": "head"
-              },
-              {
-                "tag": "body",
-                "children": [
-                  {
-                    "tag": "form"
-                  }
-                ]
-              }
-            ]
-          }
-        ],
-        "html": "<!DOCTYPE html><html><head></head><body><form></form></body></html>",
-        "noQuirksBodyHtml": "<form></form>"
-      }
-    },
-    {
-      "data": "<!doctype html><isindex action=\"POST\">",
-      "errors": [
-        "(1,38): deprecated-tag"
-      ],
-      "document": {
-        "props": {
-          "tags": {
-            "html": true,
-            "head": true,
-            "body": true,
-            "form": true,
-            "hr": true,
-            "label": true,
-            "input": true
-          },
-          "doctype": true
-        },
-        "tree": [
-          {
-            "doctype": "html"
-          },
-          {
-            "tag": "html",
-            "children": [
-              {
-                "tag": "head"
-              },
-              {
-                "tag": "body",
-                "children": [
-                  {
-                    "tag": "form",
-                    "attrs": [
-                      {
-                        "name": "action",
-                        "value": "POST"
-                      }
-                    ],
-                    "children": [
-                      {
-                        "tag": "hr"
-                      },
-                      {
-                        "tag": "label",
-                        "children": [
-                          {
-                            "text": "This is a searchable index. Enter search keywords: "
-                          },
-                          {
-                            "tag": "input",
-                            "attrs": [
-                              {
-                                "name": "name",
-                                "value": "isindex"
-                              }
-                            ]
-                          }
-                        ]
-                      },
-                      {
-                        "tag": "hr"
-                      }
-                    ]
-                  }
-                ]
-              }
-            ]
-          }
-        ],
-        "html": "<!DOCTYPE html><html><head></head><body><form action=\"POST\"><hr><label>This is a searchable index. Enter search keywords: <input name=\"isindex\"></label><hr></form></body></html>",
-        "noQuirksBodyHtml": "<form action=\"POST\"><hr><label>This is a searchable index. Enter search keywords: <input name=\"isindex\"></label><hr></form>"
-      }
-    },
-    {
-      "data": "<!doctype html><isindex prompt=\"this is isindex\">",
-      "errors": [
-        "(1,49): deprecated-tag"
-      ],
-      "document": {
-        "props": {
-          "tags": {
-            "html": true,
-            "head": true,
-            "body": true,
-            "form": true,
-            "hr": true,
-            "label": true,
-            "input": true
-          },
-          "doctype": true
-        },
-        "tree": [
-          {
-            "doctype": "html"
-          },
-          {
-            "tag": "html",
-            "children": [
-              {
-                "tag": "head"
-              },
-              {
-                "tag": "body",
-                "children": [
-                  {
-                    "tag": "form",
-                    "children": [
-                      {
-                        "tag": "hr"
-                      },
-                      {
-                        "tag": "label",
-                        "children": [
-                          {
-                            "text": "this is isindex"
-                          },
-                          {
-                            "tag": "input",
-                            "attrs": [
-                              {
-                                "name": "name",
-                                "value": "isindex"
-                              }
-                            ]
-                          }
-                        ]
-                      },
-                      {
-                        "tag": "hr"
-                      }
-                    ]
-                  }
-                ]
-              }
-            ]
-          }
-        ],
-        "html": "<!DOCTYPE html><html><head></head><body><form><hr><label>this is isindex<input name=\"isindex\"></label><hr></form></body></html>",
-        "noQuirksBodyHtml": "<form><hr><label>this is isindex<input name=\"isindex\"></label><hr></form>"
-      }
-    },
     {
       "data": "<!doctype html><isindex type=\"hidden\">",
       "errors": [
-        "(1,38): deprecated-tag"
-      ],
-      "document": {
-        "props": {
-          "tags": {
-            "html": true,
-            "head": true,
-            "body": true,
-            "form": true,
-            "hr": true,
-            "label": true,
-            "input": true
-          },
-          "doctype": true
-        },
-        "tree": [
-          {
-            "doctype": "html"
-          },
-          {
-            "tag": "html",
-            "children": [
-              {
-                "tag": "head"
-              },
-              {
-                "tag": "body",
-                "children": [
-                  {
-                    "tag": "form",
-                    "children": [
-                      {
-                        "tag": "hr"
-                      },
-                      {
-                        "tag": "label",
-                        "children": [
-                          {
-                            "text": "This is a searchable index. Enter search keywords: "
-                          },
-                          {
-                            "tag": "input",
-                            "attrs": [
-                              {
-                                "name": "name",
-                                "value": "isindex"
-                              },
-                              {
-                                "name": "type",
-                                "value": "hidden"
-                              }
-                            ]
-                          }
-                        ]
-                      },
-                      {
-                        "tag": "hr"
-                      }
-                    ]
-                  }
-                ]
-              }
-            ]
-          }
-        ],
-        "html": "<!DOCTYPE html><html><head></head><body><form><hr><label>This is a searchable index. Enter search keywords: <input name=\"isindex\" type=\"hidden\"></label><hr></form></body></html>",
-        "noQuirksBodyHtml": "<form><hr><label>This is a searchable index. Enter search keywords: <input name=\"isindex\" type=\"hidden\"></label><hr></form>"
-      }
-    },
-    {
-      "data": "<!doctype html><isindex name=\"foo\">",
-      "errors": [
-        "(1,35): deprecated-tag"
+        "(1,38): expected-closing-tag-but-got-eof"
       ],
       "document": {
         "props": {
             "html": true,
             "head": true,
             "body": true,
-            "form": true,
-            "hr": true,
-            "label": true,
-            "input": true
+            "isindex": true
           },
           "doctype": true
         },
                 "tag": "body",
                 "children": [
                   {
-                    "tag": "form",
-                    "children": [
-                      {
-                        "tag": "hr"
-                      },
-                      {
-                        "tag": "label",
-                        "children": [
-                          {
-                            "text": "This is a searchable index. Enter search keywords: "
-                          },
-                          {
-                            "tag": "input",
-                            "attrs": [
-                              {
-                                "name": "name",
-                                "value": "isindex"
-                              }
-                            ]
-                          }
-                        ]
-                      },
+                    "tag": "isindex",
+                    "attrs": [
                       {
-                        "tag": "hr"
+                        "name": "type",
+                        "value": "hidden"
                       }
                     ]
                   }
             ]
           }
         ],
-        "html": "<!DOCTYPE html><html><head></head><body><form><hr><label>This is a searchable index. Enter search keywords: <input name=\"isindex\"></label><hr></form></body></html>",
-        "noQuirksBodyHtml": "<form><hr><label>This is a searchable index. Enter search keywords: <input name=\"isindex\"></label><hr></form>"
+        "html": "<!DOCTYPE html><html><head></head><body><isindex type=\"hidden\"></isindex></body></html>",
+        "noQuirksBodyHtml": "<isindex type=\"hidden\"></isindex>"
       }
     },
     {
     {
       "data": "<!DOCTYPE html><select><optgroup><option></optgroup><option><select><option>",
       "errors": [
-        "(1,68): unexpected-select-in-select",
-        "(1,76): expected-closing-tag-but-got-eof"
+        "(1,68): unexpected-select-in-select"
       ],
       "document": {
         "props": {
         "noQuirksBodyHtml": "<!-- XXX - XXX - XXX -->"
       }
     },
-    {
-      "data": "<isindex test=x name=x>",
-      "errors": [
-        "(1,23): expected-doctype-but-got-start-tag",
-        "(1,23): deprecated-tag"
-      ],
-      "document": {
-        "props": {
-          "tags": {
-            "html": true,
-            "head": true,
-            "body": true,
-            "form": true,
-            "hr": true,
-            "label": true,
-            "input": true
-          }
-        },
-        "tree": [
-          {
-            "tag": "html",
-            "children": [
-              {
-                "tag": "head"
-              },
-              {
-                "tag": "body",
-                "children": [
-                  {
-                    "tag": "form",
-                    "children": [
-                      {
-                        "tag": "hr"
-                      },
-                      {
-                        "tag": "label",
-                        "children": [
-                          {
-                            "text": "This is a searchable index. Enter search keywords: "
-                          },
-                          {
-                            "tag": "input",
-                            "attrs": [
-                              {
-                                "name": "name",
-                                "value": "isindex"
-                              },
-                              {
-                                "name": "test",
-                                "value": "x"
-                              }
-                            ]
-                          }
-                        ]
-                      },
-                      {
-                        "tag": "hr"
-                      }
-                    ]
-                  }
-                ]
-              }
-            ]
-          }
-        ],
-        "html": "<html><head></head><body><form><hr><label>This is a searchable index. Enter search keywords: <input name=\"isindex\" test=\"x\"></label><hr></form></body></html>",
-        "noQuirksBodyHtml": "<form><hr><label>This is a searchable index. Enter search keywords: <input name=\"isindex\" test=\"x\"></label><hr></form>"
-      }
-    },
     {
       "data": "test\ntest",
       "errors": [
     {
       "data": "<option><option>",
       "errors": [
-        "(1,8): expected-doctype-but-got-start-tag",
-        "(1,16): expected-closing-tag-but-got-eof"
+        "(1,8): expected-doctype-but-got-start-tag"
       ],
       "document": {
         "props": {
                     "children": [
                       {
                         "tag": "annotation-xml",
-                        "ns": "http://www.w3.org/1998/Math/MathML"
+                        "ns": "http://www.w3.org/1998/Math/MathML"
+                      }
+                    ]
+                  },
+                  {
+                    "tag": "div"
+                  }
+                ]
+              }
+            ]
+          }
+        ],
+        "html": "<html><head></head><body><math><annotation-xml></annotation-xml></math><div></div></body></html>",
+        "noQuirksBodyHtml": "<math><annotation-xml><div></div></annotation-xml></math>"
+      }
+    },
+    {
+      "data": "<math><annotation-xml encoding=\"application/svg+xml\"><div>",
+      "errors": [
+        "(1,6): expected-doctype-but-got-start-tag",
+        "(1,58): unexpected-html-element-in-foreign-content",
+        "(1,58): expected-closing-tag-but-got-eof"
+      ],
+      "document": {
+        "props": {
+          "tags": {
+            "html": true,
+            "head": true,
+            "body": true,
+            "math math": true,
+            "math annotation-xml": true,
+            "div": true
+          }
+        },
+        "tree": [
+          {
+            "tag": "html",
+            "children": [
+              {
+                "tag": "head"
+              },
+              {
+                "tag": "body",
+                "children": [
+                  {
+                    "tag": "math",
+                    "ns": "http://www.w3.org/1998/Math/MathML",
+                    "children": [
+                      {
+                        "tag": "annotation-xml",
+                        "ns": "http://www.w3.org/1998/Math/MathML",
+                        "attrs": [
+                          {
+                            "name": "encoding",
+                            "value": "application/svg+xml"
+                          }
+                        ]
+                      }
+                    ]
+                  },
+                  {
+                    "tag": "div"
+                  }
+                ]
+              }
+            ]
+          }
+        ],
+        "html": "<html><head></head><body><math><annotation-xml encoding=\"application/svg+xml\"></annotation-xml></math><div></div></body></html>",
+        "noQuirksBodyHtml": "<math><annotation-xml encoding=\"application/svg+xml\"><div></div></annotation-xml></math>"
+      }
+    },
+    {
+      "data": "<math><annotation-xml encoding=\"application/xhtml+xml\"><div>",
+      "errors": [
+        "(1,6): expected-doctype-but-got-start-tag",
+        "(1,60): expected-closing-tag-but-got-eof"
+      ],
+      "document": {
+        "props": {
+          "tags": {
+            "html": true,
+            "head": true,
+            "body": true,
+            "math math": true,
+            "math annotation-xml": true,
+            "div": true
+          }
+        },
+        "tree": [
+          {
+            "tag": "html",
+            "children": [
+              {
+                "tag": "head"
+              },
+              {
+                "tag": "body",
+                "children": [
+                  {
+                    "tag": "math",
+                    "ns": "http://www.w3.org/1998/Math/MathML",
+                    "children": [
+                      {
+                        "tag": "annotation-xml",
+                        "ns": "http://www.w3.org/1998/Math/MathML",
+                        "attrs": [
+                          {
+                            "name": "encoding",
+                            "value": "application/xhtml+xml"
+                          }
+                        ],
+                        "children": [
+                          {
+                            "tag": "div"
+                          }
+                        ]
+                      }
+                    ]
+                  }
+                ]
+              }
+            ]
+          }
+        ],
+        "html": "<html><head></head><body><math><annotation-xml encoding=\"application/xhtml+xml\"><div></div></annotation-xml></math></body></html>",
+        "noQuirksBodyHtml": "<math><annotation-xml encoding=\"application/xhtml+xml\"><div></div></annotation-xml></math>"
+      }
+    },
+    {
+      "data": "<math><annotation-xml encoding=\"aPPlication/xhtmL+xMl\"><div>",
+      "errors": [
+        "(1,6): expected-doctype-but-got-start-tag",
+        "(1,60): expected-closing-tag-but-got-eof"
+      ],
+      "document": {
+        "props": {
+          "tags": {
+            "html": true,
+            "head": true,
+            "body": true,
+            "math math": true,
+            "math annotation-xml": true,
+            "div": true
+          }
+        },
+        "tree": [
+          {
+            "tag": "html",
+            "children": [
+              {
+                "tag": "head"
+              },
+              {
+                "tag": "body",
+                "children": [
+                  {
+                    "tag": "math",
+                    "ns": "http://www.w3.org/1998/Math/MathML",
+                    "children": [
+                      {
+                        "tag": "annotation-xml",
+                        "ns": "http://www.w3.org/1998/Math/MathML",
+                        "attrs": [
+                          {
+                            "name": "encoding",
+                            "value": "aPPlication/xhtmL+xMl"
+                          }
+                        ],
+                        "children": [
+                          {
+                            "tag": "div"
+                          }
+                        ]
+                      }
+                    ]
+                  }
+                ]
+              }
+            ]
+          }
+        ],
+        "html": "<html><head></head><body><math><annotation-xml encoding=\"aPPlication/xhtmL+xMl\"><div></div></annotation-xml></math></body></html>",
+        "noQuirksBodyHtml": "<math><annotation-xml encoding=\"aPPlication/xhtmL+xMl\"><div></div></annotation-xml></math>"
+      }
+    },
+    {
+      "data": "<math><annotation-xml encoding=\"text/html\"><div>",
+      "errors": [
+        "(1,6): expected-doctype-but-got-start-tag",
+        "(1,48): expected-closing-tag-but-got-eof"
+      ],
+      "document": {
+        "props": {
+          "tags": {
+            "html": true,
+            "head": true,
+            "body": true,
+            "math math": true,
+            "math annotation-xml": true,
+            "div": true
+          }
+        },
+        "tree": [
+          {
+            "tag": "html",
+            "children": [
+              {
+                "tag": "head"
+              },
+              {
+                "tag": "body",
+                "children": [
+                  {
+                    "tag": "math",
+                    "ns": "http://www.w3.org/1998/Math/MathML",
+                    "children": [
+                      {
+                        "tag": "annotation-xml",
+                        "ns": "http://www.w3.org/1998/Math/MathML",
+                        "attrs": [
+                          {
+                            "name": "encoding",
+                            "value": "text/html"
+                          }
+                        ],
+                        "children": [
+                          {
+                            "tag": "div"
+                          }
+                        ]
                       }
                     ]
-                  },
-                  {
-                    "tag": "div"
                   }
                 ]
               }
             ]
           }
         ],
-        "html": "<html><head></head><body><math><annotation-xml></annotation-xml></math><div></div></body></html>",
-        "noQuirksBodyHtml": "<math><annotation-xml><div></div></annotation-xml></math>"
+        "html": "<html><head></head><body><math><annotation-xml encoding=\"text/html\"><div></div></annotation-xml></math></body></html>",
+        "noQuirksBodyHtml": "<math><annotation-xml encoding=\"text/html\"><div></div></annotation-xml></math>"
       }
     },
     {
-      "data": "<math><annotation-xml encoding=\"application/svg+xml\"><div>",
+      "data": "<math><annotation-xml encoding=\"Text/htmL\"><div>",
       "errors": [
         "(1,6): expected-doctype-but-got-start-tag",
-        "(1,58): unexpected-html-element-in-foreign-content",
-        "(1,58): expected-closing-tag-but-got-eof"
+        "(1,48): expected-closing-tag-but-got-eof"
       ],
       "document": {
         "props": {
                         "attrs": [
                           {
                             "name": "encoding",
-                            "value": "application/svg+xml"
+                            "value": "Text/htmL"
+                          }
+                        ],
+                        "children": [
+                          {
+                            "tag": "div"
                           }
                         ]
                       }
                     ]
-                  },
-                  {
-                    "tag": "div"
                   }
                 ]
               }
             ]
           }
         ],
-        "html": "<html><head></head><body><math><annotation-xml encoding=\"application/svg+xml\"></annotation-xml></math><div></div></body></html>",
-        "noQuirksBodyHtml": "<math><annotation-xml encoding=\"application/svg+xml\"><div></div></annotation-xml></math>"
+        "html": "<html><head></head><body><math><annotation-xml encoding=\"Text/htmL\"><div></div></annotation-xml></math></body></html>",
+        "noQuirksBodyHtml": "<math><annotation-xml encoding=\"Text/htmL\"><div></div></annotation-xml></math>"
       }
     },
     {
-      "data": "<math><annotation-xml encoding=\"application/xhtml+xml\"><div>",
+      "data": "<math><annotation-xml encoding=\" text/html \"><div>",
       "errors": [
         "(1,6): expected-doctype-but-got-start-tag",
-        "(1,60): expected-closing-tag-but-got-eof"
+        "(1,50): unexpected-html-element-in-foreign-content",
+        "(1,50): expected-closing-tag-but-got-eof"
       ],
       "document": {
         "props": {
                         "attrs": [
                           {
                             "name": "encoding",
-                            "value": "application/xhtml+xml"
-                          }
-                        ],
-                        "children": [
-                          {
-                            "tag": "div"
+                            "value": " text/html "
                           }
                         ]
                       }
                     ]
+                  },
+                  {
+                    "tag": "div"
                   }
                 ]
               }
             ]
           }
         ],
-        "html": "<html><head></head><body><math><annotation-xml encoding=\"application/xhtml+xml\"><div></div></annotation-xml></math></body></html>",
-        "noQuirksBodyHtml": "<math><annotation-xml encoding=\"application/xhtml+xml\"><div></div></annotation-xml></math>"
+        "html": "<html><head></head><body><math><annotation-xml encoding=\" text/html \"></annotation-xml></math><div></div></body></html>",
+        "noQuirksBodyHtml": "<math><annotation-xml encoding=\" text/html \"><div></div></annotation-xml></math>"
       }
     },
     {
-      "data": "<math><annotation-xml encoding=\"aPPlication/xhtmL+xMl\"><div>",
+      "data": "<math><annotation-xml> </annotation-xml>",
       "errors": [
         "(1,6): expected-doctype-but-got-start-tag",
-        "(1,60): expected-closing-tag-but-got-eof"
+        "(1,40): expected-closing-tag-but-got-eof"
       ],
       "document": {
         "props": {
             "head": true,
             "body": true,
             "math math": true,
-            "math annotation-xml": true,
-            "div": true
+            "math annotation-xml": true
           }
         },
         "tree": [
                       {
                         "tag": "annotation-xml",
                         "ns": "http://www.w3.org/1998/Math/MathML",
-                        "attrs": [
-                          {
-                            "name": "encoding",
-                            "value": "aPPlication/xhtmL+xMl"
-                          }
-                        ],
                         "children": [
                           {
-                            "tag": "div"
+                            "text": " "
                           }
                         ]
                       }
             ]
           }
         ],
-        "html": "<html><head></head><body><math><annotation-xml encoding=\"aPPlication/xhtmL+xMl\"><div></div></annotation-xml></math></body></html>",
-        "noQuirksBodyHtml": "<math><annotation-xml encoding=\"aPPlication/xhtmL+xMl\"><div></div></annotation-xml></math>"
+        "html": "<html><head></head><body><math><annotation-xml</annotation-xml></math></body></html>",
+        "noQuirksBodyHtml": "<math><annotation-xml</annotation-xml></math>"
       }
     },
     {
-      "data": "<math><annotation-xml encoding=\"text/html\"><div>",
+      "data": "<math><annotation-xml>c</annotation-xml>",
       "errors": [
         "(1,6): expected-doctype-but-got-start-tag",
-        "(1,48): expected-closing-tag-but-got-eof"
+        "(1,40): expected-closing-tag-but-got-eof"
       ],
       "document": {
         "props": {
             "head": true,
             "body": true,
             "math math": true,
-            "math annotation-xml": true,
-            "div": true
+            "math annotation-xml": true
           }
         },
         "tree": [
                       {
                         "tag": "annotation-xml",
                         "ns": "http://www.w3.org/1998/Math/MathML",
-                        "attrs": [
+                        "children": [
                           {
-                            "name": "encoding",
-                            "value": "text/html"
+                            "text": "c"
                           }
-                        ],
+                        ]
+                      }
+                    ]
+                  }
+                ]
+              }
+            ]
+          }
+        ],
+        "html": "<html><head></head><body><math><annotation-xml>c</annotation-xml></math></body></html>",
+        "noQuirksBodyHtml": "<math><annotation-xml>c</annotation-xml></math>"
+      }
+    },
+    {
+      "data": "<math><annotation-xml><!--foo-->",
+      "errors": [
+        "(1,6): expected-doctype-but-got-start-tag",
+        "(1,32): expected-closing-tag-but-got-eof"
+      ],
+      "document": {
+        "props": {
+          "tags": {
+            "html": true,
+            "head": true,
+            "body": true,
+            "math math": true,
+            "math annotation-xml": true
+          },
+          "comment": true
+        },
+        "tree": [
+          {
+            "tag": "html",
+            "children": [
+              {
+                "tag": "head"
+              },
+              {
+                "tag": "body",
+                "children": [
+                  {
+                    "tag": "math",
+                    "ns": "http://www.w3.org/1998/Math/MathML",
+                    "children": [
+                      {
+                        "tag": "annotation-xml",
+                        "ns": "http://www.w3.org/1998/Math/MathML",
                         "children": [
                           {
-                            "tag": "div"
+                            "comment": "foo"
                           }
                         ]
                       }
             ]
           }
         ],
-        "html": "<html><head></head><body><math><annotation-xml encoding=\"text/html\"><div></div></annotation-xml></math></body></html>",
-        "noQuirksBodyHtml": "<math><annotation-xml encoding=\"text/html\"><div></div></annotation-xml></math>"
+        "html": "<html><head></head><body><math><annotation-xml><!--foo--></annotation-xml></math></body></html>",
+        "noQuirksBodyHtml": "<math><annotation-xml><!--foo--></annotation-xml></math>"
       }
     },
     {
-      "data": "<math><annotation-xml encoding=\"Text/htmL\"><div>",
+      "data": "<math><annotation-xml></svg>x",
       "errors": [
         "(1,6): expected-doctype-but-got-start-tag",
-        "(1,48): expected-closing-tag-but-got-eof"
+        "(1,28): unexpected-end-tag",
+        "(1,29): expected-closing-tag-but-got-eof"
       ],
       "document": {
         "props": {
             "head": true,
             "body": true,
             "math math": true,
-            "math annotation-xml": true,
-            "div": true
+            "math annotation-xml": true
           }
         },
         "tree": [
                       {
                         "tag": "annotation-xml",
                         "ns": "http://www.w3.org/1998/Math/MathML",
-                        "attrs": [
-                          {
-                            "name": "encoding",
-                            "value": "Text/htmL"
-                          }
-                        ],
                         "children": [
                           {
-                            "tag": "div"
+                            "text": "x"
                           }
                         ]
                       }
             ]
           }
         ],
-        "html": "<html><head></head><body><math><annotation-xml encoding=\"Text/htmL\"><div></div></annotation-xml></math></body></html>",
-        "noQuirksBodyHtml": "<math><annotation-xml encoding=\"Text/htmL\"><div></div></annotation-xml></math>"
+        "html": "<html><head></head><body><math><annotation-xml>x</annotation-xml></math></body></html>",
+        "noQuirksBodyHtml": "<math><annotation-xml>x</annotation-xml></math>"
       }
     },
     {
-      "data": "<math><annotation-xml encoding=\" text/html \"><div>",
+      "data": "<math><annotation-xml><svg>x",
       "errors": [
         "(1,6): expected-doctype-but-got-start-tag",
-        "(1,50): unexpected-html-element-in-foreign-content",
-        "(1,50): expected-closing-tag-but-got-eof"
+        "(1,28): expected-closing-tag-but-got-eof"
       ],
       "document": {
         "props": {
             "body": true,
             "math math": true,
             "math annotation-xml": true,
-            "div": true
+            "svg svg": true
           }
         },
         "tree": [
                       {
                         "tag": "annotation-xml",
                         "ns": "http://www.w3.org/1998/Math/MathML",
-                        "attrs": [
+                        "children": [
                           {
-                            "name": "encoding",
-                            "value": " text/html "
+                            "tag": "svg",
+                            "ns": "http://www.w3.org/2000/svg",
+                            "children": [
+                              {
+                                "text": "x"
+                              }
+                            ]
                           }
                         ]
                       }
                     ]
-                  },
-                  {
-                    "tag": "div"
                   }
                 ]
               }
             ]
           }
         ],
-        "html": "<html><head></head><body><math><annotation-xml encoding=\" text/html \"></annotation-xml></math><div></div></body></html>",
-        "noQuirksBodyHtml": "<math><annotation-xml encoding=\" text/html \"><div></div></annotation-xml></math>"
+        "html": "<html><head></head><body><math><annotation-xml><svg>x</svg></annotation-xml></math></body></html>",
+        "noQuirksBodyHtml": "<math><annotation-xml><svg>x</svg></annotation-xml></math>"
       }
     }
   ],
         "noQuirksBodyHtml": "<command>A</command>"
       }
     },
-    {
-      "data": "<!DOCTYPE html><body><menuitem>A",
-      "errors": [],
-      "document": {
-        "props": {
-          "tags": {
-            "html": true,
-            "head": true,
-            "body": true,
-            "menuitem": true
-          },
-          "doctype": true
-        },
-        "tree": [
-          {
-            "doctype": "html"
-          },
-          {
-            "tag": "html",
-            "children": [
-              {
-                "tag": "head"
-              },
-              {
-                "tag": "body",
-                "children": [
-                  {
-                    "tag": "menuitem"
-                  },
-                  {
-                    "text": "A"
-                  }
-                ]
-              }
-            ]
-          }
-        ],
-        "html": "<!DOCTYPE html><html><head></head><body><menuitem>A</body></html>",
-        "noQuirksBodyHtml": "<menuitem>A"
-      }
-    },
     {
       "data": "<!DOCTYPE html><body><embed>A",
       "errors": [],
             "body": true,
             "pre": true
           },
-          "doctype": true,
-          "extraNL": true
+          "doctype": true
         },
         "tree": [
           {
                     "tag": "pre",
                     "children": [
                       {
-                        "text": "\nfoo",
-                        "extraNL": true
+                        "text": "\nfoo"
                       }
                     ]
                   }
             ]
           }
         ],
-        "html": "<!DOCTYPE html><html><head></head><body><pre>\n\nfoo</pre></body></html>",
-        "noQuirksBodyHtml": "<pre>\n\nfoo</pre>"
+        "html": "<!DOCTYPE html><html><head></head><body><pre>\nfoo</pre></body></html>",
+        "noQuirksBodyHtml": "<pre>\nfoo</pre>"
       }
     },
     {
             "body": true,
             "pre": true
           },
-          "doctype": true,
-          "extraNL": true
+          "doctype": true
         },
         "tree": [
           {
                     "tag": "pre",
                     "children": [
                       {
-                        "text": "\nA",
-                        "extraNL": true
+                        "text": "\nA"
                       }
                     ]
                   }
             ]
           }
         ],
-        "html": "<!DOCTYPE html><html><head></head><body><pre>\n\nA</pre></body></html>",
-        "noQuirksBodyHtml": "<pre>\n\nA</pre>"
+        "html": "<!DOCTYPE html><html><head></head><body><pre>\nA</pre></body></html>",
+        "noQuirksBodyHtml": "<pre>\nA</pre>"
       }
     },
     {
             "body": true,
             "textarea": true
           },
-          "doctype": true,
-          "extraNL": true
+          "doctype": true
         },
         "tree": [
           {
                     "tag": "textarea",
                     "children": [
                       {
-                        "text": "\nfoo",
-                        "extraNL": true
+                        "text": "\nfoo"
                       }
                     ]
                   }
             ]
           }
         ],
-        "html": "<!DOCTYPE html><html><head></head><body><textarea>\n\nfoo</textarea></body></html>",
-        "noQuirksBodyHtml": "<textarea>\n\nfoo</textarea>"
+        "html": "<!DOCTYPE html><html><head></head><body><textarea>\nfoo</textarea></body></html>",
+        "noQuirksBodyHtml": "<textarea>\nfoo</textarea>"
       }
     },
     {
           }
         ],
         "html": "<html><head><noscript><!--</noscript></head><body>--&gt;</body></html>",
-        "noQuirksBodyHtml": "<noscript>&lt;!--</noscript>--&gt;"
+        "noQuirksBodyHtml": "<noscript><!--</noscript>--></noscript>"
       }
     },
     {
           }
         ],
         "html": "<html><head><noscript><!--</noscript>--></noscript></head><body></body></html>",
-        "noQuirksBodyHtml": "<noscript>&lt;!--</noscript>--&gt;"
+        "noQuirksBodyHtml": "<noscript><!--</noscript>--></noscript>"
       }
     }
   ],
         "(1,14): foster-parenting-character",
         "(1,20): foster-parenting-character",
         "(1,25): unexpected-end-tag",
+        "(1,25): unexpected-end-tag-in-special-element",
         "(1,26): foster-parenting-character"
       ],
       "document": {
     {
       "data": "</select><option>",
       "errors": [
-        "(1,9): XXX-undefined-error",
-        "(1,17): eof-in-select"
+        "(1,9): XXX-undefined-error"
       ],
       "fragment": {
         "name": "select"
     {
       "data": "<input><option>",
       "errors": [
-        "(1,7): unexpected-input-in-select",
-        "(1,15): eof-in-select"
+        "(1,7): unexpected-input-in-select"
       ],
       "fragment": {
         "name": "select"
     {
       "data": "<keygen><option>",
       "errors": [
-        "(1,8): unexpected-input-in-select",
-        "(1,16): eof-in-select"
+        "(1,8): unexpected-input-in-select"
       ],
       "fragment": {
         "name": "select"
     {
       "data": "<textarea><option>",
       "errors": [
-        "(1,10): unexpected-input-in-select",
-        "(1,18): eof-in-select"
+        "(1,10): unexpected-input-in-select"
       ],
       "fragment": {
         "name": "select"
         "(1,25): unexpected-select-in-select",
         "(1,59): unexpected-select-in-select",
         "(1,93): unexpected-select-in-select",
-        "(1,127): unexpected-select-in-select",
-        "(1,127): expected-closing-tag-but-got-eof"
+        "(1,127): unexpected-select-in-select"
       ],
       "document": {
         "props": {
           }
         ],
         "html": "<html><head></head><body><p id=\"status\"><noscript><strong>A</strong></noscript><span>B</span></p></body></html>",
-        "noQuirksBodyHtml": "<p id=\"status\"><noscript>&lt;strong&gt;A&lt;/strong&gt;</noscript><span>B</span></p>"
+        "noQuirksBodyHtml": "<p id=\"status\"><noscript><strong>A</strong></noscript><span>B</span></p>"
       }
     },
     {
           }
         ],
         "html": "<html><head></head><body><p id=\"status\"><noscript><strong>A</strong></noscript><span>B</span></p></body></html>",
-        "noQuirksBodyHtml": "<p id=\"status\"><noscript>&lt;strong&gt;A&lt;/strong&gt;</noscript><span>B</span></p>"
+        "noQuirksBodyHtml": "<p id=\"status\"><noscript><strong>A</strong></noscript><span>B</span></p>"
       }
     },
     {
         "noQuirksBodyHtml": "<b><em><foo><foob><foob><foob><foob><fooc><fooc><fooc><fooc><food></food></fooc></fooc></fooc></fooc></foob></foob></foob></foob></foo></em></b><aside><b></b></aside>"
       }
     },
-    {
-      "data": "<isindex action=\"x\">",
-      "errors": [],
-      "fragment": {
-        "name": "table"
-      },
-      "document": {
-        "props": {
-          "tags": {
-            "form": true,
-            "hr": true,
-            "label": true,
-            "input": true
-          }
-        },
-        "tree": [
-          {
-            "tag": "form",
-            "attrs": [
-              {
-                "name": "action",
-                "value": "x"
-              }
-            ],
-            "children": [
-              {
-                "tag": "hr"
-              },
-              {
-                "tag": "label",
-                "children": [
-                  {
-                    "text": "This is a searchable index. Enter search keywords: "
-                  },
-                  {
-                    "tag": "input",
-                    "attrs": [
-                      {
-                        "name": "name",
-                        "value": "isindex"
-                      }
-                    ]
-                  }
-                ]
-              },
-              {
-                "tag": "hr"
-              }
-            ]
-          }
-        ],
-        "html": "<form action=\"x\"><hr><label>This is a searchable index. Enter search keywords: <input name=\"isindex\"></label><hr></form>",
-        "noQuirksBodyHtml": "<form action=\"x\"><hr><label>This is a searchable index. Enter search keywords: <input name=\"isindex\"></label><hr></form>"
-      }
-    },
     {
       "data": "<option><XH<optgroup></optgroup>",
       "errors": [],
       }
     }
   ]
-}
+}
\ No newline at end of file
index b2857d9..09e0f07 100644 (file)
@@ -67,7 +67,7 @@
                );
 
                assert.deepEqual(
-                       model.getState(),
+                       model.getSelectedState(),
                        {
                                group1filter1: false,
                                group1filter2: false,
@@ -85,7 +85,7 @@
                        group3filter1: true
                } );
                assert.deepEqual(
-                       model.getState(),
+                       model.getSelectedState(),
                        {
                                group1filter1: true,
                                group1filter2: false,
                // This can simulate separate filters in the same group being hidden different
                // ways (e.g. preferences and URL).
                assert.deepEqual(
-                       model.getState(),
+                       model.getSelectedState(),
                        {
                                hidefilter1: false, // The text is "show filter 1"
                                hidefilter2: true, // The text is "show filter 2"
                // Simulates minor edits being hidden in preferences, then unhidden via URL
                // override.
                assert.deepEqual(
-                       model.getState(),
+                       model.getSelectedState(),
                        {
                                hidefilter1: false, // The text is "show filter 1"
                                hidefilter2: false, // The text is "show filter 2"
                        } )
                );
                assert.deepEqual(
-                       model.getState(),
+                       model.getSelectedState(),
                        {
                                hidefilter1: false, // The text is "show filter 1"
                                hidefilter2: false, // The text is "show filter 2"
                        } )
                );
                assert.deepEqual(
-                       model.getState(),
+                       model.getSelectedState(),
                        {
                                hidefilter1: false, // The text is "show filter 1"
                                hidefilter2: false, // The text is "show filter 2"
                        } )
                );
                assert.deepEqual(
-                       model.getState(),
+                       model.getSelectedState(),
                        {
                                hidefilter1: false, // The text is "show filter 1"
                                hidefilter2: false, // The text is "show filter 2"
                        } )
                );
                assert.deepEqual(
-                       model.getState(),
+                       model.getSelectedState(),
                        {
                                hidefilter1: false, // The text is "show filter 1"
                                hidefilter2: false, // The text is "show filter 2"
                        } )
                );
                assert.deepEqual(
-                       model.getState(),
+                       model.getSelectedState(),
                        {
                                hidefilter1: false, // The text is "show filter 1"
                                hidefilter2: false, // The text is "show filter 2"
                        'If any value is "all", the only value is "all".'
                );
        } );
+
+       QUnit.test( 'reapplyActiveFilters - "default" exclusion rules', function ( assert ) {
+               var definition = {
+                               group1: {
+                                       title: 'Group 1',
+                                       type: 'send_unselected_if_any',
+                                       exclusionType: 'default',
+                                       filters: [
+                                               {
+                                                       name: 'hidefilter1',
+                                                       label: 'Show filter 1',
+                                                       description: 'Description of Filter 1 in Group 1'
+                                               },
+                                               {
+                                                       name: 'hidefilter2',
+                                                       label: 'Show filter 2',
+                                                       description: 'Description of Filter 2 in Group 1'
+                                               },
+                                               {
+                                                       name: 'hidefilter3',
+                                                       label: 'Show filter 3',
+                                                       description: 'Description of Filter 3 in Group 1'
+                                               }
+                                       ]
+                               },
+                               group2: {
+                                       title: 'Group 2',
+                                       type: 'send_unselected_if_any',
+                                       filters: [
+                                               {
+                                                       name: 'hidefilter4',
+                                                       label: 'Show filter 4',
+                                                       description: 'Description of Filter 1 in Group 2'
+                                               },
+                                               {
+                                                       name: 'hidefilter5',
+                                                       label: 'Show filter 5',
+                                                       description: 'Description of Filter 2 in Group 2'
+                                               },
+                                               {
+                                                       name: 'hidefilter6',
+                                                       label: 'Show filter 6',
+                                                       description: 'Description of Filter 3 in Group 2'
+                                               }
+                                       ]
+                               }
+                       },
+                       model = new mw.rcfilters.dm.FiltersViewModel();
+
+               model.initializeFilters( definition );
+
+               assert.deepEqual(
+                       model.getFullState(),
+                       {
+                               // Group 1
+                               hidefilter1: { selected: false, active: true },
+                               hidefilter2: { selected: false, active: true },
+                               hidefilter3: { selected: false, active: true },
+                               // Group 2
+                               hidefilter4: { selected: false, active: true },
+                               hidefilter5: { selected: false, active: true },
+                               hidefilter6: { selected: false, active: true },
+                       },
+                       'Initial state: all filters are active.'
+               );
+
+               // Default behavior for 'exclusion' type with only 1 item selected, means that:
+               // - The items in the same group that are *not* selected are *not* active
+               // - Items in other groups are unaffected (all active)
+               model.updateFilters( {
+                       hidefilter1: false,
+                       hidefilter2: false,
+                       hidefilter3: false,
+                       hidefilter4: false,
+                       hidefilter5: false,
+                       hidefilter6: true
+               } );
+               assert.deepEqual(
+                       model.getFullState(),
+                       {
+                               // Group 1: not affected
+                               hidefilter1: { selected: false, active: true },
+                               hidefilter2: { selected: false, active: true },
+                               hidefilter3: { selected: false, active: true },
+                               // Group 2: affected
+                               hidefilter4: { selected: false, active: false },
+                               hidefilter5: { selected: false, active: false },
+                               hidefilter6: { selected: true, active: true },
+                       },
+                       'Default exclusion behavior with 1 item selected in the group.'
+               );
+
+               // Default behavior for 'exclusion' type with multiple items selected, but not all, means that:
+               // - The items in the same group that are *not* selected are *not* active
+               // - Items in other groups are unaffected (all active)
+               model.updateFilters( {
+                       // Literally updating filters to create a clean state
+                       hidefilter1: false,
+                       hidefilter2: false,
+                       hidefilter3: false,
+                       hidefilter4: false,
+                       hidefilter5: true,
+                       hidefilter6: true
+               } );
+               assert.deepEqual(
+                       model.getFullState(),
+                       {
+                               // Group 1: not affected
+                               hidefilter1: { selected: false, active: true },
+                               hidefilter2: { selected: false, active: true },
+                               hidefilter3: { selected: false, active: true },
+                               // Group 2: affected
+                               hidefilter4: { selected: false, active: false },
+                               hidefilter5: { selected: true, active: true },
+                               hidefilter6: { selected: true, active: true },
+                       },
+                       'Default exclusion behavior with multiple items (but not all) selected in the group.'
+               );
+
+               // Default behavior for 'exclusion' type with all items in the group selected, means that:
+               // - All items in the group are NOT active
+               // - Items in other groups are unaffected (all active)
+               model.updateFilters( {
+                       // Literally updating filters to create a clean state
+                       hidefilter1: false,
+                       hidefilter2: false,
+                       hidefilter3: false,
+                       hidefilter4: true,
+                       hidefilter5: true,
+                       hidefilter6: true
+               } );
+               assert.deepEqual(
+                       model.getFullState(),
+                       {
+                               // Group 1: not affected
+                               hidefilter1: { selected: false, active: true },
+                               hidefilter2: { selected: false, active: true },
+                               hidefilter3: { selected: false, active: true },
+                               // Group 2: affected
+                               hidefilter4: { selected: true, active: false },
+                               hidefilter5: { selected: true, active: false },
+                               hidefilter6: { selected: true, active: false },
+                       },
+                       'Default exclusion behavior with all items in the group.'
+               );
+       } );
+
+       QUnit.test( 'reapplyActiveFilters - "explicit" exclusion rules', function ( assert ) {
+               var definition = {
+                               group1: {
+                                       title: 'Group 1',
+                                       type: 'send_unselected_if_any',
+                                       exclusionType: 'explicit',
+                                       filters: [
+                                               {
+                                                       name: 'filter1',
+                                                       excludes: [ 'filter2', 'filter3' ],
+                                                       label: 'Show filter 1',
+                                                       description: 'Description of Filter 1 in Group 1'
+                                               },
+                                               {
+                                                       name: 'filter2',
+                                                       excludes: [ 'filter3' ],
+                                                       label: 'Show filter 2',
+                                                       description: 'Description of Filter 2 in Group 1'
+                                               },
+                                               {
+                                                       name: 'filter3',
+                                                       label: 'Show filter 3',
+                                                       excludes: [ 'filter1' ],
+                                                       description: 'Description of Filter 3 in Group 1'
+                                               },
+                                               {
+                                                       name: 'filter4',
+                                                       label: 'Show filter 4',
+                                                       description: 'Description of Filter 4 in Group 1'
+                                               }
+                                       ]
+                               }
+                       },
+                       model = new mw.rcfilters.dm.FiltersViewModel();
+
+               model.initializeFilters( definition );
+
+               assert.deepEqual(
+                       model.getFullState(),
+                       {
+                               filter1: { selected: false, active: true },
+                               filter2: { selected: false, active: true },
+                               filter3: { selected: false, active: true },
+                               filter4: { selected: false, active: true }
+                       },
+                       'Initial state: all filters are active.'
+               );
+
+               // "Explicit" behavior for 'exclusion' with one item checked:
+               // - Items in the 'excluded' list of the selected filter are inactive
+               model.updateFilters( {
+                       // Literally updating filters to create a clean state
+                       filter1: true, // Excludes 'hidefilter2', 'hidefilter3'
+                       filter2: false, // Excludes 'hidefilter3'
+                       filter3: false, // Excludes 'hidefilter1'
+                       filter4: false // No exclusion list
+               } );
+               assert.deepEqual(
+                       model.getFullState(),
+                       {
+                               filter1: { selected: true, active: true },
+                               filter2: { selected: false, active: false },
+                               filter3: { selected: false, active: false },
+                               filter4: { selected: false, active: true }
+                       },
+                       '"Explicit" exclusion behavior with one item selected that has an exclusion list.'
+               );
+
+               // "Explicit" behavior for 'exclusion' with two item checked:
+               // - Items in the 'excluded' list of each of the selected filter are inactive
+               model.updateFilters( {
+                       // Literally updating filters to create a clean state
+                       filter1: true, // Excludes 'hidefilter2', 'hidefilter3'
+                       filter2: false, // Excludes 'hidefilter3'
+                       filter3: true, // Excludes 'hidefilter1'
+                       filter4: false // No exclusion list
+               } );
+               assert.deepEqual(
+                       model.getFullState(),
+                       {
+                               filter1: { selected: true, active: false },
+                               filter2: { selected: false, active: false },
+                               filter3: { selected: true, active: false },
+                               filter4: { selected: false, active: true }
+                       },
+                       '"Explicit" exclusion behavior with two selected items that both have an exclusion list.'
+               );
+
+               // "Explicit behavior" with two filters that exclude the same item
+
+               // Two filters selected, both exclude 'hidefilter3'
+               model.updateFilters( {
+                       // Literally updating filters to create a clean state
+                       filter1: true, // Excludes 'hidefilter2', 'hidefilter3'
+                       filter2: true, // Excludes 'hidefilter3'
+                       filter3: false, // Excludes 'hidefilter1'
+                       filter4: false // No exclusion list
+               } );
+               assert.deepEqual(
+                       model.getFullState(),
+                       {
+                               filter1: { selected: true, active: true },
+                               filter2: { selected: true, active: false }, // Excluded by filter1
+                               filter3: { selected: false, active: false }, // Excluded by both filter1 and filter2
+                               filter4: { selected: false, active: true }
+                       },
+                       '"Explicit" exclusion behavior with two selected items that both exclude another item.'
+               );
+
+               // Unselect filter2: filter3 should still be excluded, because filter1 excludes it and is selected
+               model.updateFilters( {
+                       filter2: false, // Excludes 'hidefilter3'
+               } );
+               assert.deepEqual(
+                       model.getFullState(),
+                       {
+                               filter1: { selected: true, active: true },
+                               filter2: { selected: false, active: false }, // Excluded by filter1
+                               filter3: { selected: false, active: false }, // Still excluded by filter1
+                               filter4: { selected: false, active: true }
+                       },
+                       '"Explicit" exclusion behavior unselecting one item that excludes another item, that is being excluded by a third active item.'
+               );
+
+               // Unselect filter1: filter3 should now be active, since both filters that exclude it are unselected
+               model.updateFilters( {
+                       filter1: false, // Excludes 'hidefilter3' and 'hidefilter2'
+               } );
+               assert.deepEqual(
+                       model.getFullState(),
+                       {
+                               filter1: { selected: false, active: true },
+                               filter2: { selected: false, active: true }, // No longer excluded by filter1
+                               filter3: { selected: false, active: true }, // No longer excluded by either filter1 nor filter2
+                               filter4: { selected: false, active: true }
+                       },
+                       '"Explicit" exclusion behavior unselecting both items that excluded the same third item.'
+               );
+
+       } );
 }( mediaWiki, jQuery ) );