[wp-trac] [WordPress Trac] #47014: Tag balancing corrupts Custom Elements
WordPress Trac
noreply at wordpress.org
Tue Apr 23 04:20:34 UTC 2019
#47014: Tag balancing corrupts Custom Elements
--------------------------+-----------------------------
Reporter: westonruter | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Formatting | Version: 2.0.4
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
When working with [https://developer.mozilla.org/en-
US/docs/Web/Web_Components/Using_custom_elements Custom Elements] (for
[https://developer.mozilla.org/en-US/docs/Web/Web_Components Web
Components]), I noticed that `force_balance_tags()` corrupts them.
For example, given `<my-element>test</my-element>`, this gets incorrectly
mutated by `force_balance_tags()` as follows:
{{{
wp> force_balance_tags('<my-element>test</my-element>')
=> string(22) "<my -element>test</my>"
}}}
Notice the space being added after `my` in the start tag and then
`-element` being dropped in the end tag. So it's clear that `-element` is
being incorrectly interpreted as an attribute.
The issue is that the hyphen is not included in the characters expected to
be in an element name. So the fix seems merely to be:
{{{#!diff
--- a/src/wp-includes/formatting.php
+++ b/src/wp-includes/formatting.php
@@ -2465,7 +2465,7 @@ function force_balance_tags( $text ) {
// WP bug fix for LOVE <3 (and other situations with '<' before a
number)
$text = preg_replace( '#<([0-9]{1})#', '<$1', $text );
- while ( preg_match( '/<(\/?[\w:]*)\s*([^>]*)>/', $text, $regex ) )
{
+ while ( preg_match( '/<(\/?[\w:\-]*)\s*([^>]*)>/', $text, $regex )
) {
$newtext .= $tagqueue;
$i = strpos( $text, $regex[0] );
}}}
This issue has come up at least twice in supporting the
[https://wordpress.org/plugins/amp/ AMP plugin]:
* https://github.com/ampproject/amp-wp/issues/2156#issuecomment-485281213
* https://wordpress.org/support/topic/how-to-enable-shortcodes-oembed-for-
comments-in-amp-pages/#post-11427212
--
Ticket URL: <https://core.trac.wordpress.org/ticket/47014>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list