Skip to content

Commit

Permalink
Escape the HTML in the editor of the posts and post carousel blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanHerman committed Jul 25, 2024
1 parent 4a4e73c commit 93097d6
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
"@wordpress/editor": "^13.21.0",
"@wordpress/element": "^5.21.0",
"@wordpress/env": "^10.1.0",
"@wordpress/escape-html": "^3.4.0",
"@wordpress/eslint-plugin": "^17.1.0",
"@wordpress/hooks": "^3.44.0",
"@wordpress/i18n": "^4.44.0",
Expand Down
3 changes: 2 additions & 1 deletion src/blocks/post-carousel/post-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
} from '@wordpress/components';
import { PlainText } from '@wordpress/block-editor';
import { RawHTML } from '@wordpress/element';
import { escapeHTML } from '@wordpress/escape-html';
import { withSelect } from '@wordpress/data';
// Disable reason: We choose to use unsafe APIs in our codebase.
// eslint-disable-next-line @wordpress/no-unsafe-wp-apis
Expand Down Expand Up @@ -78,7 +79,7 @@ const PostItem = ( {
<RawHTML
key="html"
>
{ excerpt.trim().split( ' ', excerptLength ).join( ' ' ) }
{ escapeHTML( excerpt.trim().split( ' ', excerptLength ).join( ' ' ) ) }
</RawHTML>
</div>
}
Expand Down
5 changes: 3 additions & 2 deletions src/blocks/posts/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import apiFetch from '@wordpress/api-fetch';
import { __ } from '@wordpress/i18n';
import { compose, usePrevious } from '@wordpress/compose';
import { lazy, RawHTML, useState, useEffect, useRef } from '@wordpress/element';
import { escapeHTML } from '@wordpress/escape-html';
import { addQueryArgs } from '@wordpress/url';
// Disable reason: We choose to use unsafe APIs in our codebase.
// eslint-disable-next-line @wordpress/no-unsafe-wp-apis
Expand Down Expand Up @@ -435,8 +436,8 @@ const PostsEdit = ( props ) => {
key="html"
>
{ excerptLength < excerpt.trim().split( ' ' ).length
? excerpt.trim().split( ' ', excerptLength ).join( ' ' ) + '…'
: excerpt.trim().split( ' ', excerptLength ).join( ' ' ) }
? escapeHTML( excerpt.trim().split( ' ', excerptLength ).join( ' ' ) ) + '…'
: escapeHTML( excerpt.trim().split( ' ', excerptLength ).join( ' ' ) ) }
</RawHTML>
</div>
}
Expand Down
7 changes: 7 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4172,6 +4172,13 @@
dependencies:
"@babel/runtime" "^7.16.0"

"@wordpress/escape-html@^3.4.0":
version "3.4.0"
resolved "https://registry.yarnpkg.com/@wordpress/escape-html/-/escape-html-3.4.0.tgz#ec625d409b018ff68d6081c66586fd420f74e122"
integrity sha512-KcUv+s0J/LEZEEvd+E3IkNCeW8wde0TjO+1HrcfvqI8Rfuc0zOAZeS/6ZqIeX0m/mhQ0xS2Y3e8hsnU+wAG6Mw==
dependencies:
"@babel/runtime" "^7.16.0"

"@wordpress/eslint-plugin@^12.7.0":
version "12.9.0"
resolved "https://registry.yarnpkg.com/@wordpress/eslint-plugin/-/eslint-plugin-12.9.0.tgz#c49f0a523c8c72ade28c2b86a975668832b22938"
Expand Down

0 comments on commit 93097d6

Please sign in to comment.