Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTML parser: don't alter raw HTML #10551

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/blocks/src/api/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,10 @@ export function matcherFromSource( sourceConfig ) {
* @return {*} Attribute value.
*/
export function parseWithAttributeSchema( innerHTML, attributeSchema ) {
if ( attributeSchema.source === 'html' && ! attributeSchema.selector ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: this seems better in the matcherFromSource function because there's already a switch case there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

matcherFromSource always gets fed into hpq and will then get modified. The idea with the change is to bypass hpq entirely, for which parseWithAttributeSchema seems a good place:

export function parseWithAttributeSchema( innerHTML, attributeSchema ) {
	if ( attributeSchema.source === 'html' && ! attributeSchema.selector ) {
		return innerHTML;
	}

	return hpqParse( innerHTML, matcherFromSource( attributeSchema ) );
}

return innerHTML;
}

return hpqParse( innerHTML, matcherFromSource( attributeSchema ) );
}

Expand Down
14 changes: 14 additions & 0 deletions packages/blocks/src/api/test/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,20 @@ describe( 'block parser', () => {
);
expect( value ).toBeUndefined();
} );

it( 'should return original content for html source with no selector', () => {
const value = getBlockAttribute(
'content',
{
type: 'string',
source: 'html',
},
'<path />',
{}
);

expect( value ).toBe( '<path />' );
} );
} );

describe( 'getBlockAttributes()', () => {
Expand Down