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

If you include more than symbol into pattern, custom html block it will html escape it #67038

Open
3 of 6 tasks
asolopovas opened this issue Nov 15, 2024 · 3 comments
Open
3 of 6 tasks
Labels
Needs Technical Feedback Needs testing from a developer perspective. [Type] Help Request Help with setup, implementation, or "How do I?" questions.

Comments

@asolopovas
Copy link

Description

I use Alpine.js and often perform arrow function operation inside attributes for examples <div :class="{ 'shown' : () => shown === true"> because I use > quote turns final quote into "}&#8221" causing incorrect tags. For example if you create with html block the following <div separator="()=>{}"></div> it will turn on the output to <div separator="()=>{}&#8221;></div> it should not be escaping final quotes.

Step-by-step reproduction instructions

Open fresh WordPress installation,
create html block with the following contents <div separator="()=>{}"></div>
the html output will look like this <div separator="()=>{}&#8221;></div>

funny enough if you use < everything works fine.

Screenshots, screen recording, code snippet

No response

Environment info

No response

Please confirm that you have searched existing issues in the repo.

  • Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

  • Yes

Please confirm which theme type you used for testing.

  • Block
  • Classic
  • Hybrid (e.g. classic with theme.json)
  • Not sure
@asolopovas asolopovas added the [Type] Bug An existing feature does not function as intended label Nov 15, 2024
@Mamaduka Mamaduka added the Needs Technical Feedback Needs testing from a developer perspective. label Nov 15, 2024
@Mayank-Tripathi32
Copy link

Hello @asolopovas,

I believe the behavior you're encountering is intentional.

The issue where separator="()=>{}&#8221;" appears instead of separator="()=>{}" is due to the way HTML entities are encoded when using dangerouslySetInnerHTML.

Here’s how it works:

export default function save( { attributes } ) {
	return <RawHTML>{ attributes.content }</RawHTML>;
}

export default function RawHTML( { children, ...props } ) {
	let rawHtml = '';

	// Cast children as an array, and concatenate each element if it is a string.
	Children.toArray( children ).forEach( ( child ) => {
		if ( typeof child === 'string' && child.trim() !== '' ) {
			rawHtml += child;
		}
	} );

	// The `div` wrapper will be stripped by the `renderElement` serializer in
	// `./serialize.js` unless there are non-children props present.
	return createElement( 'div', {
		dangerouslySetInnerHTML: { __html: rawHtml },
		...props,
	} );
}

When using RawHTML to render, React applies dangerouslySetInnerHTML, which automatically escapes certain characters (like quotes) to ensure proper HTML rendering and to safeguard against XSS (cross-site scripting) attacks. This built-in behavior is designed to keep your application secure.

I hope this clears up the behavior! Let me know if you have any further questions or any corrections! Thanks

@carolinan
Copy link
Contributor

carolinan commented Nov 16, 2024

The HTML block is for HTML, so if you need to do anything more complex, use a custom block.

@t-hamano
Copy link
Contributor

I don't think the issue reported here is an issue with custom HTML blocks or React. I can reproduce the same error in the classic editor.

I think the underlying problem is that content is filtered by the wptexturize function by default.

There are a few ways to solve this, but one way is to disable texturized on specific tags:

function my_no_texturize_tags( $tags ) {
	$tags[] = 'div';
	return $tags;
}
add_filter( 'no_texturize_tags', 'my_no_texturize_tags' );

@t-hamano t-hamano added [Type] Help Request Help with setup, implementation, or "How do I?" questions. and removed [Type] Bug An existing feature does not function as intended labels Nov 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Technical Feedback Needs testing from a developer perspective. [Type] Help Request Help with setup, implementation, or "How do I?" questions.
Projects
None yet
Development

No branches or pull requests

5 participants