diff --git a/packages/blocks/src/api/matchers.js b/packages/blocks/src/api/matchers.js index 7a6ac84891658a..919502af208bdf 100644 --- a/packages/blocks/src/api/matchers.js +++ b/packages/blocks/src/api/matchers.js @@ -9,6 +9,20 @@ export { attr, prop, text, query } from 'hpq'; export { matcher as node } from './node'; export { matcher as children } from './children'; +function replaceInnerHTMLEntities( innerHTML ) { + const entityRegEx = /&(amp|lt|gt);/g; + + // This subset of chars are returned as HTML entities from Element.innerHTML + const lookUp = { + amp: '&', + lt: '<', + gt: '>', + }; + + // Replace entity with text equivalent. + return innerHTML.replace( entityRegEx, ( match, p1 ) => lookUp[ p1 ] ); +} + export function html( selector, multilineTag ) { return ( domNode ) => { let match = domNode; @@ -38,6 +52,6 @@ export function html( selector, multilineTag ) { return value; } - return match.innerHTML; + return replaceInnerHTMLEntities( match.innerHTML ); }; }