Skip to content

Commit

Permalink
Include text content of style element in validation error (#3717)
Browse files Browse the repository at this point in the history
* Include text content in validation error for invalid style elements

* Improve presentation of text content in validation error
  • Loading branch information
westonruter committed Nov 12, 2019
1 parent b5464aa commit 835ff89
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions includes/sanitizers/class-amp-base-sanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -551,8 +551,8 @@ public function prepare_validation_error( array $error = [], array $data = [] )
}
}

// Capture script contents.
if ( 'script' === $node->nodeName && ! $node->hasAttribute( 'src' ) ) {
// Capture element contents.
if ( ( 'script' === $node->nodeName && ! $node->hasAttribute( 'src' ) ) || 'style' === $node->nodeName ) {
$error['text'] = $node->textContent;
}

Expand Down
20 changes: 20 additions & 0 deletions includes/validation/class-amp-validation-error-taxonomy.php
Original file line number Diff line number Diff line change
Expand Up @@ -2157,6 +2157,26 @@ public static function render_single_url_error_details( $validation_error, $term
<dd class="detailed">
<?php if ( in_array( $key, [ 'node_name', 'parent_name' ], true ) ) : ?>
<code><?php echo esc_html( $value ); ?></code>
<?php elseif ( 'text' === $key ) : ?>
<details>
<summary>
<?php
echo esc_html(
sprintf(
/* translators: %s is the byte count */
_n(
'%s byte',
'%s bytes',
strlen( $value ),
'amp'
),
number_format_i18n( strlen( $value ) )
)
);
?>
</summary>
<p><code><?php echo esc_html( $value ); ?></code></p>
</details>
<?php elseif ( 'sources' === $key ) : ?>
<?php self::render_sources( $value ); ?>
<?php elseif ( $is_element_attributes ) : ?>
Expand Down

0 comments on commit 835ff89

Please sign in to comment.