Unverified Commit 9a0ab60e authored by Lauri Timmanee's avatar Lauri Timmanee
Browse files

Issue #3268983 by nod_, iSoLate, plach, Wim Leers, acbramley, larowlan,...

Issue #3268983 by nod_, iSoLate, plach, Wim Leers, acbramley, larowlan, scott_euser, catch: [regression] FilterHtml throws Unsupported operand types error when * used in tag attribute

(cherry picked from commit 6750f9fd)
parent 5f56a23a
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -347,6 +347,14 @@ private static function fromObjectWithHtmlRestrictions(object $object): HTMLRest
      throw new \DomainException('text formats with only filters that forbid tags rather than allowing tags are not yet supported.');
    }

    // When allowing all tags on an attribute, transform FilterHtml output from
    // ['tag' => ['*'=> TRUE]] to ['tag' => TRUE]
    foreach ($restrictions['allowed'] as $element => $attributes) {
      if (is_array($attributes) && isset($attributes['*']) && $attributes['*'] === TRUE) {
        $restrictions['allowed'][$element] = TRUE;
      }
    }

    $allowed = $restrictions['allowed'];

    return new self($allowed);
@@ -399,6 +407,14 @@ public static function fromString(string $elements_string): HTMLRestrictions {
      }
    }

    // When allowing all tags on an attribute, transform FilterHtml output from
    // ['tag' => ['*'=> TRUE]] to ['tag' => TRUE]
    foreach ($allowed_elements as $element => $attributes) {
      if (is_array($attributes) && isset($attributes['*']) && $attributes['*'] === TRUE) {
        $allowed_elements[$element] = TRUE;
      }
    }

    return new self($allowed_elements);
  }

+14 −0
Original line number Diff line number Diff line
@@ -816,6 +816,20 @@ public function providerOperands(): \Generator {
      'intersection' => 'a',
      'union' => 'b',
    ];
    yield 'wildcard + matching tag: wildcard resolves into matching tag, but matching tag already supports all attributes' => [
      'a' => new HTMLRestrictions(['p' => TRUE]),
      'b' => new HTMLRestrictions(['$text-container' => ['class' => ['foo' => TRUE, 'bar' => TRUE]]]),
      'diff' => 'a',
      'intersection' => HTMLRestrictions::emptySet(),
      'union' => new HTMLRestrictions(['p' => TRUE, '$text-container' => ['class' => ['foo' => TRUE, 'bar' => TRUE]]]),
    ];
    yield 'wildcard + matching tag: wildcard resolves into matching tag, but matching tag already supports all attributes — vice versa' => [
      'a' => new HTMLRestrictions(['$text-container' => ['class' => ['foo' => TRUE, 'bar' => TRUE]]]),
      'b' => new HTMLRestrictions(['p' => TRUE]),
      'diff' => 'a',
      'intersection' => HTMLRestrictions::emptySet(),
      'union' => new HTMLRestrictions(['p' => TRUE, '$text-container' => ['class' => ['foo' => TRUE, 'bar' => TRUE]]]),
    ];

    // Tag restrictions.
    yield 'tag restrictions are different: <a> vs <b c>' => [
+0 −7
Original line number Diff line number Diff line
@@ -267,13 +267,6 @@ public function getHTMLRestrictions() {
      }
      $tag = $node->tagName;
      if ($node->hasAttributes()) {
        // This tag has a notation like "<foo *>", to indicate all attributes
        // are allowed.
        if ($node->hasAttribute($star_protector)) {
          $restrictions['allowed'][$tag] = TRUE;
          continue;
        }

        // Mark the tag as allowed, assigning TRUE for each attribute name if
        // all values are allowed, or an array of specific allowed values.
        $restrictions['allowed'][$tag] = [];
+2 −1
Original line number Diff line number Diff line
@@ -203,7 +203,7 @@ public function testFilterFormatAPI() {
        'filter_html' => [
          'status' => 1,
          'settings' => [
            'allowed_html' => '<a> <b class> <c class="*"> <d class="foo bar-* *">',
            'allowed_html' => '<a> <b class> <c class="*"> <d class="foo bar-* *"> <e *>',
          ],
        ],
      ],
@@ -217,6 +217,7 @@ public function testFilterFormatAPI() {
          'b' => ['class' => TRUE],
          'c' => ['class' => TRUE],
          'd' => ['class' => ['foo' => TRUE, 'bar-*' => TRUE]],
          'e' => ['*' => TRUE],
          '*' => ['style' => FALSE, 'on*' => FALSE, 'lang' => TRUE, 'dir' => ['ltr' => TRUE, 'rtl' => TRUE]],
        ],
      ],